Package org.jpedal.examples
Class PdfUtilities
java.lang.Object
org.jpedal.examples.PdfUtilities
PdfUtilities
This class provides a simple Java API to access general PDF features in JPEDAL via a simple API
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
static enum
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
ensure PDF file is closed once no longer needed and all resources releasedint
getCommandCountForPageStream
(int page) return a count of Postscript commands from page -access the XML Document properties String (if present) from the open PDF filereturn a Map containing the pair value properties (if present) from the open PDF file -getFontDataForPage
(int page) return a String detailing the fonts from page -int
number of pages in PDF file (starting at 1)float[]
getPageDimensions
(int page, PdfUtilities.PageUnits units, PdfUtilities.PageSizeType type) int
get the PDF version numbergetXImageDataForPage
(int page) get image data on pages in PDF file (starting at 1) (Method IS NOT THREADSAFE)getXObjectsForPage
(int page) get XObject data on pages in PDF file (starting at 1)boolean
return boolean to show if Pdf file contains embedded fontsboolean
boolean
boolean
routine to open the PDF File so we can accessvoid
setPassword
(String password) static void
showPermissionsAsString
(int P)
-
Constructor Details
-
PdfUtilities
-
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
- 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
get the PDF version number- Returns:
- PDF version
-
getXImageDataForPage
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
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
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
-
openPDFFile
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 fontsPdfUtilities 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
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
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 pageNumberunits
- units to use for pageSize dimensions (pixels, Inches, Centimetres) except rotation which is always in degreestype
- 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 PDFPdfUtilities pdfUtils=new PdfUtilities("C:/pdfs/mypdf.pdf"); //pdfUtils.setPassword("password"); if (pdfUtils.openPDFFile()) { int P = pdfUtils.getPdfFilePermissions(); PdfUtilities.showPermissionsAsString(P); } pdfUtils.closePDFfile();
-