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

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
     
    static enum 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    PdfUtilities(byte[] byteArray)
     
    PdfUtilities(String fileName)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    ensure PDF file is closed once no longer needed and all resources released
     
    int
    PdfUtilities pdfUtils=new PdfUtilities("C:/pdfs/mypdf.pdf"); // pdfUtils.setPassword("password"); if (pdfUtils.openPDFFile()) { int commandsOnPage=pdfUtils.getCommandCountForPageStream(); } pdfUtils.closePDFfile();
    access the XML Document properties String (if present) from the open PDF file
    return a Map containing the pair value properties (if present) from the open PDF file -
    return a String detailing the fonts from page
    int
    number of pages in PDF file (starting at 1)
    float[]
    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();
    int
    PdfUtilities pdfUtils = new PdfUtilities("C:/pdfs/mypdf.pdf"); // pdfUtils.setPassword("password"); if (pdfUtils.openPDFFile()) { int P = pdfUtils.getPdfFilePermissions(); } pdfUtils.closePDFfile();
    get the PDF version number
    get image data on pages in PDF file (starting at 1) (Method IS NOT THREADSAFE)
    get XObject data on pages in PDF file (starting at 1)
    boolean
    return boolean to show if Pdf file contains embedded fonts
    boolean
    PdfUtilities pdfUtils = new PdfUtilities("C:/pdfs/mypdf.pdf"); // pdfUtils.setPassword("password"); if (pdfUtils.openPDFFile()) { boolean isMarked = pdfUtils.isMarkedContent(); } pdfUtils.closePDFfile();
    boolean
    PdfUtilities pdfUtils = new PdfUtilities("C:/pdfs/mypdf.pdf"); // pdfUtils.setPassword("password"); if (pdfUtils.isPDFLinearized()) { // file is Linearized and has FastWeb view } pdfUtils.closePDFfile();
    boolean
    routine to open the PDF File so we can access
    void
    setPassword(String password)
     
    static void
    PdfUtilities pdfUtils = new PdfUtilities("C:/pdfs/mypdf.pdf"); // pdfUtils.setPassword("password"); if (pdfUtils.openPDFFile()) { int P = pdfUtils.getPdfFilePermissions(); PdfUtilities.showPermissionsAsString(P); } pdfUtils.closePDFfile();

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PdfUtilities

      public PdfUtilities(String fileName)
    • PdfUtilities

      public PdfUtilities(byte[] byteArray)
  • Method Details

    • getCommandCountForPageStream

      public int getCommandCountForPageStream(int page)
      
           PdfUtilities pdfUtils=new PdfUtilities("C:/pdfs/mypdf.pdf");
           // pdfUtils.setPassword("password");
           if (pdfUtils.openPDFFile()) {
               int commandsOnPage=pdfUtils.getCommandCountForPageStream();
           }
           pdfUtils.closePDFfile();
       
      Parameters:
      page - pdf logical page
      Returns:
      The count of Postscript commands from the page
    • 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)
      
           PdfUtilities pdfUtils=new PdfUtilities("C:/pdfs/mypdf.pdf");
           // pdfUtils.setPassword("password");
           if (pdfUtils.openPDFFile()) {
               String pageImages=pdfUtils.getXImageDataForPage(int page);
           }
           pdfUtils.closePDFfile();
       
      Parameters:
      page - logical page in pdf file
      Returns:
      The image data on the page
    • getXObjectsForPage

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

      public String getFontDataForPage(int page)
      return a String detailing the fonts from page
      
           PdfUtilities pdfUtils=new PdfUtilities("C:/pdfs/mypdf.pdf");
           // pdfUtils.setPassword("password");
           if (pdfUtils.openPDFFile()) {
               String fontDetailsOnPage = pdfUtils.getFontDataForPage(int oage);
           }
      
           pdfUtils.closePDFfile();
       
      Parameters:
      page - pdf logical page
      Returns:
      the fonts on the 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 - 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:
      true 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 -
      
           PdfUtilities pdfUtils = new PdfUtilities("C:/pdfs/mypdf.pdf");
           // pdfUtils.setPassword("password");
           if (pdfUtils.openPDFFile()) {
               Map mapOfValuePairs = pdfUtils.getDocumentPropertyStringValuesAsMap();
           }
      
           pdfUtils.closePDFfile();
       
      Returns:
      A map of document properties from the PDF file
    • getDocumentPropertyFieldsInXML

      public String getDocumentPropertyFieldsInXML()
      access the XML Document properties String (if present) from the open PDF file
      
           PdfUtilities pdfUtils = new PdfUtilities("C:/pdfs/mypdf.pdf");
           // pdfUtils.setPassword("password");
           if (pdfUtils.openPDFFile()) {
                String XMLStringData = pdfUtils.getDocumentPropertyFieldsInXML();
           }
      
           pdfUtils.closePDFfile();
       
      Returns:
      String containing the raw text data
    • getPageDimensions

      public float[] getPageDimensions(int page, PdfUtilities.PageUnits units, PdfUtilities.PageSizeType type)
      
           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();
       
      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
    • isPDFLinearized

      public boolean isPDFLinearized()
      
           PdfUtilities pdfUtils = new PdfUtilities("C:/pdfs/mypdf.pdf");
           // pdfUtils.setPassword("password");
           if (pdfUtils.isPDFLinearized()) {
               // file is Linearized and has FastWeb view
           }
      
           pdfUtils.closePDFfile();
       
      Returns:
      a boolean to show if file is Linearized
    • getPdfFilePermissions

      public int getPdfFilePermissions()
      
           PdfUtilities pdfUtils = new PdfUtilities("C:/pdfs/mypdf.pdf");
           // pdfUtils.setPassword("password");
           if (pdfUtils.openPDFFile()) {
               int P = pdfUtils.getPdfFilePermissions();
           }
      
           pdfUtils.closePDFfile();
       
      Returns:
      an unsigned 32-bit integer containing a set of permission flags
    • isMarkedContent

      public boolean isMarkedContent()
      
           PdfUtilities pdfUtils = new PdfUtilities("C:/pdfs/mypdf.pdf");
           // pdfUtils.setPassword("password");
           if (pdfUtils.openPDFFile()) {
               boolean isMarked = pdfUtils.isMarkedContent();
           }
      
           pdfUtils.closePDFfile();
       
      Returns:
      true if fully meets MarkedContent specification - may still be able to extract something if false
    • showPermissionsAsString

      public static void showPermissionsAsString(int P)
      
           PdfUtilities pdfUtils = new PdfUtilities("C:/pdfs/mypdf.pdf");
           // pdfUtils.setPassword("password");
           if (pdfUtils.openPDFFile()) {
               int P = pdfUtils.getPdfFilePermissions();
               PdfUtilities.showPermissionsAsString(P);
           }
      
           pdfUtils.closePDFfile();
       
      Parameters:
      P - a 32-bit integer containing permission flags extracted from PDF