Hi, I own the PDF-XChange Pro SDK (Viewer and Tools, etc..) and I've come across a new requirement from my client. They want me to fill in a PDF automatically based on data in a database. My initial thoughts are that I hope I have what I need with the SDK from you. If I scan in the form as a PDF:
1). What do I use to create fillable form fields on the PDF? I'm guessing each form field will have a name or id associated with it correct?
2). What do I use to load this PDF and fill those fields?
Any help or steps to get me going in the right direction would be greatly appreciated. Thank you very much for your time.
Best Regards,
Nelson
Fill a PDF form via code?
Moderators: Daniel - PDF-XChange, PDF-XChange Support, Vasyl - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange
-
- Site Admin
- Posts: 19846
- Joined: Mon Jan 12, 2009 8:07 am
Re: Fill a PDF form via code?
Hello Nelson,
I am afraid that for now there is no way to generate Acro Forms with our SDKs for existing PDF files, but you can create new documents with such fields usin gour PDF Tools SDK and the PXCLIB40 LIB Functions:
https://www.pdf-xchange.com/product/pdf-tools-sdk
As for importing data if you already have the form - you could import data to it via .fdf files - in order to generate an .fdf file you will need to know all the field names , and also .fdf generation from separate database entries could be quite complicated, and I can not point you to documentation on the requirements for .fdf files containing form data and their structure.
But if those PDF files with forms would be opened in a window inside your application - and you want to integrate our VIewer AX in it - then it will be relatively easy for you to allow the users to fill in the forms, then save all the form data as .fdf and store the .fdf as a whole in the database - and then load the .fdf again in an empty form.
Ver3 of our Viewer (and the AX SDK) will have form creation capabilities, but until then your options are limited to the outlined above I am afraid.
Best,
Stefan
I am afraid that for now there is no way to generate Acro Forms with our SDKs for existing PDF files, but you can create new documents with such fields usin gour PDF Tools SDK and the PXCLIB40 LIB Functions:
https://www.pdf-xchange.com/product/pdf-tools-sdk
As for importing data if you already have the form - you could import data to it via .fdf files - in order to generate an .fdf file you will need to know all the field names , and also .fdf generation from separate database entries could be quite complicated, and I can not point you to documentation on the requirements for .fdf files containing form data and their structure.
But if those PDF files with forms would be opened in a window inside your application - and you want to integrate our VIewer AX in it - then it will be relatively easy for you to allow the users to fill in the forms, then save all the form data as .fdf and store the .fdf as a whole in the database - and then load the .fdf again in an empty form.
Ver3 of our Viewer (and the AX SDK) will have form creation capabilities, but until then your options are limited to the outlined above I am afraid.
Best,
Stefan
-
- User
- Posts: 33
- Joined: Tue Aug 24, 2010 3:44 am
Re: Fill a PDF form via code?
Hi Stefan, thank you for the prompt reply.
I'm not familiar with FDF files, but if my form data can be saved as an FDF, that's fine. I would store them in a folder along with the PDF (not actually in the database). I could then load the PDF and load the FDF (I'm guessing that overlays the data in the fields or something?).
Again, I don't want to "create" the form via code dynamically - but rather have the form with the fields already set (knowing the fieldnames) and I just want to populate the fields.
Sorry to re-hash the question, but is the response still "no" for this using your SDKs that I have?
Best Regards,
Nelson
I own the PDF Tools SDK and if I can add the fields to the existing PDF form I have scanned in, that would be great! I don't want to be adding fields on-the-fly. The fields will be fixed on the form wherever I create/place them. Can I add these types of fields using PDF-XChange Viewer Pro? I want to do this part visually on the screen (not via code). Just wondering how to get those fields on there or if I need a program like Adobe Acrobat Pro.you can create new documents with such fields usin gour PDF Tools SDK and the PXCLIB40 LIB Functions
Yes, the forms will be opened in my application window (via your PDF-XChange ActiveX Viewer) that I'm using in my code. I want to open the form and have the fields populated from a MySQL database, so at this point I would know the field names on the form and the values they need to be. I don't want the user typing into those fields, but rather fill them in automatically (at least for those that I have data for). Others can be filled in manually.But if those PDF files with forms would be opened in a window inside your application - and you want to integrate our VIewer AX in it - then it will be relatively easy for you to allow the users to fill in the forms, then save all the form data as .fdf and store the .fdf as a whole in the database - and then load the .fdf again in an empty form.
I'm not familiar with FDF files, but if my form data can be saved as an FDF, that's fine. I would store them in a folder along with the PDF (not actually in the database). I could then load the PDF and load the FDF (I'm guessing that overlays the data in the fields or something?).
Again, I don't want to "create" the form via code dynamically - but rather have the form with the fields already set (knowing the fieldnames) and I just want to populate the fields.
Sorry to re-hash the question, but is the response still "no" for this using your SDKs that I have?
Best Regards,
Nelson
-
- Site Admin
- Posts: 19846
- Joined: Mon Jan 12, 2009 8:07 am
Re: Fill a PDF form via code?
Hello nlopes,
Sorry - no way to add fields to an existing file, but you could e.g. grab the picture from the scanner, and with it and the functions in the PXCLIB40 LIB you could build up a new file - with the image as background and the fields in front.
And yes - once the form is filled - you can call the respective commands to save all form data as an .fdf file - and then store it along the original PDF.
Then on consecutive opens - you fill in the form with any default data from the database - and if there is an .fdf- load it after that - and it will overwrite any already filled in fields.
I hope this is a viable solution for you.
Best,
Stefan
Sorry - no way to add fields to an existing file, but you could e.g. grab the picture from the scanner, and with it and the functions in the PXCLIB40 LIB you could build up a new file - with the image as background and the fields in front.
Then you should be able to use JS in our Viewer AX - and populate the fields as needed.Yes, the forms will be opened in my application window (via your PDF-XChange ActiveX Viewer) that I'm using in my code. I want to open the form and have the fields populated from a MySQL database
And yes - once the form is filled - you can call the respective commands to save all form data as an .fdf file - and then store it along the original PDF.
Then on consecutive opens - you fill in the form with any default data from the database - and if there is an .fdf- load it after that - and it will overwrite any already filled in fields.
I hope this is a viable solution for you.
Best,
Stefan
-
- User
- Posts: 33
- Joined: Tue Aug 24, 2010 3:44 am
Re: Fill a PDF form via code?
Thanks again Stefan. Yes, this method should work for what I need. I'm just not familiar with using JS in the viewer. Any tips or suggestions on where to start learning that?
Also, I found a simple PDF editor that allows me to create the form fields (put text boxes, check boxes, etc..) onto the PDF visually which I can use for adding the AcroForm fields to the PDF. That makes it really easy to add and I don't have to create them through code (i.e. positioning them, etc...) using the PXCLIB40 LIB.
So, now I just need to learn how to use JS to populate the fields from my database.
Best Regards,
Nelson
P.S. I also found another library called QuickPDF that allows me to read/set the form fields via code very easily. It seems to be very well done and simple enough to use if I can't figure out JS (which I'd prefer since I already own it). I hope you will provide the ability to place AcroForm fields on a PDF and read/set their data in your upcoming release as you mentioned. Hope it's released soon!
Also, I found a simple PDF editor that allows me to create the form fields (put text boxes, check boxes, etc..) onto the PDF visually which I can use for adding the AcroForm fields to the PDF. That makes it really easy to add and I don't have to create them through code (i.e. positioning them, etc...) using the PXCLIB40 LIB.
So, now I just need to learn how to use JS to populate the fields from my database.
Best Regards,
Nelson
P.S. I also found another library called QuickPDF that allows me to read/set the form fields via code very easily. It seems to be very well done and simple enough to use if I can't figure out JS (which I'd prefer since I already own it). I hope you will provide the ability to place AcroForm fields on a PDF and read/set their data in your upcoming release as you mentioned. Hope it's released soon!
-
- Site Admin
- Posts: 19846
- Joined: Mon Jan 12, 2009 8:07 am
Re: Fill a PDF form via code?
Hello Nelson,
I'd recommend you to start with the samples in:
C:\Program Files\Tracker Software\PDF-XChange Viewer SDK\Examples\<<Your programing language>>\JavaScript
And also take a look at the
JavaScript for Acrobat API Reference.
Yes - we are working on these features, and as soon as we are ready - you can count on us to release the new SDKs.
Best,
Stefan
I'd recommend you to start with the samples in:
C:\Program Files\Tracker Software\PDF-XChange Viewer SDK\Examples\<<Your programing language>>\JavaScript
And also take a look at the
JavaScript for Acrobat API Reference.
Yes - we are working on these features, and as soon as we are ready - you can count on us to release the new SDKs.
Best,
Stefan
-
- User
- Posts: 30
- Joined: Tue Apr 17, 2012 8:55 pm
Re: Fill a PDF form via code?
// Javascript Example 1
// Set each field as the name of the field
i=0;
for (i = 0; i < this.numFields; i++)
{ this.getField(this.getNthFieldName(i)).value = this.getNthFieldName(i);}
// Javascript Example 2
// Set the Name of "Field_Name1" to "New Value"
this.getField(“Field_Name1”).value =”New Value” ;
'-- VB6 Example
'-- Use the RunJavaScript function of the ActiveX Control to set the text of a Merge Field using the JavaScript above
ls_input = 'for (i = 0; i < this.numFields; i++) { this.getField(this.getNthFieldName(i)).value = this.getNthFieldName(i);}'
pdfxchange_ctrl.RunJavaScript(ls_input, ls_output)
// Set each field as the name of the field
i=0;
for (i = 0; i < this.numFields; i++)
{ this.getField(this.getNthFieldName(i)).value = this.getNthFieldName(i);}
// Javascript Example 2
// Set the Name of "Field_Name1" to "New Value"
this.getField(“Field_Name1”).value =”New Value” ;
'-- VB6 Example
'-- Use the RunJavaScript function of the ActiveX Control to set the text of a Merge Field using the JavaScript above
ls_input = 'for (i = 0; i < this.numFields; i++) { this.getField(this.getNthFieldName(i)).value = this.getNthFieldName(i);}'
pdfxchange_ctrl.RunJavaScript(ls_input, ls_output)
-
- Site Admin
- Posts: 19846
- Joined: Mon Jan 12, 2009 8:07 am
Re: Fill a PDF form via code?
Thanks for the samples promisekey!
Hope they will be useful to Nelson and others as well!
Cheers,
Stefan
Hope they will be useful to Nelson and others as well!
Cheers,
Stefan