Class PDFUtils


  • public final class PDFUtils
    extends java.lang.Object

    Class that contains tools to manage of PDF files.

    Project:

    Library for the integration with the services of @Firma, eVisor and TS@.

    Version:
    1.0, 19/08/2020.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] addAttachment​(byte[] pdf, java.util.ArrayList<FileAttachment> attachments)
      Adds the supplied attachment list to supplied PDF.
      static byte[] concatPDF​(byte[] pdf1, byte[] pdf2, java.lang.String identifier1, java.lang.String identifier2, java.lang.String rule)
      Concatenates the supplied PDF files.
      static byte[] concatPDFs​(java.util.List<byte[]> files)
      Methods that concatenates the supplied PDF files to a PDF file.
      static int getNumPages​(byte[] document)
      Gets the page number of a PDF document.
      static java.util.List<java.lang.String> getPagesOrientation​(byte[] document)
      Gets a List of String that represents the orientation of each page.
      static byte[] imageToPDF​(byte[] image)
      Method that converts a image file to PDF file.
      static byte[] includePages​(byte[] targetPdf, byte[] originPdf, MatrixPagesInclude pagesIncl)
      Method that creates a PDF file by including a document in another with the specified rules.
      static boolean isPDFFile​(byte[] file)
      Checks if the supplied document is a PDF document.
      • Methods inherited from class java.lang.Object

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

      • addAttachment

        public static byte[] addAttachment​(byte[] pdf,
                                           java.util.ArrayList<FileAttachment> attachments)
                                    throws SignatureReportException
        Adds the supplied attachment list to supplied PDF.
        Parameters:
        pdf - PDF file.
        attachments - Attachment files.
        Returns:
        Modified file.
        Throws:
        SignatureReportException - if an error occurs.
      • concatPDF

        public static byte[] concatPDF​(byte[] pdf1,
                                       byte[] pdf2,
                                       java.lang.String identifier1,
                                       java.lang.String identifier2,
                                       java.lang.String rule)
                                throws UtilsException
        Concatenates the supplied PDF files.
        Parameters:
        pdf1 - PDF file.
        pdf2 - PDF file.
        identifier1 - Token used to identifies the first input document.
        identifier2 - Token used to identifies the second input document.
        rule - Concatenation rule.Ej: $identifier1(1)+ $identifier2(4-6). Concat the page 1 of the first document with the pages 4 to 6 of the second document.
        Returns:
        Concatenated PDF file.
        Throws:
        UtilsException - If an error occurs.
      • isPDFFile

        public static boolean isPDFFile​(byte[] file)
        Checks if the supplied document is a PDF document.
        Parameters:
        file - Document to check.
        Returns:
        True if the document is a PDF file. Otherwise false
      • includePages

        public static byte[] includePages​(byte[] targetPdf,
                                          byte[] originPdf,
                                          MatrixPagesInclude pagesIncl)
                                   throws UtilsException
        Method that creates a PDF file by including a document in another with the specified rules.
        Parameters:
        targetPdf - Target document.
        originPdf - Original document.
        pagesIncl - Rules.
        Returns:
        A PDF document.
        Throws:
        UtilsException - If an error occurs.
      • getNumPages

        public static int getNumPages​(byte[] document)
                               throws UtilsException
        Gets the page number of a PDF document.
        Parameters:
        document - PDF document.
        Returns:
        Page number.
        Throws:
        UtilsException - If an error occurs.
      • getPagesOrientation

        public static java.util.List<java.lang.String> getPagesOrientation​(byte[] document)
                                                                    throws UtilsException
        Gets a List of String that represents the orientation of each page.
        Parameters:
        document - PDF document.
        Returns:
        a List of String that represents the orientation of each page.
        Throws:
        UtilsException - If an error occurs.
      • concatPDFs

        public static byte[] concatPDFs​(java.util.List<byte[]> files)
                                 throws UtilsException
        Methods that concatenates the supplied PDF files to a PDF file.
        Parameters:
        files - List of PDF files.
        Returns:
        Concatenated PDF file.
        Throws:
        UtilsException - If an error occurs.
      • imageToPDF

        public static byte[] imageToPDF​(byte[] image)
                                 throws UtilsException
        Method that converts a image file to PDF file.
        Parameters:
        image - Image file.
        Returns:
        PDF file.
        Throws:
        UtilsException - If an error occurs.