Hi, long time lurker, first time poster.
I am writing a script that will do three things:
1. Pull variables out of an Excel spreadsheet (figured this out already)
2. Open an Adobe PDF that has been form prepped and now has several form fields and populate said form fields with previously captured variables.
3. Save PDF as something new
I am stuck on number 2. I have not had any luck evoking the form fields. So, I come to you fine gentlemen for advice, links to references, crude humor, and another other assistance you may want to offer.
Thank you.
Help with adobe PDF and AHK
-
- Posts: 2
- Joined: 22 Feb 2017, 19:04
Re: Help with adobe PDF and AHK
What application are you using to edit the PDF? How would you access the fields without AHK? Can you tab from field to field?
Edit: Have you read this?
https://autohotkey.com/boards/viewtopic.php?t=15193
Edit: Have you read this?
https://autohotkey.com/boards/viewtopic.php?t=15193
-
- Posts: 2
- Joined: 22 Feb 2017, 19:04
Re: Help with adobe PDF and AHK
1. I am using Adobe Acrobat DC.enter8 wrote:What application are you using to edit the PDF? How would you access the fields without AHK? Can you tab from field to field?
Edit: Have you read this?
https://autohotkey.com/boards/viewtopic.php?t=15193
2. I would access the fields through Adobe Acrobat.
3. I can tab from field to field in the PDF, yes.
I was hoping to directly call the fields sort of like GetField for a webform in some languages. Open to ideas though.
Thank you.
Re: Help with adobe PDF and AHK
The COM methods appear only to work with Adobe Acrobat Pro (possibly the same thing as Adobe Acrobat DC).
Is there another pdf reader than can do this with COM or some other method rather than pressing the tab button?
Thanks.
Is there another pdf reader than can do this with COM or some other method rather than pressing the tab button?
Thanks.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Help with adobe PDF and AHK
I have a poorly written program at work that I have to use. I use the TAB method. It sounds like your form doesn't change, so that may work for you.
I didn't like that I couldn't call each box by name, but after using the script with the TAB method hundreds of times now, I can say that I'm always getting the right information in the right place. So maybe you should just go that direction.....
I didn't like that I couldn't call each box by name, but after using the script with the TAB method hundreds of times now, I can say that I'm always getting the right information in the right place. So maybe you should just go that direction.....
- JoeWinograd
- Posts: 2202
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Help with adobe PDF and AHK
Here's how I've done this in AHK. The overall approach is to create an FDF from the PDF, then modify the FDF (in your case, with the variables pulled from the Excel spreadsheet), then create a new PDF from the modified FDF.
First thing to do is download PDFtk Server from here:
http://www.pdflabs.com/tools/pdftk-server/
Don't be misled by "Server" in the name. I don't know why they called it that, but it's just an executable (pdftk.exe, with a supporting DLL, libiconv2.dll) that runs on "standard" Windows — it does not have to run on a "server" Windows.
In your AHK code, create an FDF from your PDF using PDFtk's generate_fdf parameter. Here's an actual line of code from one of my AHK programs that does it (I'm sure the variable names make it clear what's happening):
RunWait,%PDFtkEXE% "%PDFform%" generate_fdf output "%FDFfile%",,Hide
Now modify the FDF data with the data extracted from the Excel spreadsheet. If you're not familiar with FDF format, a web search will get you everything you need. The quick summary is that it is a plain text file consisting of key-value pairs. It is easy to parse and modify, because each key is preceded by /T and each value by /V. For example, here are a few lines from an FDF file:
/T (FirstName)
/V (John)
/T (LastName)
/V (Smith)
/T (Phone)
/V (708-555-1212)
After modifying the values with the data from the Excel spreadsheet, create a new PDF using PDFtk's fill_form parameter. Again, here's an actual line of code from one of my AHK programs:
RunWait,%PDFtkEXE% "%PDFform%" fill_form "%FDFtemp%" output "%PDFtemp%",,Hide
This technique has worked perfectly here in many AHK scripts, but if you run into any problems, let me know and I'll try to help. Btw, the manual for it is here:
https://www.pdflabs.com/docs/pdftk-man-page/
And examples are here:
https://www.pdflabs.com/docs/pdftk-cli-examples/
You should also take a look at its licensing:
https://www.pdflabs.com/docs/pdftk-license/
As a disclaimer, I want to emphasize that I have no affiliation with this company and no financial interest in it whatsoever. I am simply a happy user/customer. Regards, Joe
First thing to do is download PDFtk Server from here:
http://www.pdflabs.com/tools/pdftk-server/
Don't be misled by "Server" in the name. I don't know why they called it that, but it's just an executable (pdftk.exe, with a supporting DLL, libiconv2.dll) that runs on "standard" Windows — it does not have to run on a "server" Windows.
In your AHK code, create an FDF from your PDF using PDFtk's generate_fdf parameter. Here's an actual line of code from one of my AHK programs that does it (I'm sure the variable names make it clear what's happening):
RunWait,%PDFtkEXE% "%PDFform%" generate_fdf output "%FDFfile%",,Hide
Now modify the FDF data with the data extracted from the Excel spreadsheet. If you're not familiar with FDF format, a web search will get you everything you need. The quick summary is that it is a plain text file consisting of key-value pairs. It is easy to parse and modify, because each key is preceded by /T and each value by /V. For example, here are a few lines from an FDF file:
/T (FirstName)
/V (John)
/T (LastName)
/V (Smith)
/T (Phone)
/V (708-555-1212)
After modifying the values with the data from the Excel spreadsheet, create a new PDF using PDFtk's fill_form parameter. Again, here's an actual line of code from one of my AHK programs:
RunWait,%PDFtkEXE% "%PDFform%" fill_form "%FDFtemp%" output "%PDFtemp%",,Hide
This technique has worked perfectly here in many AHK scripts, but if you run into any problems, let me know and I'll try to help. Btw, the manual for it is here:
https://www.pdflabs.com/docs/pdftk-man-page/
And examples are here:
https://www.pdflabs.com/docs/pdftk-cli-examples/
You should also take a look at its licensing:
https://www.pdflabs.com/docs/pdftk-license/
As a disclaimer, I want to emphasize that I have no affiliation with this company and no financial interest in it whatsoever. I am simply a happy user/customer. Regards, Joe