Package com.lowagie.examples.objects.bookmarks

Source Code of com.lowagie.examples.objects.bookmarks.OutlineActions

/*
* $Id$
*
* This code is part of the 'iText Tutorial'.
* You can find the complete tutorial at the following address:
* http://itextdocs.lowagie.com/tutorial/
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* itext-questions@lists.sourceforge.net
*/

package com.lowagie.examples.objects.bookmarks;

import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Chunk;
import com.lowagie.text.LwgDocument;
import com.lowagie.text.DocumentException;
import com.lowagie.text.LwgFont;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfAction;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfDestination;
import com.lowagie.text.pdf.PdfOutline;
import com.lowagie.text.pdf.PdfWriter;

/**
* Demonstrates how pagelabels work.
*
* @author blowagie
*/

public class OutlineActions {

  /**
   * Demonstrates some PageLabel functionality.
   *
   * @param args no arguments needed here
   */
  public static void main(String[] args) {

    System.out.println("Outlines with actions");

    // step 1: creation of a document-object
    LwgDocument document = new LwgDocument();
    LwgDocument remote = new LwgDocument();
    try {
            // step 2:
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("OutlineActions.pdf"));
            PdfWriter.getInstance(remote, new FileOutputStream("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(LwgFont.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(LwgFont.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);
    } catch (DocumentException de) {
      System.err.println(de.getMessage());
    } catch (IOException ioe) {
      System.err.println(ioe.getMessage());
    }

    // step 5: we close the document
    document.close();
    remote.close();
  }
}
TOP

Related Classes of com.lowagie.examples.objects.bookmarks.OutlineActions

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.