Example usage for com.itextpdf.text.pdf PdfSmartCopy setOutlines

List of usage examples for com.itextpdf.text.pdf PdfSmartCopy setOutlines

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfSmartCopy setOutlines.

Prototype

public void setOutlines(final List<HashMap<String, Object>> outlines) 

Source Link

Document

Sets the bookmarks.

Usage

From source file:com.github.hossman.PdfShrinker.java

License:Apache License

public static void main(String args[]) throws Exception {
    if (1 != args.length) {
        System.err.println("Run this app with a single command line PDF filename");
        System.err.println("The specified file will be read, and a shrunk version written to stdout");
        System.err.println("ie:   java -jar pdf-shrinker.jar big.pdf > small.pdf");
        System.exit(-1);//  ww w .j ava  2 s . c o m
    }

    Document document = new Document();
    PdfSmartCopy copy = new PdfSmartCopy(document, System.out);
    copy.setCompressionLevel(9);
    copy.setFullCompression();
    document.open();
    PdfReader reader = new PdfReader(args[0]);
    List<HashMap<String, Object>> bookmarks = SimpleBookmark.getBookmark(reader);
    int pages = reader.getNumberOfPages();
    for (int i = 0; i < pages; i++) {
        PdfImportedPage page = copy.getImportedPage(reader, i + 1);
        copy.addPage(page);
    }
    copy.freeReader(reader);
    reader.close();
    copy.setOutlines(bookmarks);
    document.close();
}

From source file:com.preselect.pdfservice.tasks.PdfConversionTask.java

License:Open Source License

private static void copyDocument(PdfReader reader, int start, int end, String path, OutlineItems outline)
        throws IOException, DocumentException {
    Document document = new Document();
    PdfSmartCopy copy = new PdfSmartCopy(document, new FileOutputStream(path));

    document.open();/* ww  w  . j a v a  2  s .  c o  m*/
    for (int i = (start - 1); i <= (end - 1);) {
        copy.addPage(copy.getImportedPage(reader, ++i));
    }
    List<OutlineItem> outlineForChapter = getOutlineBetweenPages(outline, start, end);
    Iterator<OutlineItem> iterator = outlineForChapter.iterator();
    if (iterator.hasNext()) {
        List<HashMap<String, Object>> bookmarksForChapter = getBookmarks(iterator.next(), iterator, 1);
        SimpleBookmark.shiftPageNumbers(bookmarksForChapter, (-start + 1), null);
        copy.setOutlines(bookmarksForChapter);
    }
    if (outlineForChapter.size() > 0) {
        OutlineItem firstOutline = outlineForChapter.get(0);
        document.addTitle(firstOutline.getTitle());
    }
    document.addCreator("Content Select");
    document.close();
    copy.close();
}