The Adobe PDF Java Toolkit has a number of facilities for working with forms in PDF files. One of the fundamental operations in working with forms is determining the type of form in a document, if one exists. While we were writing a sample that demonstrates this with PDFJT, we thought this might be a tool that would be handy for others – so we’ve put up a simple web demo based on this sample for you to use.
The web page uses PDFJT and the FormTypeEvaluator sample that we recently created and added to PDFJT to display information on the type of form in a PDF file by using the
API call. There are four different document types that it can return :
- Flat – the PDF contains no forms
- AcroForm – form is defined through dictionaries of PDF objects
- StaticXFA – form is defined in XML and its form elements refer to AcroForm elements
- DynamicXFA – form is defined in xml but the document contains only a PDF shell, enough to state a viewer can’t process the file
Let’s take a look at the code that drives this sample :
1) Create a PDFDocument object from a file on disk
File pdfFile = new File(inputFile); FileInputStream fis = new FileInputStream(pdfFile); ByteReader reader = new InputStreamByteReader(fis); PDFDocument doc = PDFDocument.newInstance(reader, PDFOpenOptions.newInstance());
2) Use the XFAService to get the document’s type.
System.out.println("This document's type is : " + XFAService.getDocumentType(doc).toString());
Simple, no? We hope you find this useful and welcome your feedback.