I have been using a modified version of the code on this website (Read And Write PDF Forms From Excel (VBA) ~ My Engineering World ) to copy text from an excel document to a PDF template and then save the result. Now I want to have the macro also add in an image to the image field in my template. I'm pretty new to VBA coding, so appologies if this is a dumb question.
Basically for my text I was just using "objAcroPDDoc.GetJSObject. GetField.[field name].Value" to highlight the relevant field in the PDF and paste in the value from my excel file. But I'm not sure how to modify it to have it add in an image from a specified file path instead.
Thanks in advance for any help!
And here's the reference page on the JSO
I have the same problem. Is there still (2 years later :)) no other way to import an image to a pdf image field instead of doing it via button icon?
I tried this solution already but it does not work for me.
This is a snippet of my code:
Set objAcroPDDoc = objAcroAVDoc.GetPDDoc Set objJSO = objAcroPDDoc.GetJSObject objJSO.getField("image").buttonImportIcon ("/C/test.pdf") // I also tried : objJSO.getField("image").buttonImportIcon ("/C/test.jpg")
Is there someone who can help me with my problem?
First, is the button field setup as "Icon Only"?
Then, are you getting any results at all? Are there any errors reported in the console window?
Oh yes.... The button field setup was not "Icon Only".
Now it works. Thank you so so much!!!
I have still an other question: I use this button to display an image. On this image I do some drawings. If I save this pdf the button is displayed over my drawings and I can't see them anymore. Is it possible to change the layer of the button? I couldn't find anything.
You mean you use the drawing tools in acrobat to add markup annotations, such as circles, rectangles and lines?
If so, then you have a problem. Form fields are always drawn last, so form fields will always draw on top of markup annotations. The only thing you could do is flatten the button into the PDF, Page content is always drawn first.
Ahhh.. yes. That's perfect. I have to flatten this pdf anyway before I send it to the customer. And in the flatten pdf I can see my drawings (yes, I mean markup annotations ;)).
Thank you very much for this hint.
Sorry, I have an other last question:
Is it possible to flatten just the button (in my vba script)? After I imported the Icon?
I mean something like that:
Yes, the "flattenPages" function includes a parameter for controlling how non-printing annotations are handled.
Here's the reference entry.
Set the drawing markups "print" property to false, then flatten with non-printing annots ignored, then reset print to true.
I am also using this workaround with the button image. And it worked well the last years... But now I got an file read error. I didn't change the code and also the images are the same. And also at the same location. I couldn't find anything on google. Maybe someoneelse has an idea?
Dim objAcroApp As Object, objAcroAVDoc As Object Dim objAcroPDDoc As Object, objJSO As Object Dim varKey As Variant Dim FDate As String Set objAcroApp = CreateObject("AcroExch.App") Set objAcroAVDoc = CreateObject("AcroExch.AVDoc") ' open file If objAcroAVDoc.Open(templateFile, "") = True Then Set objAcroPDDoc = objAcroAVDoc.GetPDDoc Set objJSO = objAcroPDDoc.GetJSObject ClearForm = objJSO.ResetForm() 'clear the form 'add image objJSO.getField("##Skizze##").buttonImportIcon ("/C/test.jpg") End If
Can you open the jpg file in Adobe Acrobat?
Thank you for your reply.
Yes, I can open the image in Adobe and I can also import this image as button icon.
But not in VBA anymore. 😕
Thank you for your reply and your good explanation. I will try to fix it in that way. 🙂