|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.faceless.pdf2.FDF
public final class FDF
A class representing an FDF
object. "FDF" stands for "Forms Data Format",
and is Adobes format for submitting form data from a PDF to a server, and generating
a response. XFDF, an XML representation of FDF, can be handled the same way.
This class supports both loading an existing FDF file which can be imported into a
PDF via the PDF.importFDF()
method, and creating a new FDF from
a PDF which can then be rendered via the render(java.io.OutputStream)
method.
Here's a simple example showing how to complete a PDF form with an FDF and save the
completed PDF to an OutputStream
.
PDF pdf = new PDF(new PDFReader(new FileInputStream("blankform.pdf"))); FDF fdf = new FDF(new InputStream("data.fdf")); pdf.importFDF(fdf); pdf.render(outputstream);
And here's an example showing how to create an FDF and an XFDF file of all the fields in a PDF's Form
FDF fdf = new FDF(pdf); fdf.setFields(pdf.getForm().getElements().values()); fdf.render(new FileOutputStream("out.fdf")); Document xfdf = fdf.getXFDF(); OutputStream out = new FileOutputStream("out.xfdf"); Transformer tr = TransformerFactory.newInstance().newTransformer(); tr.transform(new DOMSource(xfdf), new StreamResult(out));Note that an FDF may include JavaScript which may be executed when the FDF is imported into the PDF. See
willExecuteJavaScript()
and getJavaScript(java.lang.String)
PDF.importFDF(org.faceless.pdf2.FDF)
,
Form
Field Summary | |
---|---|
static Collection |
ALLANNOTATIONS
Special value that can be passed to setAnnotations(java.util.Collection)
to include all annotations in the PDF |
Constructor Summary | |
---|---|
FDF(InputStream fdfstream)
Create a new FDF from the specified InputStream. |
|
FDF(PDF pdf)
Create a new FDF from the specified PDF. |
Method Summary | |
---|---|
static String |
getCanonicalDate(FormElement field)
For the given field, if it is a Date field return it's value in the "canonical" date format described in the PDF specification (necessary for form submission). |
String |
getDocumentID(boolean primary)
Return the document ID that this FDF belongs to. |
Map |
getFields()
Return a read-only map of all the field values in the FDF. |
String |
getFile()
Return the file associated with this FDF (the "F" entry), or null if not set. |
String |
getJavaScript(String type)
Get the JavaScript from this FDF for the specified event, or null if none is defined. |
Document |
getXFDF()
Get the FDF object as an XFDF Document. |
void |
render(OutputStream out)
Save the FDF file to the specified OutputStream. |
void |
setAnnotations(Collection annots)
Add the specified annotations to the FDF. |
void |
setCanonicalDates(boolean canonicaldates)
Set whether to format dates as canonical dates when creating a new FDF or XFDF file. |
void |
setFields(Collection fields)
Set the fields that are to be included in this FDF. |
void |
setFile(String file)
Set the filename associated with this FDF (the "F" entry). |
void |
setIgnoreErrors(boolean ignore)
Whether to ignore errors when importing this FDF. |
void |
setIncludeEmptyFields(boolean includeempty)
Set whether to include empty fields when creating a new FDF or XFDF file. |
void |
setIncludeUniqueID(boolean includenm)
Set whether to include the "NM" or Unique ID
for each annotation. |
void |
setJavaScript(String type,
String script)
Set the JavaScript for this FDF for the specified event, or null if none is defined. |
boolean |
willExecuteJavaScript()
Return true if this FDF will execute JavaScript on the PDF when it is imported - checks for a "Before", "After" or "AfterPermsReady" event. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Collection ALLANNOTATIONS
setAnnotations(java.util.Collection)
to include all annotations in the PDF
Constructor Detail |
---|
public FDF(InputStream fdfstream) throws IOException
fdfstream
- an InputStream containing the form data.
IOException
public FDF(PDF pdf)
render(java.io.OutputStream)
method.
Method Detail |
---|
public void setFields(Collection fields)
FDF(PDF)
constructor.
fields
- the fields to include - eg. pdf.getForm().getElements().values()
or PDFAction.getFormSubmitFields()
public void setAnnotations(Collection annots)
ALLANNOTATIONS
will add every annotation in the PDF.
Since 2.11.7
public Map getFields()
public void setFile(String file)
file
- the Filename, or null to clear itpublic String getFile()
null
if not set.
public String getDocumentID(boolean primary)
PDF.getDocumentID(boolean)
method,
but returns the ID of the document associated with this FDF (or
null if this is not specified)
primary
- whether to return the primary or secondary ID
null
if no ID is setpublic void setIgnoreErrors(boolean ignore)
public void setIncludeEmptyFields(boolean includeempty)
public void setCanonicalDates(boolean canonicaldates)
public void setIncludeUniqueID(boolean includenm)
Unique ID
for each annotation. The default is no.
public void render(OutputStream out) throws IOException
IOException
public Document getXFDF()
DOMSource source = new DOMSource(fdf.getXFDF()); Transformer tr = TransformerFactory.newInstance().newTransformer(); tr.transform(source), new StreamResult(System.out));
public static String getCanonicalDate(FormElement field)
Field Value
public boolean willExecuteJavaScript()
setJavaScript(java.lang.String, java.lang.String)
on the FDF to clear
out the action that would be run before it is imported.
public String getJavaScript(String type)
null
if none is defined.
type
- one of Doc, Before, After, AfterPermsReadypublic void setJavaScript(String type, String script)
null
if none is defined.
type
- one of Doc, Before, After, AfterPermsReady
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |