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

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

Introduction

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

Prototype

public void setCompressionLevel(final int compressionLevel) 

Source Link

Document

Sets the compression level to be used for streams written by this writer.

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 www  .  j a  va  2  s. c  om
    }

    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();
}