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 – Forms

1 min read

JPedal6In my third article, I covered general PDF handling. In the fourth part I will look at some of  the forms features which are available in  JPedal 6.

 

Access PDF Form Data

JPedal includes extensive support for Interactive Forms and Compnents which is converts into Java Object representations and also allows access to Forms names and the GUI representations. The data can be accessed with a single call on a page or document basis.

PdfFormUtilities extract=new PdfFormUtilities("C:/pdfs/mypdf.pdf");
 //extract.setPassword("password");
 if (extract.openPDFFile()) {
      //all formNames
      Object[] names=extract.getFormComponentsFromDocument(null, ReturnValues.FORM_NAMES);
 
      // all forms in document called Mabel
      Object[] PDFObjectsAsPoJos=extract.getFormComponentsFromDocument("Mabel", ReturnValues.FORMOBJECTS_FROM_NAME);
 
      //a form with PDF Reference 25 0 R
      Object[] PDFObjectsAsPoJos=extract.getFormComponentsFromDocument("25 0 R", ReturnValues.FORMOBJECTS_FROM_REF);
 
      //all Swing versions of the Form objects
      Object[] swingComponents=extract.getFormComponentsFromDocument(null, ReturnValues.GUI_FORMS_FROM_NAME);
 
      //all formNames on page 5
      Object[] names=extract.getFormComponentsFromPage(null, ReturnValues.FORM_NAMES,5);
 
      // all forms in document called Mabel on page 5
      Object[] PDFObjectsAsPoJos=extract.getFormComponentsFromPage("Mabel", ReturnValues.FORMOBJECTS_FROM_NAME,5);
 
      //a form with PDF Reference 25 0 R on page 5
      Object[] PDFObjectsAsPoJos=extract.getFormComponentsFromPage("25 0 R", ReturnValues.FORMOBJECTS_FROM_REF,5);
 
      //all Swing versions of the Form objects on page 5
      Object[] swingComponents=extract.getFormComponentsFromPage(null, ReturnValues.GUI_FORMS_FROM_NAME,5);
 }
 
 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 *