Search in sources :

Example 1 with PdfOutline

use of com.lowagie.text.pdf.PdfOutline in project itext2 by albfernandez.

the class DestinationsTest method main.

/**
 * Creates a document with some goto actions.
 */
@Test
public void main() throws Exception {
    // step 1: creation of a document-object
    Document document = new Document();
    // step 2:
    PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Destinations.pdf"));
    // step 3:
    writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
    document.open();
    // step 4: we grab the ContentByte and do some stuff with it
    PdfContentByte cb = writer.getDirectContent();
    // we create a PdfTemplate
    PdfTemplate template = cb.createTemplate(25, 25);
    // we add some crosses to visualize the destinations
    template.moveTo(13, 0);
    template.lineTo(13, 25);
    template.moveTo(0, 13);
    template.lineTo(50, 13);
    template.stroke();
    // we add the template on different positions
    cb.addTemplate(template, 287, 787);
    cb.addTemplate(template, 187, 487);
    cb.addTemplate(template, 487, 287);
    cb.addTemplate(template, 87, 87);
    // we define the destinations
    PdfDestination d1 = new PdfDestination(PdfDestination.XYZ, 300, 800, 0);
    PdfDestination d2 = new PdfDestination(PdfDestination.FITH, 500);
    PdfDestination d3 = new PdfDestination(PdfDestination.FITR, 200, 300, 400, 500);
    PdfDestination d4 = new PdfDestination(PdfDestination.FITBV, 100);
    PdfDestination d5 = new PdfDestination(PdfDestination.FIT);
    // we define the outlines
    PdfOutline out1 = new PdfOutline(cb.getRootOutline(), d1, "root");
    PdfOutline out2 = new PdfOutline(out1, d2, "sub 1");
    new PdfOutline(out1, d3, "sub 2");
    new PdfOutline(out2, d4, "sub 2.1");
    new PdfOutline(out2, d5, "sub 2.2");
    // step 5: we close the document
    document.close();
}
Also used : PdfWriter(com.lowagie.text.pdf.PdfWriter) PdfDestination(com.lowagie.text.pdf.PdfDestination) PdfContentByte(com.lowagie.text.pdf.PdfContentByte) Document(com.lowagie.text.Document) PdfTemplate(com.lowagie.text.pdf.PdfTemplate) PdfOutline(com.lowagie.text.pdf.PdfOutline) Test(org.junit.Test)

Example 2 with PdfOutline

use of com.lowagie.text.pdf.PdfOutline in project itext2 by albfernandez.

the class OutlineActionsTest method main.

/**
 * Demonstrates some PageLabel functionality.
 */
@Test
public void main() throws Exception {
    // step 1: creation of a document-object
    Document document = new Document();
    Document remote = new Document();
    // step 2:
    PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("OutlineActions.pdf"));
    PdfWriter.getInstance(remote, PdfTestBase.getOutputStream("remote.pdf"));
    // step 3:
    writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
    document.open();
    remote.open();
    // step 4:
    // we add some content
    document.add(new Paragraph("Outline action example"));
    // we add the outline
    PdfContentByte cb = writer.getDirectContent();
    PdfOutline root = cb.getRootOutline();
    PdfOutline links = new PdfOutline(root, new PdfAction("http://www.lowagie.com/iText/links.html"), "Useful links");
    links.setColor(new Color(0x00, 0x80, 0x80));
    links.setStyle(Font.BOLD);
    new PdfOutline(links, new PdfAction("http://www.lowagie.com/iText"), "Bruno's iText site");
    new PdfOutline(links, new PdfAction("http://itextpdf.sourceforge.net/"), "Paulo's iText site");
    new PdfOutline(links, new PdfAction("http://sourceforge.net/projects/itext/"), "iText @ SourceForge");
    PdfOutline other = new PdfOutline(root, new PdfDestination(PdfDestination.FIT), "other actions", false);
    other.setStyle(Font.ITALIC);
    new PdfOutline(other, new PdfAction("remote.pdf", 1), "Go to yhe first page of a remote file");
    new PdfOutline(other, new PdfAction("remote.pdf", "test"), "Go to a local destination in a remote file");
    new PdfOutline(other, PdfAction.javaScript("app.alert('Hello');\r", writer), "Say Hello");
    remote.add(new Paragraph("Some remote document"));
    remote.newPage();
    Paragraph p = new Paragraph("This paragraph contains a ");
    p.add(new Chunk("local destination").setLocalDestination("test"));
    remote.add(p);
    // step 5: we close the document
    document.close();
    remote.close();
}
Also used : PdfAction(com.lowagie.text.pdf.PdfAction) PdfWriter(com.lowagie.text.pdf.PdfWriter) Color(java.awt.Color) PdfDestination(com.lowagie.text.pdf.PdfDestination) PdfContentByte(com.lowagie.text.pdf.PdfContentByte) Document(com.lowagie.text.Document) Chunk(com.lowagie.text.Chunk) Paragraph(com.lowagie.text.Paragraph) PdfOutline(com.lowagie.text.pdf.PdfOutline) Test(org.junit.Test)

Example 3 with PdfOutline

use of com.lowagie.text.pdf.PdfOutline in project OpenPDF by LibrePDF.

the class Bookmarks method onParagraph.

/**
 * Adds an outline for every new Paragraph
 * @param writer        The PdfWrite to write to the Document
 * @param document      The Document to write to
 * @param position      An int that specifies the y / x coordinate of the top / left edge of the window
 */
public void onParagraph(PdfWriter writer, Document document, float position) {
    n++;
    PdfContentByte cb = writer.getDirectContent();
    PdfDestination destination = new PdfDestination(PdfDestination.FITH, position);
    new PdfOutline(cb.getRootOutline(), destination, "paragraph " + n);
}
Also used : PdfDestination(com.lowagie.text.pdf.PdfDestination) PdfContentByte(com.lowagie.text.pdf.PdfContentByte) PdfOutline(com.lowagie.text.pdf.PdfOutline)

Example 4 with PdfOutline

use of com.lowagie.text.pdf.PdfOutline in project OpenPDF by LibrePDF.

the class Destinations method main.

/**
 * Creates a document with some goto actions.
 *
 * @param args
 *            no arguments needed
 */
public static void main(String[] args) {
    System.out.println("Destinations");
    // step 1: creation of a document-object
    Document document = new Document();
    try {
        // step 2:
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Destinations.pdf"));
        // step 3:
        writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
        document.open();
        // step 4: we grab the ContentByte and do some stuff with it
        PdfContentByte cb = writer.getDirectContent();
        // we create a PdfTemplate
        PdfTemplate template = cb.createTemplate(25, 25);
        // we add some crosses to visualize the destinations
        template.moveTo(13, 0);
        template.lineTo(13, 25);
        template.moveTo(0, 13);
        template.lineTo(50, 13);
        template.stroke();
        // we add the template on different positions
        cb.addTemplate(template, 287, 787);
        cb.addTemplate(template, 187, 487);
        cb.addTemplate(template, 487, 287);
        cb.addTemplate(template, 87, 87);
        // we define the destinations
        PdfDestination d1 = new PdfDestination(PdfDestination.XYZ, 300, 800, 0);
        PdfDestination d2 = new PdfDestination(PdfDestination.FITH, 500);
        PdfDestination d3 = new PdfDestination(PdfDestination.FITR, 200, 300, 400, 500);
        PdfDestination d4 = new PdfDestination(PdfDestination.FITBV, 100);
        PdfDestination d5 = new PdfDestination(PdfDestination.FIT);
        // we define the outlines
        PdfOutline out1 = new PdfOutline(cb.getRootOutline(), d1, "root");
        PdfOutline out2 = new PdfOutline(out1, d2, "sub 1");
        new PdfOutline(out1, d3, "sub 2");
        new PdfOutline(out2, d4, "sub 2.1");
        new PdfOutline(out2, d5, "sub 2.2");
    } catch (Exception de) {
        de.printStackTrace();
    }
    // step 5: we close the document
    document.close();
}
Also used : PdfWriter(com.lowagie.text.pdf.PdfWriter) FileOutputStream(java.io.FileOutputStream) PdfDestination(com.lowagie.text.pdf.PdfDestination) PdfContentByte(com.lowagie.text.pdf.PdfContentByte) Document(com.lowagie.text.Document) PdfTemplate(com.lowagie.text.pdf.PdfTemplate) PdfOutline(com.lowagie.text.pdf.PdfOutline)

Example 5 with PdfOutline

use of com.lowagie.text.pdf.PdfOutline in project OpenPDF by LibrePDF.

the class ListItemBookmarks method main.

/**
 * Creates a document with outlines for ListItems.
 *
 * @param args no arguments needed
 */
public static void main(String[] args) {
    System.out.println("Bookmarks for ListItems");
    // create a new document-object
    Document document = new Document(PageSize.A4);
    try {
        // create a new writer to write the document to a file
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("ListItemBookmarks.pdf"));
        // set viewer preference to make the outlines visible (some viewers ignore this)
        writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
        // open the document to add content to the body
        document.open();
        // create a new list and add some ListItems containing a Chunk object
        // that has a local destination set (this identifier is used below)
        List list = new List();
        list.add(new ListItem(new Chunk(Constants.EA_RES).setLocalDestination("item1")));
        list.add(new ListItem(new Chunk(Constants.HIS_REBUS).setLocalDestination("item2")));
        list.add(new ListItem(new Chunk(Constants.APUD_HELVETIOS).setLocalDestination("item3")));
        document.add(list);
        // get the root outline by accessing the direct content
        PdfOutline rootOutline = writer.getDirectContent().getRootOutline();
        // add outline elements with a goto-PdfAction referring back to the
        // local destination which was set on the Chunks added to the list above
        new PdfOutline(rootOutline, PdfAction.gotoLocalPage("item1", false), "Ea res est Helvetiis");
        new PdfOutline(rootOutline, PdfAction.gotoLocalPage("item2", false), "His rebus adducti");
        new PdfOutline(rootOutline, PdfAction.gotoLocalPage("item3", false), "Apud Helvetios longe");
    } catch (Exception e) {
        e.printStackTrace();
    }
    // close document
    document.close();
}
Also used : PdfWriter(com.lowagie.text.pdf.PdfWriter) FileOutputStream(java.io.FileOutputStream) List(com.lowagie.text.List) ListItem(com.lowagie.text.ListItem) Document(com.lowagie.text.Document) Chunk(com.lowagie.text.Chunk) PdfOutline(com.lowagie.text.pdf.PdfOutline)

Aggregations

PdfOutline (com.lowagie.text.pdf.PdfOutline)9 PdfContentByte (com.lowagie.text.pdf.PdfContentByte)8 PdfDestination (com.lowagie.text.pdf.PdfDestination)8 Document (com.lowagie.text.Document)5 PdfWriter (com.lowagie.text.pdf.PdfWriter)5 Chunk (com.lowagie.text.Chunk)3 FileOutputStream (java.io.FileOutputStream)3 Paragraph (com.lowagie.text.Paragraph)2 PdfAction (com.lowagie.text.pdf.PdfAction)2 PdfTemplate (com.lowagie.text.pdf.PdfTemplate)2 Color (java.awt.Color)2 Test (org.junit.Test)2 DocumentException (com.lowagie.text.DocumentException)1 List (com.lowagie.text.List)1 ListItem (com.lowagie.text.ListItem)1 IOException (java.io.IOException)1