clone PDF form

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Generator for Java (v4)  /  clone PDF form

DynamicPDF Generator for Java (v4) Forum

 Mar 03 2010 8:26 AM
Hello,

I have the following use-case: Load PDF form from existing PDF file A and merge/place the same PDF form into document B.

How can I do that? I have tried simply by automatically inspecting the form in document A and try to create the same structure in document B but the code becomes excessively complex. The complexity is given because:

- There are multiple ways to search for form fields
- There are separate parallel hierarchies for form fields
- It seems not possible to read properties from the existing form fields e.g. TextField how to retrieve x, y, width, height.

com.cete.dynamicpdf.forms.TextField does not seem to have anything like getX(), getY(), getHeight(), getWidth() so how else can I replicate an existing loaded (from file) PDF form into a different document?

Thanks in advance,
Best regards,
Giovanni
 Mar 03 2010 9:05 AM
Posted by a ceTe Software moderator
Hello Giovanni,

You can get the field information from one PDF and create a similar field in another PDF without any problem.

    PdfDocument pdf = new PdfDocument( filePath );
    PdfFormField pdfField = pdf.getForm().getFields().getPdfFormField("fieldName");
    float x = pdfField.getX( currPage );
    float width = pdfField.getWidth();

You can use the above information to add new fields to another PDF.

    Document document = new Document();
    Page page = new Page();
    //This text field is from com.cete.dynamicpdf.pageelements.forms.
    TextField field = new TextField( "txt", x, y, width, height );

You can refer to the TextField and Form Flattening examples on our help documentation.

Thanks,
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 1:51 PM.