|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.justformspdf.pdf.PDF
The PDF class is responsible for accessing PDF forms, rendering form fields and writing generated PDF to an output stream. In a typical program following is the sequence of operations:
PDFReader
To make the API calls simple and efficient there are only a few public methods available to the users of this class.
Here is an example showing how PDF object should be constructed.
FileInputStream fis = new FileInputStream("C:\\JustFormsPDF\\examples\\AddressForm32A2.pdf"); PDF pdf = new PDF(new PDFReader(fis)); FormText text = (FormText) form.getElement("Name"); text.setValue("John K. Baker"); pdf.render(); pdf.writeTo(new FileOutputStream("C:\\JustFormsPDF\\examples\\AddressForm32A2_out.pdf"));
Constructor Summary | |
PDF(com.justformspdf.pdf.PDFReader reader) Create PDF object from the specified PDFReader object. |
Method Summary | |
com.justformspdf.pdf.Form |
getForm() Return the parsed PDF AcroForm or Form object containing all the form elements. |
int |
getSize() Get the size of modified/updated PDF file in bytes |
boolean |
isSaveProtected() Get the "Save Protected" flag. |
void |
render() This method renders the PDF document with new or modified form elements. |
void |
setSaveProtected(boolean b) Set the "Save Protected" flag. |
void |
writeTo(java.io.OutputStream os) This method writes the updated/modified PDF contents to an OutputStream The output stream can be a File stream or Servlet (to browser) stream. |
Constructor Detail |
public PDF(com.justformspdf.pdf.PDFReader reader)
Here is an example showing how PDF object should be constructed.
FileInputStream fis = new FileInputStream("C:\\JustFormsPDF\\examples\\AddressForm32A2.pdf"); PDF pdf = new PDF(new PDFReader(fis));
reader
- the PDFReader objectMethod Detail |
public void render() throws java.lang.Exception
Here is an example showing the user of render() method.
//... //... FormText text = (FormText) form.getElement("Name"); text.setValue("John K. Baker"); pdf.render(); pdf.writeTo(new FileOutputStream("C:\\JustFormsPDF\\examples\\AddressForm32A2_out.pdf")); //... //...java.lang.Exception
public void writeTo(java.io.OutputStream os) throws java.lang.Exception
Here is an example showing how a PDF should be streamed to a file.
pdf.render(); pdf.writeTo(new FileOutputStream("C:\\JustFormsPDF\\examples\\AddressForm32A2_out.pdf"));
Here is an example showing how a PDF should be streamed to a browser (using Servlet's HttpResponse object)
pdf.render(); resp.setContentType("application/pdf"); pdf.writeTo(resp.getOutputStream());
os
- the output streamjava.lang.Exception
public com.justformspdf.pdf.Form getForm()
Here is an example showing how PDF Form object should be accessed and how its elements should be filled or modified.
FileInputStream fis = new FileInputStream("C:\\JustFormsPDF\\examples\\AddressForm32A2.pdf"); PDF pdf = new PDF(new PDFReader(fis)); Form form = pdf.getForm(); FormText name = (FormText) form.getElement("Name"); name.setValue("John K. Baker"); FormCheckbox addressType = (FormCheckbox) form.getElement("AddressTypePerm"); addressType.check(true); FormComboBox suffix = (FormComboBox) form.getElement("Suffix"); //suffix.setValue("5"); suffix.setValueByIndex(5); FormRadioGroup ethnic = (FormRadioGroup) form.getElement("ethnic"); //ethnic.setValue("ETH02"); ethnic.setValueByIndex(2);
Form
public int getSize()
public boolean isSaveProtected()
This save-protected feature can be used in a browser based application to restrict users from saving the generated PDFs.
setSaveProtected(boolean)
public void setSaveProtected(boolean b)
This feature can be used in a browser based application to make generated PDFs save-protected. If you want your application user just view the PDF and do not save it you may try this feature. Some advanced user may still 'hack' this feature by altering the contents of generated PDF by opening it into a text or hex editor but for most of the users this feature will work fine.
Here is an example showing the user of render() method.
//... FileInputStream fis = new FileInputStream("C:\\JustFormsPDF\\examples\\AddressForm32A2.pdf"); PDF pdf = new PDF(new PDFReader(fis)); //... //... pdf.setSaveProtected(false); //... //...
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |