Gnostice PDFOne
Pro. Ed. v5.0.0


com.gnostice.pdfone
Class PdfNamedAction

java.lang.Object
  extended bycom.gnostice.pdfone.PdfAction
      extended bycom.gnostice.pdfone.PdfNamedAction

public class PdfNamedAction
extends PdfAction

This class represents a named action.


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 #<% pageno %>", 100, 100, "1-5");

        // Write text (containing custom placeholder) where the link
        // annotation has been placed
        doc1.writeText(
            "Go to page #<% nextpageno %>", 
            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;
    }

    static
    {
        PDFOne.activate("T95VZE:W8HBPVA:74VQ8QV:LO4V8",
            "9B1HRZAP:X5853ERNE:5EREMEGRQ:TX1R10");
    }

}


Nested Class Summary
 
Nested classes inherited from class com.gnostice.pdfone.PdfAction
PdfAction.PdfEvent
 
Field Summary
 
Fields inherited from class com.gnostice.pdfone.PdfAction
GOTO, JAVASCRIPT, LAUNCH, NAMED, NAMED_FIND, NAMED_FIRSTPAGE, NAMED_LASTPAGE, NAMED_NEXTPAGE, NAMED_OPEN, NAMED_PREVPAGE, NAMED_PRINT, NAMED_SEARCH, REMOTE_GOTO, URI
 
Constructor Summary
PdfNamedAction(int namedAction)
          Constructs a named action of specified type.
 
Method Summary
 int getNamedAction()
          Returns the type of named action.
 void prepareActionDict()
           
 void setNamedAction(int namedAction)
          Specifies type of the named action.
 
Methods inherited from class com.gnostice.pdfone.PdfAction
getActionType
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PdfNamedAction

public PdfNamedAction(int namedAction)
Constructs a named action of specified type.

Parameters:
namedAction - constant specifying the type of named action
See Also:
PdfAction
Method Detail

getNamedAction

public int getNamedAction()
Returns the type of named action.

Returns:
constant specifying the type of named action
See Also:
PdfAction, setNamedAction(int)

setNamedAction

public void setNamedAction(int namedAction)
Specifies type of the named action.

Parameters:
namedAction - constant specifying the type of the named action
See Also:
PdfAction, getNamedAction()

prepareActionDict

public void prepareActionDict()
                       throws PdfException
Throws:
PdfException

Gnostice PDFOne
Pro. Ed. v5.0.0

To contact our support team, send an e-mail to support@gnostice.com.
 
© 2010 Gnostice Information Technologies Private Limited. All rights reserved.
www.gnostice.com