Example usage for com.lowagie.text.pdf PdfWriter getCurrentDocumentSize

List of usage examples for com.lowagie.text.pdf PdfWriter getCurrentDocumentSize

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfWriter getCurrentDocumentSize.

Prototype

public int getCurrentDocumentSize() 

Source Link

Document

Use this method to gets the current document size.

Usage

From source file:de.dhbw.humbuch.util.PDFHandler.java

/**
 * Creates a ByteArrayOutputStream which contains the PDF as a byte array.
 * /*from   w  w  w .j  a  va 2  s  . com*/
 * @return the byteArrayOutputStream the PDF is stored in, null if an error
 *         occurred.
 */
public ByteArrayOutputStream createByteArrayOutputStreamForPDF() {
    ByteArrayOutputStream byteArrayOutputStream;
    try {
        byteArrayOutputStream = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, byteArrayOutputStream);
        event = new HeaderFooter();
        writer.setBoxSize("art", new Rectangle(36, 54, 559, 788));
        writer.setPageEvent(event);

        this.document.open();
        this.addMetaData(document);
        int initialDocumentSize = writer.getCurrentDocumentSize();
        this.insertDocumentParts(document);

        if (byteArrayOutputStream.size() > 0 || writer.getCurrentDocumentSize() > initialDocumentSize) {
            this.document.close();
        } else {
            return null;
        }

        return byteArrayOutputStream;
    } catch (DocumentException e) {
        System.err.println("Could not create ByteArrayOutputStream of PDF data. " + e.getMessage());
    }

    return null;
}