Populate pdf fields using vba

New Here ,
Jul 26, 2018

Copy link to clipboard

Copied

I'm trying to fill in an existing PDF file fields using access VBA by the code below. "User Name:" is one field on my pdf. I'm trying to enter a value to this field. When I run this with an appropriate file path it gives me an error saying: Run-time error '424': Object required.   The Adobe file version is Adobe Acrobat XI Pro.

Private Sub Adobefill_Click()

Dim FileNm, gApp, avDoc, pdDoc, jso

FileNm = "C:\projects\test\"

Set gApp = CreateObject("AcroExch.app")

Set avDoc = CreateObject("AcroExch.AVDoc")

If avDoc.Open(FileNm, "") Then

    Set pdDoc = avDoc.GetPDDoc()

    Set jso = pdDoc.GetJSObject

    jso.getfield("User Name:").Value = "[user name redacted by moderator by request]"      '<-------- I get an error here

    pdDoc.Save PDSaveIncremental, FileNm 'Save changes to the PDF document

    pdDoc.Close

End If

'Close the PDF; the True parameter prevents the Save As dialog from showing

  1. avDoc.Close (True)

'Some cleaning

Set gApp = Nothing

Set avDoc = Nothing

Set pdDoc = Nothing

Set jso = Nothing

End Sub

TOPICS
Acrobat SDK and JavaScript

Views

7.3K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Populate pdf fields using vba

New Here ,
Jul 26, 2018

Copy link to clipboard

Copied

I'm trying to fill in an existing PDF file fields using access VBA by the code below. "User Name:" is one field on my pdf. I'm trying to enter a value to this field. When I run this with an appropriate file path it gives me an error saying: Run-time error '424': Object required.   The Adobe file version is Adobe Acrobat XI Pro.

Private Sub Adobefill_Click()

Dim FileNm, gApp, avDoc, pdDoc, jso

FileNm = "C:\projects\test\"

Set gApp = CreateObject("AcroExch.app")

Set avDoc = CreateObject("AcroExch.AVDoc")

If avDoc.Open(FileNm, "") Then

    Set pdDoc = avDoc.GetPDDoc()

    Set jso = pdDoc.GetJSObject

    jso.getfield("User Name:").Value = "[user name redacted by moderator by request]"      '<-------- I get an error here

    pdDoc.Save PDSaveIncremental, FileNm 'Save changes to the PDF document

    pdDoc.Close

End If

'Close the PDF; the True parameter prevents the Save As dialog from showing

  1. avDoc.Close (True)

'Some cleaning

Set gApp = Nothing

Set avDoc = Nothing

Set pdDoc = Nothing

Set jso = Nothing

End Sub

TOPICS
Acrobat SDK and JavaScript

Views

7.3K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 26, 2018 0
Adobe Community Professional ,
Jul 26, 2018

Copy link to clipboard

Copied

Step through your code and make sure that you have a iso object. If that's the case, then the reason for the error is very likely that your document does not have a field named "User Name:" - make sure that you spell the field name exactly the same way as it is spelled in the PDF form.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 26, 2018 1
New Here ,
Jul 26, 2018

Copy link to clipboard

Copied

Thank you for responding. I stepped through the code and that's how i got to know where the error is occuring. So if you don't mind how and where do i add the iso object?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 26, 2018 0
Adobe Community Professional ,
Jul 26, 2018

Copy link to clipboard

Copied

The way you are doing it should work: You first get the AV doc, from that you get the PD doc, and from that you get the JSO. If the file is not being opened correctly, then you won't have an AVDoc, which means that the call to getPDDoc will also not return anything. You need to figure out where you are not getting the correct information. You know that at the point you want to use the JSO, it's not valid, but you need to work backwards to find out where things start to go wrong.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 26, 2018 1
Most Valuable Participant ,
Jul 26, 2018

Copy link to clipboard

Copied

Does your field name actually include the colon “:”? That’s pretty unusual.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 26, 2018 1
Adobe Employee ,
Jul 26, 2018

Copy link to clipboard

Copied

A field name CANNOT contain a ‘:’ – it’s forbidden by the PDF spec.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 26, 2018 1
New Here ,
Jul 26, 2018

Copy link to clipboard

Copied

Yes. It is ordered in this manner. The username is read only I cannot edit that.

User Name:            (blank field to enter data)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 26, 2018 0
Most Valuable Participant ,
Jul 26, 2018

Copy link to clipboard

Copied

The name of a field, and the label next to it, are not connected. Check the field name again. If you have managed to enter it with a colon, fix that.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 26, 2018 0
New Here ,
Jul 26, 2018

Copy link to clipboard

Copied

Hi all,

It worked! I put it the exact field name and it worked. Thanks for all the help.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 26, 2018 0
Adobe Community Professional ,
Jul 26, 2018

Copy link to clipboard

Copied

Look for the name of the blank field.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 26, 2018 0
Adobe Community Professional ,
Jul 26, 2018

Copy link to clipboard

Copied

Leonard, you may want to tell that to the Acrobat team

The only time I usually see colons in a form field names is with forms that were created by Acrobat when it tried to identify form fields automatically, and then used whatever was in front of the assumed field as it's name (e.g. "User Name:"), including any colons.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 26, 2018 0
New Here ,
Jul 26, 2018

Copy link to clipboard

Copied

Can you also help me with the code on how to select a value in a drop down menu or (Comobox) in the pdf? 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 26, 2018 0
Adobe Community Professional ,
Jul 26, 2018

Copy link to clipboard

Copied

You do that the same way as with a text field. Just make sure that the value you pass in is actually an available option in your drop down control.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 26, 2018 0
New Here ,
Jul 26, 2018

Copy link to clipboard

Copied

Yup got it. Thanks!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 26, 2018 0
New Here ,
Oct 03, 2018

Copy link to clipboard

Copied

I need to populate pdf fields using vba code and the code works perfectly for me in my home computer where I have installed Acrobat Pro version. But when I run the application to my workplace it doesn't work because I have adobe reader  installed there and I have no access to install anything there as a client machine. They have Office 365 installed and therefore I can run VBA but it doesn't work because Acrobat Pro is not available there. Is there any way to do the same task for Adobe reader or any possible solution to run the some application written at my home there?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 03, 2018 0
Adobe Community Professional ,
Oct 03, 2018

Copy link to clipboard

Copied

You need Adobe Acrobat Standard or Pro.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 03, 2018 0
New Here ,
Oct 04, 2018

Copy link to clipboard

Copied

I found there only AcroPDF.dll. Nothing else. So there is literally no way to access pdf fields without installing Standard or Pro version?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 04, 2018 0
Most Valuable Participant ,
Oct 04, 2018

Copy link to clipboard

Copied

Adobe put there developer tools into the paid for software, and leave them out of the free software - because they are a marketing tool.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 04, 2018 1