public class PdfNamedAction extends PdfAction
import java.awt.Color; import java.io.File; import java.io.IOException; import com.gnostice.pdfone.PDFOne; import com.gnostice.pdfone.PdfAction; import com.gnostice.pdfone.PdfCustomPlaceholderHandler; import com.gnostice.pdfone.PdfDocument; import com.gnostice.pdfone.PdfException; import com.gnostice.pdfone.PdfLinkAnnot; import com.gnostice.pdfone.PdfNamedAction; import com.gnostice.pdfone.PdfPage; import com.gnostice.pdfone.PdfRect; import com.gnostice.pdfone.PdfWriter; public class NamedAction_Demo implements PdfCustomPlaceholderHandler { public static void main(String[] args) throws IOException, PdfException { PdfWriter writer1 = PdfWriter.fileWriter(new File( "PdfNamedAction_example.pdf")); PdfDocument doc1 = new PdfDocument(writer1); // Create a new PDF page (1) PdfPage page1 = new PdfPage(); // Create a link annotation PdfLinkAnnot lAnnot = new PdfLinkAnnot( new PdfRect(126, 151, 37, 12), Color.BLUE); // Create a named action PdfNamedAction na = new PdfNamedAction( PdfAction.NAMED_NEXTPAGE); // Add the named action to the link annotation lAnnot.addAction(na); // Add the link annotation to the page page1.addAnnotation(lAnnot); // Create copies (2-3) of page 1 PdfPage page2 = (PdfPage) page1.clone(); PdfPage page3 = (PdfPage) page1.clone(); PdfPage page4 = (PdfPage) page1.clone(); // Create new page (5) PdfPage page5 = new PdfPage(); // Add all pages to document doc1.add(page1); doc1.add(page2); doc1.add(page3); doc1.add(page4); doc1.add(page5); // Specify that write() method needs to process // custom placeholders doc1.setCph(new NamedAction_Demo()); // Write text (containing pre-defined placeholder) identifying // the page doc1.writeText("This is page #", 100, 100, "1-5"); // Write text (containing custom placeholder) where the link // annotation has been placed doc1.writeText( "Go to page #", 100, 150, "1-4"); doc1.setOpenAfterSave(true); doc1.write(); writer1.dispose(); } // Modifies the custom placeholder with the value of current page // number plus one public String onCustomPlaceHolder(String variable, PdfDocument d, int pagenumber) { if (variable.equalsIgnoreCase("nextpageno")) { return String.valueOf(pagenumber + 1); } return variable; } }
PdfAction.PdfEvent
GOTO, JAVASCRIPT, LAUNCH, NAMED, NAMED_FIND, NAMED_FIRSTPAGE, NAMED_LASTPAGE, NAMED_NEXTPAGE, NAMED_OPEN, NAMED_PREVPAGE, NAMED_PRINT, NAMED_SEARCH, REMOTE_GOTO, URI
Constructor and Description |
---|
PdfNamedAction(int namedAction)
Constructs a named action of specified type.
|
Modifier and Type | Method and Description |
---|---|
int |
getNamedAction()
Returns the type of named action.
|
void |
prepareActionDict() |
void |
setNamedAction(int namedAction)
Specifies type of the named action.
|
getActionType
public PdfNamedAction(int namedAction)
namedAction
- constant specifying the type of named actionPdfAction
public int getNamedAction()
PdfAction
,
setNamedAction(int)
public void setNamedAction(int namedAction)
namedAction
- constant specifying the type of the named actionPdfAction
,
getNamedAction()
public void prepareActionDict() throws PdfException
PdfException