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

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

Introduction

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

Prototype

public void setFullCompression() throws DocumentException 

Source Link

Document

Use this method to set the document's compression to the PDF 1.5 mode with object streams and xref streams.

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);//from   ww  w.  j  a  v  a2  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();
}