Class PdfUtilities


  • public class PdfUtilities
    extends Object

    PdfUtilities

    This class provides a simple Java API to access general PDF features in JPEDAL via a simple API

    • Constructor Detail

      • PdfUtilities

        public PdfUtilities​(String fileName)
      • PdfUtilities

        public PdfUtilities​(byte[] byteArray)
    • Method Detail

      • getCommandCountForPageStream

        public int getCommandCountForPageStream​(int page)
        return a count of Postscript commands from page -
        Returns:

        PdfUtilities pdfUtils=new PdfUtilities("C:/pdfs/mypdf.pdf");
         //pdfUtils.setPassword("password");
         if (pdfUtils.openPDFFile()) {
          int commandsOnPage=pdfUtils.getCommandCountForPageStream();
         }
        
         pdfUtils.closePDFfile();
      • setPassword

        public void setPassword​(String password)
        Parameters:
        password - the USER or OWNER password for the PDF file
      • getPageCount

        public int getPageCount()
        number of pages in PDF file (starting at 1)
        Returns:
        page count

        PdfUtilities pdfUtils=new PdfUtilities("C:/pdfs/mypdf.pdf");
         //pdfUtils.setPassword("password");
         if (pdfUtils.openPDFFile()) {
         int pageCount=pdfUtils.getPageCount();
         }
        
         pdfUtils.closePDFfile();
      • getXImageDataForPage

        public String getXImageDataForPage​(int page)
        get image data on pages in PDF file (starting at 1) (Method IS NOT THREADSAFE)
        Returns:
        page count

        PdfUtilities pdfUtils=new PdfUtilities("C:/pdfs/mypdf.pdf");
         //pdfUtils.setPassword("password");
         if (pdfUtils.openPDFFile()) {
         String pageImages=pdfUtils.getXImageDataForPage(int page);
         }
        
         pdfUtils.closePDFfile();
      • getFontDataForPage

        public String getFontDataForPage​(int page)
      • getAllFontDataForDocument

        public Map<Integer,​String> getAllFontDataForDocument()
      • openPDFFile

        public boolean openPDFFile()
                            throws PdfException
        routine to open the PDF File so we can access
        Returns:
        true if successful
        Throws:
        PdfException
      • closePDFfile

        public void closePDFfile()
        ensure PDF file is closed once no longer needed and all resources released
      • hasEmbeddedFonts

        public boolean hasEmbeddedFonts()
        return boolean to show if Pdf file contains embedded fonts

        PdfUtilities pdfUtils=new PdfUtilities("C:/pdfs/mypdf.pdf");
         //pdfUtils.setPassword("password");
         if (pdfUtils.openPDFFile()) {
          boolean usesEmbeddedFonts=pdfUtils.hasEmbeddedFonts();
         }
        
         pdfUtils.closePDFfile();
      • getDocumentPropertyStringValuesAsMap

        public Map<String,​String> getDocumentPropertyStringValuesAsMap()
        return a Map containing the pair value properties (if present) from the open PDF file -
        Returns:

        PdfUtilities pdfUtils=new PdfUtilities("C:/pdfs/mypdf.pdf");
         //pdfUtils.setPassword("password");
         if (pdfUtils.openPDFFile()) {
          Map mapOfValuePairs=pdfUtils.getDocumentPropertyStringValuesAsMap();
         }
        
         pdfUtils.closePDFfile();
      • getDocumentPropertyFieldsInXML

        public String getDocumentPropertyFieldsInXML()
        access the XML Document properties String (if present) from the open PDF file
        Returns:
        String containing the raw text data

        PdfUtilities pdfUtils=new PdfUtilities("C:/pdfs/mypdf.pdf");
         //pdfUtils.setPassword("password");
         if (pdfUtils.openPDFFile()) {
          String XMLStringData=pdfUtils.getDocumentPropertyFieldsInXML();
         }
        
         pdfUtils.closePDFfile();
      • getPageDimensions

        public float[] getPageDimensions​(int page,
                                         PdfUtilities.PageUnits units,
                                         PdfUtilities.PageSizeType type)
        Parameters:
        page - is pageNumber
        units - units to use for pageSize dimensions (pixels, Inches, Centimetres) except rotation which is always in degrees
        type - which values to select (MediaBox, CropBox)
        Returns:
        a float[] with 5 values:- x,y,w,h, pageRotation

        PdfUtilities pdfUtils=new PdfUtilities("C:/pdfs/mypdf.pdf");
         //pdfUtils.setPassword("password");
         if (pdfUtils.openPDFFile()) {
          float[] pageDimensions=pdfUtils.getPageDimensions(pageNum, PageUnits.Inches, PageSizeType.CropBox);
         }
        
         pdfUtils.closePDFfile();
      • getPdfFilePermissions

        public int getPdfFilePermissions()
        Returns:
        an unsigned 32-bit integer containing a set of permission flags

        PdfUtilities pdfUtils=new PdfUtilities("C:/pdfs/mypdf.pdf");
         //pdfUtils.setPassword("password");
         if (pdfUtils.openPDFFile()) {
          int P = pdfUtils.getPdfFilePermissions();
         }
        
         pdfUtils.closePDFfile();
      • showPermissionsAsString

        public static void showPermissionsAsString​(int P)
        Parameters:
        P - a 32-bit integer containing permission flags extracted from PDF

        PdfUtilities pdfUtils=new PdfUtilities("C:/pdfs/mypdf.pdf");
                  //pdfUtils.setPassword("password");
                  if (pdfUtils.openPDFFile()) {
                   int P = pdfUtils.getPdfFilePermissions();
                   PdfUtilities.showPermissionsAsString(P);
                  }
        
                  pdfUtils.closePDFfile();