Open action

This is a code example of iText PDF, discover more.

7th November 2015

Switch code for this example
 * This example was written by Bruno Lowagie in answer to the following question:
package sandbox.annotations;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfAction;
import com.itextpdf.text.pdf.PdfDestination;
import com.itextpdf.text.pdf.PdfWriter;

import sandbox.WrapToTest;

 * @author Bruno Lowagie (iText Software)
public class OpenAt100pct {
    public static final String DEST = "results/annotations/open100pct.pdf";

    public static void main(String[] args) throws IOException, DocumentException {
        File file = new File(DEST);
        new OpenAt100pct().createPdf(DEST);
    public void createPdf(String dest) throws FileNotFoundException, DocumentException {
        Rectangle pagesize = PageSize.LETTER;
        Document document = new Document(pagesize);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest));;
        PdfDestination pdfDest = new PdfDestination(PdfDestination.XYZ, 0, 842, 1f);
        writer.setOpenAction(PdfAction.gotoLocalPage(1, pdfDest, writer));
        document.add(new Paragraph("Hello World"));

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now