Class PdfUtilities

java.lang.Object
org.jpedal.examples.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 Details

    • PdfUtilities

      public PdfUtilities(String fileName)
    • PdfUtilities

      public PdfUtilities(byte[] byteArray)
  • Method Details

    • getCommandCountForPageStream

      public int getCommandCountForPageStream(int page)
      return a count of Postscript commands from page -
      Parameters:
      page - pdf logical 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
    • getPDFVersion

      public String getPDFVersion()
      get the PDF version number
      Returns:
      PDF version
    • getXImageDataForPage

      public String getXImageDataForPage(int page)
      get image data on pages in PDF file (starting at 1) (Method IS NOT THREADSAFE)
      Parameters:
      page - logical page in pdf file
      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();
    • getXObjectsForPage

      public String getXObjectsForPage(int page)
      get XObject data on pages in PDF file (starting at 1)
      Parameters:
      page - logical page in pdf file
      Returns:
      page count
      PdfUtilities pdfUtils=new PdfUtilities("C:/pdfs/mypdf.pdf");
       //pdfUtils.setPassword("password");
       if (pdfUtils.openPDFFile()) {
       String pageXObjects = pdfUtils.getXObjectsForPage(int page);
       }
      
       pdfUtils.closePDFfile();
    • getFontDataForPage

      public String getFontDataForPage(int page)
      return a String detailing the fonts from page -
      Parameters:
      page - pdf logical page
      Returns:
      PdfUtilities pdfUtils=new PdfUtilities("C:/pdfs/mypdf.pdf");
       //pdfUtils.setPassword("password");
       if (pdfUtils.openPDFFile()) {
        String fontDetailsOnPage = pdfUtils.getFontDataForPage(int oage);
       }
      
       pdfUtils.closePDFfile();
    • 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 - if problem with opening a PDF file
    • 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();
      Returns:
      flag to show if present in pdf file
    • 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();
    • isPDFLinearized

      public boolean isPDFLinearized()
      Returns:
      a boolean to show if file is Linearized
      PdfUtilities pdfUtils=new PdfUtilities("C:/pdfs/mypdf.pdf");
       //pdfUtils.setPassword("password");
       if (pdfUtils.isPDFLinearized()) {
        //file is Linearized and has FastWeb view
       }
      
       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();
    • isMarkedContent

      public boolean isMarkedContent()
      Returns:
      a boolean showing if fully meets MarkedContent specification - may still be able to extract something if false
      PdfUtilities pdfUtils=new PdfUtilities("C:/pdfs/mypdf.pdf");
       //pdfUtils.setPassword("password");
       if (pdfUtils.openPDFFile()) {
        boolean isMarked = pdfUtils.isMarkedContent();
       }
      
       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();