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) 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 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 pageint
number of pages in PDF file (starting at 1)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();
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 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
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 accessvoid
setPassword
(String password) 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();
-
Constructor Details
-
PdfUtilities
-
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
- 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)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
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
return a String detailing the fonts from pagePdfUtilities 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
-
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:
true
if present in pdf file
-
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
access the XML Document properties String (if present) from the open PDF filePdfUtilities 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 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
-
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
-