Search in sources :

Example 1 with PdfDestination

use of com.itextpdf.kernel.pdf.navigation.PdfDestination in project i7js-highlevel by itext.

the class C06E08_ExplicitDestinations method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    // here we need to add pages to the document beforehand, because we'll need to get their instances for destination creation
    pdf.addNewPage();
    pdf.addNewPage();
    PdfDestination jekyll = PdfExplicitDestination.createFitH(pdf.getPage(1), 416);
    PdfDestination hyde = PdfExplicitDestination.createXYZ(pdf.getPage(1), 150, 516, 2);
    PdfDestination jekyll2 = PdfExplicitDestination.createFitR(pdf.getPage(2), 50, 380, 130, 440);
    document.add(new Paragraph().add(new Link("Link to Dr. Jekyll", jekyll)));
    document.add(new Paragraph().add(new Link("Link to Mr. Hyde", hyde)));
    document.add(new Paragraph().add(new Link("Link to Dr. Jekyll on page 2", jekyll2)));
    document.add(new Paragraph().setFixedPosition(50, 400, 80).add("Dr. Jekyll"));
    document.add(new Paragraph().setFixedPosition(150, 500, 80).add("Mr. Hyde"));
    document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));
    document.add(new Paragraph().setFixedPosition(50, 400, 80).add("Dr. Jekyll on page 2"));
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfDestination(com.itextpdf.kernel.pdf.navigation.PdfDestination) AreaBreak(com.itextpdf.layout.element.AreaBreak) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Link(com.itextpdf.layout.element.Link) Paragraph(com.itextpdf.layout.element.Paragraph)

Aggregations

PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)1 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)1 PdfDestination (com.itextpdf.kernel.pdf.navigation.PdfDestination)1 Document (com.itextpdf.layout.Document)1 AreaBreak (com.itextpdf.layout.element.AreaBreak)1 Link (com.itextpdf.layout.element.Link)1 Paragraph (com.itextpdf.layout.element.Paragraph)1