Sign UpSign Up   Sign InSign In Welcome Guest,
Live Chat Live Chat

Copy form fields from one PDF to another

Last post 03-28-2009, 3:17 AM by forever. 23 replies.
Page 1 of 2 (24 items)   1 2 Next >
Sort Posts: Previous Next
  •  12-18-2008, 3:13 PM 157266

    Copy form fields from one PDF to another

    We deal with alot of PDFs where legal disclosures are constantly edited.   These forms also have form fields on them.   When we recieve a new form from our legal department they do not have form fields on them, but the layout of the form is exactly the same.   We would like to automatically copy all of the form fields from the old document to the new one in an automated fashion.   Can we do this with the Aspose.Pdf.Kit?   If so I would love to see some code examples on how to accomplish this.

     
  •  12-19-2008, 2:34 AM 157321 in reply to 157266

    Re: Copy form fields from one PDF to another

    Dear ChadBoyer,

    Thanks for considering Aspose.Pdf.Kit.

    Honestly, there isn't any interface to meet your requirement. However, you can copy simple field through the following workaround:

       string path = TestPath + @"gemini_6947\";
       Form myForm = new Form(path + "FieldCopy.in.pdf");
       String fieldName = "Button1";
       //get field type
       FieldType myType = myForm.GetFieldType(fieldName);
       //get field value
       String myValue = myForm.GetField(fieldName);
       //get field appearance
       FormFieldFacade myFacade = myForm.GetFieldFacade(fieldName);
       myForm.Save();

       FormEditor editor = new FormEditor(path + "Empty.pdf", path + "FieldCopy.out.pdf");
       //create a new field using information above
       editor.AddField(myType, fieldName, myValue,  myFacade.PageNumber, myFacade.Box.Left, myFacade.Box.Bottom, myFacade.Box.Left + myFacade.Box.Width, myFacade.Box.Bottom +  myFacade.Box.Height);
       editor.Save();

    However, this can only work with AcroForm Field. And information such as color, border ... will be lost. We are still working to develop new interface for this feature, but it won't be finished in a short time. Sorry for the inconvenience.

    Best Regards.


    Luke Fu
    Product Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
  •  12-19-2008, 10:07 AM 157407 in reply to 157321

    Re: Copy form fields from one PDF to another

    Thank you for your example.   The only problem with it is I don't have a property named "PageNumber" exposed on the FormFieldFascade class.   I am using 3.3.0.0.

     
  •  12-19-2008, 1:58 PM 157431 in reply to 157407

    Re: Copy form fields from one PDF to another

    Dear ChadBoyer,

    Sorry for my carelessness. That property is only included in the testing version, and it will be provided in the coming new release. As for your problem, please replace it with the actual page number in which page the field is located, such as 1, 2 or 3.

    FormEditor.LocalCopyField( ) is already provided to copy field within a PDF document. We decide to provide new functions for remote field copying. Before that, please try the workaround.

    Any other question is also welcomed. Best regards.


    Luke Fu
    Product Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
  •  12-19-2008, 5:13 PM 157458 in reply to 157431

    Re: Copy form fields from one PDF to another

    Attachment: Present (inaccessible)

    Chad and I work together.  We have tried another approach to copy form fields from one PDF to another.  I am having some issues though.  I have attached some sample PDFs that work with the code I have pasted below.

    Issue 1 - Textbox values:
    The textboxes copy to the right place in the new PDF and even the size if fine, but when I try to type in the field all of the input stacks on top of each other within the textbox.

    Issue 2 – RadioButtonList position:
    When I copy over the RadioButtonList form control it creates the correct number of radio button items but it does not position them correctly on the screen. The first thing I noticed is that the entire list of radio buttons is treated as one form field name and is only represented once in the Form.FieldNames collection.  This also means that I can only get to the FormFieldFacade of the container control and not the individual parts/radio button items.  I did see the RadioHoriz and RadioGap on the FormEditor object from which I am using to add the field to the new PDF, but my problem is that the spacing on the individual radio button items is not consistent it needs to draw both across and down i.e. 2 columns and 3 rows.  If I could somehow get to the individual radio button items in the Form and then be able to add a list of radio button items contained within a RadioButtonList field/control then I think this would solve this issue.

    Issue 3 – RadioButtonList type/style:
    The style of my radio button list items is a check instead of a circle but I cannot figure out how to set this.

    string copyFieldsFromPdf = @"C:\Temp\FormFields\CopyFieldsFromPdf.pdf";
    string copyToPdf = @"C:\Temp\FormFields\CopyToPdf.pdf";
    string outputPdf = @"C:\Temp\FormFields\OutputPdf.pdf";
    
    PdfFileInfo orriginalPdfFileInfo = new PdfFileInfo(copyFieldsFromPdf);
    int orriginalNumberOfPages = orriginalPdfFileInfo.NumberofPages;
    
    PdfFileInfo emptyPdfFileInfo = new PdfFileInfo(copyToPdf);
    int emptyNumberOfPages = emptyPdfFileInfo.NumberofPages;
    
    PdfFileEditor pdfFileEditor = new PdfFileEditor();
    MemoryStream[] orriginalPdfPageStreams = pdfFileEditor.SplitToPages(copyFieldsFromPdf);
    
    FormEditor formEditor = new FormEditor(copyToPdf, outputPdf);
    
    for (int i = 0; i < orriginalNumberOfPages && i < emptyNumberOfPages; i++)
    {
        Aspose.Pdf.Kit.Form pdfForm = new Aspose.Pdf.Kit.Form(orriginalPdfPageStreams[i]);
    
        foreach (string fieldName in pdfForm.FieldsNames)
        {
            string fullName = pdfForm.GetFullFieldName(fieldName);
            FormFieldFacade facade = pdfForm.GetFieldFacade(fullName);
    
            float lowLeftX = facade.Box.Left;
            float lowLeftY = facade.Box.Bottom;
            float upRightX = facade.Box.Left + facade.Box.Width;
            float upRightY = facade.Box.Top;
            int pageNumber = i + 1;
    
            formEditor.Facade = facade;
            //formEditor.RadioHoriz;
            //formEditor.RadioGap
            formEditor.Items = facade.Items;
            formEditor.AddField(pdfForm.GetFieldType(fieldName), fieldName, pageNumber, lowLeftX, lowLeftY, upRightX, upRightY);
        }
    }
    
    formEditor.Save();
    

    Thanks,
    Ryan

     
  •  12-20-2008, 4:17 AM 157477 in reply to 157458

    Re: Copy form fields from one PDF to another

    Dear Ryan,

    What I introduced before is just a workaround, it only works for simple field creation. That is, the newly created field can only be specified with the location and an initial value. Those three issues cannot be satisfied by the workaround method.

    Please describe your requirement in detail, so as we can develop new interface for field copying across different documents.

    Best regards.


    Luke Fu
    Product Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
  •  12-23-2008, 9:18 AM 157801 in reply to 157477

    Re: Copy form fields from one PDF to another

    The driving factor behind our pursuing this functionality is that we have PDF forms that we use Acrobat Professional to draw a bunch of form fields on.  We then receive updated forms on a regular basis where the text in PDF changes but the location of the form fields stays the same.  These updated forms do not have form fields on them so we have to get the form fields from one of the old forms that we have already drawn the form fields on then copy them to the new form.  Acrobat Professional only allows us to select a page worth of form fields at a time and many of the forms have multiple pages.  This becomes a very time consuming process switching back and forth between the forms to copy over all of the form fields.

    We would like to see the Aspose.Pdf.Kit control expose a method where we provide an old form with form fields on it and a new form that does not have form fields on it and it would then copy over every form field as it is on the old form to the new form.  This would include radio button lists their display type and location of each individual radio button list item.  To keep it simple this method would place an exact copy of all form fields in the old PDF on the new PDF.  Keep in mind the new PDF already has text, images, etc. just no form fields.

     
  •  12-23-2008, 6:16 PM 157935 in reply to 157801

    Re: Copy form fields from one PDF to another

    Dear Ryan,

    Thanks for your detailed description. We will investigate into it and try to support this feature :) But I am afraid the ETA will be one month.

    Best regards.


    Luke Fu
    Product Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
  •  12-24-2008, 11:22 AM 158021 in reply to 157935

    Re: Copy form fields from one PDF to another

    This is a feature that is worth the wait for us!

    Thanks,
    Ryan

     
  •  02-10-2009, 1:39 PM 164473 in reply to 157935

    Re: Copy form fields from one PDF to another

    I was wondering if there had been any progress made on this feature?

    Ryan

     
  •  02-10-2009, 4:58 PM 164505 in reply to 164473

    Re: Copy form fields from one PDF to another

    Hello Ryan,

    Our development team is working hard to get this issue resolved, but as Luke have mentioned, the ETA for the resolution of this problem is on month. Your patience in this regard is highly appreciated.


    Nayyer Shahbaz
    Support Developer, Aspose Sialkot Team
    About Us
    Contact Us

    Keep in touch! We're on Twitter and Facebook
     
  •  02-10-2009, 5:50 PM 164513 in reply to 164505

    Re: Copy form fields from one PDF to another

    Dear Ryan,

    Thanks for your patience. Actually, this feature has been finished. It will be included in the next release after more careful testing.

    If you need the function urgently, please let us know. We can provide you a trial version before the public release.

    Best regards.


    Luke Fu
    Product Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
  •  02-11-2009, 8:58 AM 164658 in reply to 164513

    Re: Copy form fields from one PDF to another

    We would be very excited to test it out for you and provide feedback before you release the feature.  We have quite a few PDF forms that we would use this on right away.  How would we go about getting a test trial version?

    Ryan

     
  •  02-11-2009, 8:59 PM 164785 in reply to 164658

    Re: Copy form fields from one PDF to another

    Dear ryan,

    Our Product Manager will upload the trial version here soon. Please download it and test it.

    FYI:
    1. XfaForm documents are not supported.
    2. Radio Button is different with other form types, we are looking for some easy ways to copy. Hope it will be included in the next coming formal release.
    3. Three methods are introduced:
    public void OuterCopyField(String srcFileName, String fieldName)
    public void OuterCopyField(String srcFileName, String fieldName, int pageNum)
    public void OuterCopyField(String srcFileName, String fieldName, int pageNum, float abscissa, float ordinate)

    You can just copy the field to its original page & position, or you can specify its new page & position.

    Best regards.


    Luke Fu
    Product Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
  •  02-12-2009, 1:07 AM 164811 in reply to 164785

    Re: Copy form fields from one PDF to another

    Attachment: Present (inaccessible)

    Hi,

    The attachment includes a Beta dll(3.3.1.2) and the API documentation, please download and try it.

    Thanks,


    Felix Liu
    Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
Page 1 of 2 (24 items)   1 2 Next >
View as RSS news feed in XML