de.vc.jfo.tools

## Class PDFWriter

- java.lang.Object
- - de.vc.jfo.tools.PDFWriter

-     public class PDFWriter
      extends java.lang.Object

  The PDFWriter is a tool writing a set of existing PDFs or XSL-FO Documents to a single PDF file or stream. XSL-FO Documents are rendered automatically to PDF before they are appended. Also one can specify whether a new appended document should start at an odd page. This is usefull in some cases when printing documents on duplex printers.
  This writer uses a third party library called iText, available at http://www.lowagie.com/iText/
  Usage:

  `PDFWriter w = new PDFWriter("merge.pdf"); w.appendPDF("file1.pdf"); w.appendPDF("file2.pdf"); w.appendDocument( de.vc.jfo.Document doc ); w.close(); // very important!`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `PDFWriter(java.io.OutputStream pdfOutput)` Creates a new PDF writer that are merges documents to one large PDF.
    `PDFWriter(java.io.OutputStream pdfOutput, boolean startOnOddPageNumber)` Creates a new PDF writer that are merges documents to one large PDF.
    `PDFWriter(java.lang.String pdfOutputFile)` Creates a new PDF writer that are merges documents to one large PDF.
    `PDFWriter(java.lang.String pdfOutputFile, boolean startOnOddPageNumber)` Creates a new PDF writer that are merges documents to one large PDF.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `appendDocument(Document document)` Appends an XSL-FO document to the PDF output.
    `void` | `appendPDF(byte[] pdfFile)` Appends an existing PDF file to the PDF output.
    `void` | `appendPDF(java.lang.String pdfFile)` Appends an existing PDF file to the PDF output.
    `void` | `appendPDF(java.net.URL pdfFile)` Appends an existing PDF file to the PDF output.
    `void` | `close()` Closes this writer and the output stream of the PDF target.
    `int` | `getTotalNumberOfPages()` Gets the total number of pages that were written into the PDF stream.
    `void` | `setRenderer(Renderer renderer)` Sets the renderer that is used to render XSL-FO Documents.
    `void` | `write(Document document)` Deprecated. Use appendDocument.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### PDFWriter

          public PDFWriter(java.lang.String pdfOutputFile)
                    throws java.io.FileNotFoundException

      Creates a new PDF writer that are merges documents to one large PDF.
      Parameters:
        `pdfOutputFile` - Output PDF file.
      Throws:
        `java.io.FileNotFoundException`

    - #### PDFWriter

          public PDFWriter(java.lang.String pdfOutputFile,
                   boolean startOnOddPageNumber)
                    throws java.io.FileNotFoundException

      Creates a new PDF writer that are merges documents to one large PDF.
      Parameters:
        `pdfOutputFile` - Output PDF file.
        `startOnOddPageNumber` - Start each document on an odd page number (eg for duplex printing).
      Throws:
        `java.io.FileNotFoundException`

    - #### PDFWriter

          public PDFWriter(java.io.OutputStream pdfOutput)

      Creates a new PDF writer that are merges documents to one large PDF.
      Parameters:
        `pdfOutput` - Stream to merged PDF.

    - #### PDFWriter

          public PDFWriter(java.io.OutputStream pdfOutput,
                   boolean startOnOddPageNumber)

      Creates a new PDF writer that are merges documents to one large PDF.
      Parameters:
        `pdfOutput` - Stream to merged PDF.
        `startOnOddPageNumber` - Start each document on an odd page number (eg for duplex printing).

  - ### Method Detail

    - #### setRenderer

          public void setRenderer(Renderer renderer)

      Sets the renderer that is used to render XSL-FO Documents.
      Parameters:
        `renderer` - Renderer
      See Also:
        `appendDocument(de.vc.jfo.Document)`

    - #### appendPDF

          public void appendPDF(byte[] pdfFile)
                         throws java.io.IOException

      Appends an existing PDF file to the PDF output.
      Parameters:
        `pdfFile` - PDF file in array (e.g. from database).
      Throws:
        `java.io.IOException`

    - #### appendPDF

          public void appendPDF(java.net.URL pdfFile)
                         throws java.io.IOException

      Appends an existing PDF file to the PDF output.
      Parameters:
        `pdfFile` - URL of PDF file.
      Throws:
        `java.io.IOException`

    - #### appendPDF

          public void appendPDF(java.lang.String pdfFile)
                         throws java.io.IOException

      Appends an existing PDF file to the PDF output.
      Parameters:
        `pdfFile` - Path to PDF file.
      Throws:
        `java.io.IOException`

    - #### appendDocument

          public void appendDocument(Document document)
                              throws java.io.IOException

      Appends an XSL-FO document to the PDF output. Therefore the XSL-FO document is transformed to PDF. If no concrete PDF renderer was specified (setRenderer) the PDF renderer with the highest priority is used (see jfo-config.xml).
      Parameters:
        `document` - Document
      Throws:
        `java.io.IOException`
      See Also:
        `setRenderer(Renderer)`

    - #### write

          public void write(Document document)
                     throws java.io.IOException

      Deprecated. Use appendDocument.
      Appends an XSL-FO document to the PDF output. Therefore the XSL-FO document is transformed to PDF by the renderer with the highest priority.
      Parameters:
        `document` - Document
      Throws:
        `java.io.IOException`

    - #### close

          public void close()
                     throws java.io.IOException

      Closes this writer and the output stream of the PDF target. You must ensure calling this method when all documents are appended.
      Throws:
        `java.io.IOException`

    - #### getTotalNumberOfPages

          public int getTotalNumberOfPages()

      Gets the total number of pages that were written into the PDF stream.
      Returns:
        Total number of pages.

© 2003-2011 by Sascha Schmidt (vision-cloud.de). All Rights Reserved.