Class PDFTool


  • public class PDFTool
    extends java.lang.Object
    PDF toolbox
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  PDFTool.PDFEvent
      PDF events, manage specific header and footer
      static interface  PDFTool.PDFInterface  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static com.lowagie.text.Font BOLD  
      static com.lowagie.text.pdf.PdfPCell CELL_BLACK  
      static com.lowagie.text.pdf.PdfPCell CELL_GRAY  
      static com.lowagie.text.pdf.PdfPCell CELL_WHITE  
      static com.lowagie.text.Font CODE  
      static com.lowagie.text.Paragraph EMPTY  
      static java.lang.String EURO  
      static com.lowagie.text.Font HEADER  
      static java.awt.Color IMAGE_COLOR  
      static float IMAGE_SCALE  
      static com.lowagie.text.Font MEDIUM  
      static com.lowagie.text.Font MONO  
      static com.lowagie.text.Font NORMAL  
      static com.lowagie.text.Font SCRIPT
      Deprecated.
      static com.lowagie.text.Font SMALL  
      static com.lowagie.text.Font TINY  
      static com.lowagie.text.Font TITLE0  
      static com.lowagie.text.Font TITLE1  
      static com.lowagie.text.Font TITLE2  
    • Method Summary

      Modifier and Type Method Description
      static com.lowagie.text.Chapter addChapter​(com.lowagie.text.Document d, java.lang.String title, PDFTool.PDFEvent event, boolean isOpen)  
      static com.lowagie.text.Paragraph addHTMLParagraph​(java.lang.String html)
      Add HTML paragraph
      static com.lowagie.text.Section addSection​(com.lowagie.text.Document d, com.lowagie.text.Chapter chapter, java.lang.String title, PDFTool.PDFEvent event, boolean isOpen)  
      static com.lowagie.text.Section addSection​(com.lowagie.text.Document d, com.lowagie.text.Section section, java.lang.String title, PDFTool.PDFEvent event, boolean isOpen)  
      static com.lowagie.text.Document build​(com.lowagie.text.Rectangle pageSize, PDFTool.PDFInterface pdf, java.lang.String pdfPath, boolean replace)
      Build a simple PDF document
      static com.lowagie.text.Document build​(com.lowagie.text.Rectangle pageSize, PDFTool.PDFInterface pdf, java.lang.String pdfPath, boolean replace, PDFTool.PDFEvent event, int tocPage, int tocDepth)
      Build a PDF document
      static com.lowagie.text.Document build​(PDFTool.PDFInterface pdf, java.lang.String pdfPath, boolean replace)  
      static void close​(com.lowagie.text.Document d)
      Close a document
      static byte[] concat​(byte[] in1, byte[] in2)  
      static void concat​(java.io.File out, java.io.File in1, java.io.File in2)  
      static void concat​(java.io.OutputStream os, java.io.InputStream is1, java.io.InputStream is2)  
      static void concat​(java.lang.String out, java.lang.String in1, java.lang.String in2)  
      static com.lowagie.text.pdf.PdfPCell getCell​(java.lang.String text)
      Build a Table cell
      static com.lowagie.text.pdf.PdfPCell getCell​(java.lang.String text, com.lowagie.text.Font font, int align, boolean border, java.awt.Color color)
      Build a Table cell
      static com.lowagie.text.pdf.PdfPCell getCellImage​(java.lang.String path, java.awt.Color bkg)  
      static com.lowagie.text.pdf.PdfPCell getColoredCell​(java.awt.Color color, boolean border)
      Build an empty colored cell
      static com.lowagie.text.pdf.PdfPCell getDecalCell​(java.lang.String text, com.lowagie.text.Font font, int align, boolean border, java.awt.Color color)
      Build decaled cell on the right
      static PDFTool.PDFEvent getDocEvent​(boolean pagine, int margin, byte[] headerImg, byte[] footerImg)
      Build a document event handler
      static PDFTool.PDFEvent getDocEvent​(boolean pagine, int margin, java.lang.String headerImg, java.lang.String footerImg)
      Build a document event handler
      static com.lowagie.text.pdf.PdfPCell getHeaderCell​(java.lang.String text, int align, java.awt.Color color)
      Build a header cell
      static com.lowagie.text.pdf.PdfPCell getHeaderCell​(java.lang.String text, java.awt.Color color)
      Build a header cell
      static com.lowagie.text.pdf.PdfPCell getHeaderCellVertical​(java.lang.String text, java.awt.Color color)
      Build a header cell with vertical text
      static com.lowagie.text.Image getImage​(byte[] data)
      Get an image from specified byte array data
      static com.lowagie.text.Image getImage​(java.lang.String path)
      Get an image from specified file path
      static com.lowagie.text.Image getImageFromDBDoc​(Grant g, DocumentDB doc)
      Get image from from DBDoc image
      static com.lowagie.text.Image getImageFromDBDoc​(Grant g, java.lang.String docId)
      Get image from DBDoc image
      static com.lowagie.text.Image getImageFromResource​(com.simplicite.objects.System.ObjectExternal ext, java.lang.String resourceCode)
      Get image from external object resource image
      static com.lowagie.text.Image getImageFromResource​(Grant g, java.lang.String resourceCode)
      Get image from disposition resource image
      static com.lowagie.text.Image getImageFromResource​(Grant g, java.lang.String resourceCode, java.lang.String objectName, java.lang.String objectId)
      Get image from resource image
      static com.lowagie.text.Image getImageFromResource​(ObjectDB obj, java.lang.String resourceCode)
      Get image from object resource image
      static com.lowagie.text.Image getImageFromStaticContent​(Grant g, java.lang.String relativePath)
      Get image from static content
      static com.lowagie.text.Image getImageFromStaticResource​(java.lang.String path)
      Get image from static resource
      static com.lowagie.text.Paragraph getLovParagraph​(ObjectField f)  
      static com.lowagie.text.pdf.PdfPTable getTable​(int[] cols, boolean header)
      Build a PDF table
      static com.lowagie.text.pdf.PdfPTable getTable​(int[] cols, boolean header, int spacingBefore, int spacingAfter)
      Build a PDF table
      static com.lowagie.text.pdf.PdfPTable getTable​(int nbcols, boolean header)
      Build a PDF table
      static java.lang.String getValue​(ObjectDB o, ObjectField f, boolean lovCode)  
      static com.lowagie.text.pdf.PdfPTable insertFieldArea​(com.lowagie.text.Document d, ObjectDB o, FieldArea fa, java.awt.Color bkg, boolean lovCode, boolean emptyValues)
      Insert a field area as a table of 2 columns
      static void insertForm​(com.lowagie.text.Document d, ObjectDB o, java.awt.Color bkg, boolean lovCode)
      Insert object form in PDF (flow of field areas)
      static void insertForm​(com.lowagie.text.Document d, ObjectDB o, java.awt.Color bkg, boolean lovCode, boolean emptyValues)
      Insert object form in PDF (flow of field areas)
      static void insertImage​(com.lowagie.text.Document d, com.lowagie.text.Image img, boolean canRotate, int align)
      Insert one image into the document
      static void insertList​(com.lowagie.text.Document d, ObjectDB o, boolean splitOption, boolean splitBoolean, boolean splitLongText, boolean lov, java.awt.Color headColor, boolean lovCode)
      Generic method to serialize one object current list in distinct PDF tables : Mandatories, Options, Booleans, Long text/HTML, images
      static void insertList​(com.lowagie.text.Document d, ObjectDB o, java.util.List<ObjectField> cols, java.util.List<ObjectField> options, java.util.List<ObjectField> bools, java.util.List<ObjectField> larges, boolean lov, java.awt.Color headColor, boolean lovCode)  
      static com.lowagie.text.Document open​(com.lowagie.text.Rectangle pageSize, java.io.OutputStream out, PDFTool.PDFEvent event)
      Open a new PDF document with output stream
      static com.lowagie.text.Document open​(com.lowagie.text.Rectangle pageSize, java.lang.String pdfPath, boolean replace, PDFTool.PDFEvent event)
      Open a new PDF document with file output
      static com.lowagie.text.Document open​(java.io.OutputStream out)
      Open a new PDF document A4 with output stream
      static com.lowagie.text.Document open​(java.io.OutputStream out, PDFTool.PDFEvent event)
      Open a new PDF document A4 with output stream
      static void stamp​(java.io.InputStream in, java.io.OutputStream out, byte[] image, float posX, float posY)
      Stamp an existing PDF with an image on each pages
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • TITLE0

        public static com.lowagie.text.Font TITLE0
      • TITLE1

        public static com.lowagie.text.Font TITLE1
      • TITLE2

        public static com.lowagie.text.Font TITLE2
      • HEADER

        public static com.lowagie.text.Font HEADER
      • BOLD

        public static com.lowagie.text.Font BOLD
      • NORMAL

        public static com.lowagie.text.Font NORMAL
      • MONO

        public static com.lowagie.text.Font MONO
      • MEDIUM

        public static com.lowagie.text.Font MEDIUM
      • SMALL

        public static com.lowagie.text.Font SMALL
      • CODE

        public static com.lowagie.text.Font CODE
      • TINY

        public static com.lowagie.text.Font TINY
      • SCRIPT

        @Deprecated
        public static com.lowagie.text.Font SCRIPT
        Deprecated.
      • EMPTY

        public static final com.lowagie.text.Paragraph EMPTY
      • CELL_WHITE

        public static com.lowagie.text.pdf.PdfPCell CELL_WHITE
      • CELL_GRAY

        public static com.lowagie.text.pdf.PdfPCell CELL_GRAY
      • CELL_BLACK

        public static com.lowagie.text.pdf.PdfPCell CELL_BLACK
      • IMAGE_COLOR

        public static java.awt.Color IMAGE_COLOR
    • Method Detail

      • build

        public static com.lowagie.text.Document build​(PDFTool.PDFInterface pdf,
                                                      java.lang.String pdfPath,
                                                      boolean replace)
      • build

        public static com.lowagie.text.Document build​(com.lowagie.text.Rectangle pageSize,
                                                      PDFTool.PDFInterface pdf,
                                                      java.lang.String pdfPath,
                                                      boolean replace)
        Build a simple PDF document
        Parameters:
        pageSize - such as PageSize.A4 or PageSize.A4.rotate()
        pdf - Interface to implement the content
        pdfPath - File path
        replace - True to delete any older doc, False to stop if already exists
        Returns:
        Document or null
      • build

        public static com.lowagie.text.Document build​(com.lowagie.text.Rectangle pageSize,
                                                      PDFTool.PDFInterface pdf,
                                                      java.lang.String pdfPath,
                                                      boolean replace,
                                                      PDFTool.PDFEvent event,
                                                      int tocPage,
                                                      int tocDepth)
        Build a PDF document
        Parameters:
        pageSize - such as PageSize.A4 or PageSize.A4.rotate()
        pdf - Interface to implement the content
        pdfPath - File path
        replace - True to delete any older doc, False to stop if already exists
        event - Doc event (may be null)
        tocPage - Insert a table of content in the given page, 0 = no TOC
        tocDepth - Table of content depth (chapter=1, section=2, sub-section=3...)
        Returns:
        Document or null
      • open

        public static com.lowagie.text.Document open​(com.lowagie.text.Rectangle pageSize,
                                                     java.lang.String pdfPath,
                                                     boolean replace,
                                                     PDFTool.PDFEvent event)

        Open a new PDF document with file output

        Parameters:
        pdfPath - File path
        replace - True to delete any older doc, False to stop if already exists
        event - Doc event (may be null)
        Returns:
        A document or null
      • open

        public static final com.lowagie.text.Document open​(java.io.OutputStream out)

        Open a new PDF document A4 with output stream

        Parameters:
        out - Output stream (can be HTTP response output stream of file output stream)
        Returns:
        A document or null
      • open

        public static final com.lowagie.text.Document open​(java.io.OutputStream out,
                                                           PDFTool.PDFEvent event)

        Open a new PDF document A4 with output stream

        Parameters:
        out - Output stream (can be HTTP response output stream of file output stream)
        event - Doc event (may be null)
        Returns:
        A document or null
      • open

        public static com.lowagie.text.Document open​(com.lowagie.text.Rectangle pageSize,
                                                     java.io.OutputStream out,
                                                     PDFTool.PDFEvent event)

        Open a new PDF document with output stream

        Parameters:
        pageSize - such as PageSize.A4 or PageSize.A4.rotate()
        out - Output stream (can be HTTP response output stream of file output stream)
        event - Doc event (may be null)
        Returns:
        A document or null
      • close

        public static void close​(com.lowagie.text.Document d)

        Close a document

        Parameters:
        d - Opened document
      • stamp

        public static final void stamp​(java.io.InputStream in,
                                       java.io.OutputStream out,
                                       byte[] image,
                                       float posX,
                                       float posY)
                                throws java.lang.Exception

        Stamp an existing PDF with an image on each pages

        Parameters:
        in - Input stream of source PDF
        out - Output stream of destination PDF
        image - Image data
        posX - Absolute position X
        posY - Absolute position Y
        Throws:
        java.lang.Exception
      • getDocEvent

        public static PDFTool.PDFEvent getDocEvent​(boolean pagine,
                                                   int margin,
                                                   java.lang.String headerImg,
                                                   java.lang.String footerImg)
        Build a document event handler
        Parameters:
        pagine - True to display the page numbers on page bottom
        margin - Border margin in pixels
        headerImg - Path to the header image
        footerImg - Path to the footer image
        Returns:
        event or null if file read fails
      • getDocEvent

        public static PDFTool.PDFEvent getDocEvent​(boolean pagine,
                                                   int margin,
                                                   byte[] headerImg,
                                                   byte[] footerImg)
        Build a document event handler
        Parameters:
        pagine - True to display the page numbers on page bottom
        margin - Border margin in pixels
        headerImg - Header image data
        footerImg - Footer image data
        Returns:
        event
      • addChapter

        public static com.lowagie.text.Chapter addChapter​(com.lowagie.text.Document d,
                                                          java.lang.String title,
                                                          PDFTool.PDFEvent event,
                                                          boolean isOpen)
                                                   throws com.lowagie.text.DocumentException
        Throws:
        com.lowagie.text.DocumentException
      • addSection

        public static com.lowagie.text.Section addSection​(com.lowagie.text.Document d,
                                                          com.lowagie.text.Chapter chapter,
                                                          java.lang.String title,
                                                          PDFTool.PDFEvent event,
                                                          boolean isOpen)
                                                   throws com.lowagie.text.DocumentException
        Throws:
        com.lowagie.text.DocumentException
      • addSection

        public static com.lowagie.text.Section addSection​(com.lowagie.text.Document d,
                                                          com.lowagie.text.Section section,
                                                          java.lang.String title,
                                                          PDFTool.PDFEvent event,
                                                          boolean isOpen)
                                                   throws com.lowagie.text.DocumentException
        Throws:
        com.lowagie.text.DocumentException
      • getCell

        public static com.lowagie.text.pdf.PdfPCell getCell​(java.lang.String text)

        Build a Table cell

        Parameters:
        text - Simple text
        Returns:
        Table cell
      • getCell

        public static com.lowagie.text.pdf.PdfPCell getCell​(java.lang.String text,
                                                            com.lowagie.text.Font font,
                                                            int align,
                                                            boolean border,
                                                            java.awt.Color color)

        Build a Table cell

        Parameters:
        text - Simple text
        font - Font to use
        align - Alignment
        border - True to draw the border
        color - Background color
        Returns:
        Table cell
      • getHeaderCell

        public static com.lowagie.text.pdf.PdfPCell getHeaderCell​(java.lang.String text,
                                                                  int align,
                                                                  java.awt.Color color)

        Build a header cell

        Parameters:
        text - header text
        align - cell alignment
        Returns:
        Table cell
      • getHeaderCell

        public static com.lowagie.text.pdf.PdfPCell getHeaderCell​(java.lang.String text,
                                                                  java.awt.Color color)

        Build a header cell

        Parameters:
        text - Text
        Returns:
        Table cell
      • getHeaderCellVertical

        public static com.lowagie.text.pdf.PdfPCell getHeaderCellVertical​(java.lang.String text,
                                                                          java.awt.Color color)

        Build a header cell with vertical text

        Parameters:
        text - Text
        Returns:
        Table cell
      • getColoredCell

        public static com.lowagie.text.pdf.PdfPCell getColoredCell​(java.awt.Color color,
                                                                   boolean border)

        Build an empty colored cell

        Parameters:
        color - Background color
        border - True to draw the border
        Returns:
        Table cell
      • getDecalCell

        public static com.lowagie.text.pdf.PdfPCell getDecalCell​(java.lang.String text,
                                                                 com.lowagie.text.Font font,
                                                                 int align,
                                                                 boolean border,
                                                                 java.awt.Color color)

        Build decaled cell on the right

        Returns:
        Table cell
      • getTable

        public static com.lowagie.text.pdf.PdfPTable getTable​(int[] cols,
                                                              boolean header,
                                                              int spacingBefore,
                                                              int spacingAfter)
                                                       throws com.lowagie.text.DocumentException

        Build a PDF table

        Parameters:
        cols - Table of column sizes or percents; table size = nbr of columns
        Returns:
        PDF Table
        Throws:
        com.lowagie.text.DocumentException
      • getTable

        public static com.lowagie.text.pdf.PdfPTable getTable​(int[] cols,
                                                              boolean header)
                                                       throws com.lowagie.text.DocumentException

        Build a PDF table

        Parameters:
        cols - Table of columns size in percents; table size = nbr of columns
        header - True to display a header line
        Returns:
        PDF Table
        Throws:
        com.lowagie.text.DocumentException
      • getTable

        public static com.lowagie.text.pdf.PdfPTable getTable​(int nbcols,
                                                              boolean header)
                                                       throws com.lowagie.text.DocumentException

        Build a PDF table

        Parameters:
        nbcols - Nb of columns
        header - True to display a header line
        Returns:
        PDF Table
        Throws:
        com.lowagie.text.DocumentException
      • insertList

        public static void insertList​(com.lowagie.text.Document d,
                                      ObjectDB o,
                                      boolean splitOption,
                                      boolean splitBoolean,
                                      boolean splitLongText,
                                      boolean lov,
                                      java.awt.Color headColor,
                                      boolean lovCode)
                               throws com.lowagie.text.DocumentException
        Generic method to serialize one object current list in distinct PDF tables : Mandatories, Options, Booleans, Long text/HTML, images
        Parameters:
        d - Document
        o - Object
        splitOption - Put the optional fields after the main table
        splitBoolean - Put the boolean fields after the main table
        splitLongText - Put the large fields after the main table
        lov - True to insert the lists of values after all
        Throws:
        com.lowagie.text.DocumentException
      • insertList

        public static void insertList​(com.lowagie.text.Document d,
                                      ObjectDB o,
                                      java.util.List<ObjectField> cols,
                                      java.util.List<ObjectField> options,
                                      java.util.List<ObjectField> bools,
                                      java.util.List<ObjectField> larges,
                                      boolean lov,
                                      java.awt.Color headColor,
                                      boolean lovCode)
                               throws com.lowagie.text.DocumentException
        Throws:
        com.lowagie.text.DocumentException
      • getValue

        public static java.lang.String getValue​(ObjectDB o,
                                                ObjectField f,
                                                boolean lovCode)
      • getCellImage

        public static com.lowagie.text.pdf.PdfPCell getCellImage​(java.lang.String path,
                                                                 java.awt.Color bkg)
                                                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getLovParagraph

        public static com.lowagie.text.Paragraph getLovParagraph​(ObjectField f)
      • addHTMLParagraph

        public static com.lowagie.text.Paragraph addHTMLParagraph​(java.lang.String html)
        Add HTML paragraph
        Parameters:
        html - HTML
      • insertForm

        public static void insertForm​(com.lowagie.text.Document d,
                                      ObjectDB o,
                                      java.awt.Color bkg,
                                      boolean lovCode,
                                      boolean emptyValues)
                               throws com.lowagie.text.DocumentException
        Insert object form in PDF (flow of field areas)
        Parameters:
        d - Document
        o - Object
        bkg - Field name background
        lovCode - Display LOV code or label
        emptyValues - true to display empty values
        Throws:
        com.lowagie.text.DocumentException
      • insertForm

        public static void insertForm​(com.lowagie.text.Document d,
                                      ObjectDB o,
                                      java.awt.Color bkg,
                                      boolean lovCode)
                               throws com.lowagie.text.DocumentException
        Insert object form in PDF (flow of field areas)
        Parameters:
        d - Document
        o - Object
        bkg - Field name background
        lovCode - Display LOV code or label
        Throws:
        com.lowagie.text.DocumentException
      • insertFieldArea

        public static com.lowagie.text.pdf.PdfPTable insertFieldArea​(com.lowagie.text.Document d,
                                                                     ObjectDB o,
                                                                     FieldArea fa,
                                                                     java.awt.Color bkg,
                                                                     boolean lovCode,
                                                                     boolean emptyValues)
                                                              throws com.lowagie.text.DocumentException
        Insert a field area as a table of 2 columns
        Parameters:
        d - Document (optional)
        o - Object
        fa - Field area
        bkg - Field name background
        lovCode - Display LOV code or label
        emptyValues - true to display empty values
        Throws:
        com.lowagie.text.DocumentException
      • getImageFromDBDoc

        public static com.lowagie.text.Image getImageFromDBDoc​(Grant g,
                                                               java.lang.String docId)
        Get image from DBDoc image
        Parameters:
        g - Grant
        docId - Image document ID
      • getImageFromDBDoc

        public static com.lowagie.text.Image getImageFromDBDoc​(Grant g,
                                                               DocumentDB doc)
        Get image from from DBDoc image
        Parameters:
        g - Grant
        doc - Image document
      • getImageFromResource

        public static com.lowagie.text.Image getImageFromResource​(Grant g,
                                                                  java.lang.String resourceCode)
        Get image from disposition resource image
        Parameters:
        g - Grant
        resourceCode - Resource code
      • getImageFromResource

        public static com.lowagie.text.Image getImageFromResource​(ObjectDB obj,
                                                                  java.lang.String resourceCode)
        Get image from object resource image
        Parameters:
        obj - Object
        resourceCode - Resource code
      • getImageFromResource

        public static com.lowagie.text.Image getImageFromResource​(com.simplicite.objects.System.ObjectExternal ext,
                                                                  java.lang.String resourceCode)
        Get image from external object resource image
        Parameters:
        ext - External object
        resourceCode - Resource code
      • getImageFromResource

        public static com.lowagie.text.Image getImageFromResource​(Grant g,
                                                                  java.lang.String resourceCode,
                                                                  java.lang.String objectName,
                                                                  java.lang.String objectId)
        Get image from resource image
        Parameters:
        g - Grant
        resourceCode - Resource code
        objectName - Object name (typically Disposition, ObjectInternal or ObjectExternal)
        objectId - Object ID
      • getImageFromStaticResource

        public static com.lowagie.text.Image getImageFromStaticResource​(java.lang.String path)
        Get image from static resource
        Parameters:
        path - Static image resource path
      • getImageFromStaticContent

        public static com.lowagie.text.Image getImageFromStaticContent​(Grant g,
                                                                       java.lang.String relativePath)
        Get image from static content
        Parameters:
        g - Grant
        relativePath - Static content image relative path
      • getImage

        public static com.lowagie.text.Image getImage​(java.lang.String path)
        Get an image from specified file path
        Parameters:
        path - Absolute path to image file
      • getImage

        public static com.lowagie.text.Image getImage​(byte[] data)
        Get an image from specified byte array data
        Parameters:
        data - Image data
      • insertImage

        public static void insertImage​(com.lowagie.text.Document d,
                                       com.lowagie.text.Image img,
                                       boolean canRotate,
                                       int align)
        Insert one image into the document
        Parameters:
        d - PDF document
        img - Image
        canRotate - True to rotate the image when larger than doc width
        align - Image alignment ex: Image.MIDDLE
      • concat

        public static void concat​(java.lang.String out,
                                  java.lang.String in1,
                                  java.lang.String in2)
                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • concat

        public static void concat​(java.io.File out,
                                  java.io.File in1,
                                  java.io.File in2)
                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • concat

        public static byte[] concat​(byte[] in1,
                                    byte[] in2)
                             throws java.lang.Exception
        Throws:
        java.lang.Exception
      • concat

        public static void concat​(java.io.OutputStream os,
                                  java.io.InputStream is1,
                                  java.io.InputStream is2)
                           throws java.lang.Exception
        Throws:
        java.lang.Exception