Mark Stephens

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.

He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

New APIs to handle PDF files in JPedal 6 – General Features

1 min read

JPedal6In my second article I covered PDF files and text handling. In the third part I will look at general Utilities features which are available in  JPedal 6.

 

 

Get a page count

JPedal makes it very easy to scan the pages of a PDF file for text. This features is built into all examples so it also accessible from other examples or as part of the PdfUtilities class. Here is a simple example (Javadoc).
JPedal includes some very powerful features for text search including regular expressions.

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

Access PDF page size and rotation

Every page in a  PDF document can have its own dimensions and rotation. MediaBox is the actual page size and CropBox is the visible page size (we recommend you always use CropBox.

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

Detect if embedded fonts used in PDF Document

JPedal allows the user to see if embeddedFonts are used in the PDF document.

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

Access PDF Document properties

A PDF document can contain a set of pre-defined Document properties or an XML value containing any data.

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

The JPedal API provides a great deal of easy to use functionality with PDF handling. Are there any other additional features you would like to see?
Next time we look at making some more features in the JPedal library easily available with a new API.

If you’re a first-time reader, or simply want to be notified when we post new articles and updates, you can keep up to date by social media (Twitter, Facebook and Google+) or the Blog RSS.

Mark Stephens

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.

He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Leave a Reply

Your email address will not be published. Required fields are marked *