Example usage for com.lowagie.text Document compress

List of usage examples for com.lowagie.text Document compress

Introduction

In this page you can find the example usage for com.lowagie.text Document compress.

Prototype

boolean compress

To view the source code for com.lowagie.text Document compress.

Click Source Link

Document

Allows the pdf documents to be produced without compression for debugging purposes.

Usage

From source file:classroom.intro.HelloWorld02.java

public static void main(String[] args) {
    Document.compress = false;
    // step 1//from   w ww  .  j a v a  2 s.c o  m
    Document document = new Document();
    try {
        // step 2
        PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        // step 3
        document.open();
        // step 4
        document.add(new Paragraph("Hello World"));
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    // step 5
    document.close();
}

From source file:classroom.intro.HelloWorld08.java

public static void main(String[] args) {
    Document.compress = false;
    // step 1//from   www . j a va2 s  .  c o m
    Document document = new Document();
    try {
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        // step 3
        document.open();
        // step 4
        PdfContentByte cb = writer.getDirectContent();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb.beginText();
        cb.setFontAndSize(bf, 12);
        cb.moveText(88.66f, 788);
        cb.showText("ld");
        cb.moveText(-22f, 0);
        cb.showText("Wor");
        cb.moveText(-15.33f, 0);
        cb.showText("llo");
        cb.endText();
        PdfTemplate tmp = cb.createTemplate(250, 25);
        tmp.beginText();
        tmp.setFontAndSize(bf, 12);
        tmp.moveText(0, 7);
        tmp.showText("He");
        tmp.endText();
        cb.addTemplate(tmp, 36, 781);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    // step 5
    document.close();
}

From source file:classroom.intro.HelloWorld09.java

public static void main(String[] args) {
    Document.compress = false;
    BaseFont bf = null;//from  w ww .  j  ava2s .  com
    // step 1
    Document document = new Document();
    try {
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT1));
        // step 3
        document.open();
        // step 4
        PdfContentByte cb = writer.getDirectContent();
        bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb.beginText();
        cb.setFontAndSize(bf, 12);
        cb.moveText(88.66f, 788);
        cb.showText("ld");
        cb.moveText(-22f, 0);
        cb.showText("Wor");
        cb.endText();
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    // step 5
    document.close();

    try {
        PdfReader reader = new PdfReader(RESULT1);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT2));
        PdfContentByte cb1 = stamper.getUnderContent(1);
        cb1.beginText();
        cb1.setFontAndSize(bf, 12);
        cb1.setTextMatrix(51.33f, 788);
        cb1.showText("llo");
        cb1.endText();
        PdfContentByte cb2 = stamper.getOverContent(1);
        PdfTemplate tmp = cb2.createTemplate(250, 25);
        tmp.beginText();
        tmp.setFontAndSize(bf, 12);
        tmp.moveText(0, 7);
        tmp.showText("He");
        tmp.endText();
        cb2.addTemplate(tmp, 36, 781);
        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

}

From source file:classroom.intro.HelloWorld10.java

public static void main(String[] args) {
    // step 1/*from  w w w. jav a2s.  c  o m*/
    Document.compress = false;
    Document document = new Document();
    try {
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        // step 3
        document.open();
        // step 4
        PdfContentByte cb = writer.getDirectContent();
        Graphics2D graphics2D = cb.createGraphics(PageSize.A4.getWidth(), PageSize.A4.getHeight());
        graphics2D.drawString("Hello World", 36, 54);
        graphics2D.dispose();
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    // step 5
    document.close();
}

From source file:classroom.intro.HelloWorld11.java

public static void main(String[] args) {
    // step 1//from   ww  w  . j av a2 s  .c om
    Document.compress = false;
    Document document = new Document();
    try {
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        // step 3
        document.open();
        // step 4
        PdfContentByte cb = writer.getDirectContent();
        Graphics2D graphics2D = cb.createGraphicsShapes(PageSize.A4.getWidth(), PageSize.A4.getHeight());
        graphics2D.drawString("Hello World", 36, 54);
        graphics2D.dispose();
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    // step 5
    document.close();
}

From source file:net.sf.jsignpdf.UncompressPdf.java

License:Mozilla Public License

/**
 * The main 'main'./*from   w  w w  .j av  a  2  s  .c  om*/
 * 
 * @param args
 */
public static void main(String[] args) {
    if (args == null || args.length == 0) {
        System.out.println("Usage:\njava " + UncompressPdf.class.getName() + " file.pdf [file2.pdf [...]]");
        return;
    }
    Document.compress = false;
    for (String tmpFile : args) {
        String newFileName = null;
        if (tmpFile.toLowerCase().endsWith(".pdf")) {
            newFileName = tmpFile.substring(0, tmpFile.length() - 4) + "_uncompressed.pdf";
        } else {
            newFileName = tmpFile + "_uncompressed.pdf";
        }
        System.out.println("Uncompressing " + tmpFile + " to " + newFileName);
        try {
            PdfReader reader = new PdfReader(tmpFile);
            PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(newFileName), '\0');
            int total = reader.getNumberOfPages() + 1;
            for (int i = 1; i < total; i++) {
                reader.setPageContent(i, reader.getPageContent(i));
            }
            stamper.close();
        } catch (NullPointerException npe) {
            npe.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}