Here is Java sample code to create a menu item that will display a preview of a rubber stamp and that can added to any JMenu. The method AnnotToolbar.createStampMenuItem to create this preview menu item was added in version v2016R1 of Qoppa’s PDF components jPDFNotes and jPDFEditor.
try { // Create a menu item with a preview of the rubber stamp JMenuItem menuItem = AnnotToolbar.createStampMenuItem("Correct", Color.blue); menuItem.setActionCommand(START_STAMP); menuItem.addActionListener(this); // Add the menu item to the stamp menu on the toolbar m_NotesBean.getAnnotToolbar().getJmAddStamps().add(menuItem); } catch (PDFException ex) { ex.printStackTrace(); } |
You will then need to add an actionlistener to listen for the stamp action and start the “stamping”.
public void actionPerformed(ActionEvent e) { MutableDocument doc = m_NotesBean.getMutableDocument(); IAnnotationFactory factory = doc.getAnnotationFactory(); if (e.getActionCommand() == START_STAMP) { // create a rubber stamp using the annotation factory RubberStamp myStamp = factory.createRubberStamp ("Correct", Color.blue); // make the stamp rotated by 45 degrees myStamp.setRotation(45); // start the stamp tool to add the rubber stamp to the page m_NotesBean.startEdit (myStamp, false, false); } } |
See a full sample when you download the full jPDFNotes Demo / Sample application under jPDFNotesSamples under package jPDFNotesSamples.customStamps.