How to add text to a pdf file using Access VBA??
Copy link to clipboard
Copied
I'm down on my hands and knees, begging. I have 300 files that I want to put a variable string at the top of the first page (centered, or at the right hand side). I am using Acrobat X and Microsoft Access 2010 and I do have the SDK and have spend over 10 hours so far searching it and the internet in general, for help and still am coming up empty handed.
I can do the looping and passing variables with my eyes closed, but I cannot get the syntax for the actual opening of the pdf and inserting the string.
I was trying to modify code I found yesterday that is supposed to add an annotation, but I don't want an annotation, I just want a string of text at the top of page 1. For now, all I want is to be successful at doing ONE file. Can someone please give me a concrete example of the code I need to use? Like I said, I'm in begging mode
Public Sub AddText()
Dim pdDoc As Acrobat.AcroPDDoc
Dim page As Acrobat.AcroPDPage
Dim annot As Acrobat.AcroPDAnnot
Dim jso As Object
Dim strPath As String
Dim intpoint(1) As Integer
Dim intpopupRect(3) As Integer
Dim props As Object
Set pdDoc = CreateObject("AcroExch.PDDoc")
pdDoc.Open ("c:\Test\Test.pdf")
Set page = pdDoc.AcquirePage(0)
'Set annot = page.AddAnnot(0)
intpoint(0) = 0
intpoint(1) = page.GetSize.y
intpopupRect(0) = 0
intpopupRect(1) = page.GetSize.y - 100
intpopupRect(2) = 200
intpopupRect(3) = page.GetSize.y
annot.SetColor (vbRed)
annot.SetContents "JCPC - 22 - 2011050000001"
pdDoc.Save 1, "c:\Test\Test.pdf"
pdDoc.Close
Set pdDoc = Nothing
MsgBox "Done"
End Sub
Copy link to clipboard
Copied
You should look at the JSObject and how to call JavaScript methods from VB(A). Then look at the addWatermark method.
Copy link to clipboard
Copied
I've looked at that stuff until I'm blue in the face, and still don't get it.
Copy link to clipboard
Copied
I have to say 10 hours is not enough to scratch he surface of the SDK.
We tend not to give examples - well I don't. Instead I help people understand the documents and write their own code.
So, what is it about the addWatermark method which is stopping you from getting further? How can we help with that.
Copy link to clipboard
Copied
I can't figure out how to call it.
Public Sub AddText()
Dim pdApp As Acrobat.AcroApp
Dim pdDoc As Acrobat.AcroPDDoc
Dim pdPage As Acrobat.AcroPDPage
Dim jso As Object
Dim doc As Variant
Set pdApp = CreateObject("AcroExch.App")
Set pdDoc = CreateObject("AcroExch.PDDoc")
pdDoc.Open ("c:\Test\Test.pdf")
page = pdDoc.AcquirePage(o)
Set jso = pdDoc.GetJSObject
*****************What do you do after you get the JSObject?
doc = jso.pdApp.activeDocs
pdDoc.Save 1, "c:\Test\Test.pdf"
pdDoc.Close
Set pdDoc = Nothing
MsgBox "Done"
End Sub
Copy link to clipboard
Copied
Jso.addWatermarkFromText( - parameters as defined in the JS docs - )
Copy link to clipboard
Copied
Just did that and I'm getting an error message, "Object variable or With block variable not set."
Public Sub AddText()
Dim pdApp As Acrobat.AcroApp
Dim pdDoc As Acrobat.AcroPDDoc
Dim pdPage As Acrobat.AcroPDPage
Dim jso As Object
Dim doc As Variant
Dim oColor As Object
Set pdApp = CreateObject("AcroExch.App")
Set pdDoc = CreateObject("AcroExch.PDDoc")
pdDoc.Open ("c:\Test\Test.pdf")
Set jso = pdDoc.GetJSObject
Call jso.addWatermarkFromText("WTF", 0, "Helvetica", 16, , 0, 0, True, True, True, 0, 0, 100, 100, False, 1, False, , , 1)
pdDoc.Save 1, "c:\Test\Test.pdf"
pdDoc.Close
Set pdDoc = Nothing
MsgBox "Done"
End Sub
Copy link to clipboard
Copied
You cannot skip arguments, you can either use the function with one
argument (just the required argument), or you have to provide all of them.
Also, it looks like you are trying to specify 20 parameters, even though
the function only takes 19. Try the following:
Call jso.addWaterMarkFromText("Test Text", jso.app.Constants.Align.Center,
jso.Font.Helv, 16, _
jso.Color.Black, 0, 0, True, True, True, _
jso.app.Constants.Align.Center, jso.app.Constants.Align.Center, _
100, 100, False, 1, False, 0, 1)
I just typed this in without running it through the compiler, so there may
be typos in the code, but you should get the idea of how the code is
supposed to look like.
Karl Heinz Kremer
PDF Acrobatics Without a Net
PDF Software Development, Training and More...
khk@khk.net
http://www.khkonsulting.com
On Fri, Jul 26, 2013 at 1:55 PM, I Love Mustangs
Copy link to clipboard
Copied
Karl,
Your previous posting is really helpful. Could you help me to explain the 19 parameters. I could not understand True and Flase parameters.
Regards,
Purna Pani
Copy link to clipboard
Copied
Which ones of the 19 parameters are not clear in the documentation?
Copy link to clipboard
Copied
Parameter 1: Text String
Parameter 2: Alignment of what?
Parameter 3: Font Type
Parameter 4: Font Size
Parameter 5: Font Colour
Parameter 6: Dimesion Assignement for What?
Parameter 7: Dimension Assignment for What?
Parameter 8: Boolean Parameter for What Purpose?
Parameter 9: Boolean Parameter for What Purpose?
Parameter 10: Boolean Parameter for What Purpose?
Parameter 11: Alignment of what?
Parameter 12: Alignment of what?
Parameter 13: Dimension Assignment for What?
Parameter 14: Dimension Assignment for What?
Parameter 15: Boolean Parameter for What Purpose?
Parameter 16: What is the purpose for assigning?
Parameter 17: Boolean Parameter for What Purpose?
Parameter 18: What is the purpose for assigning?
Parameter 19: What is the purpose for assigning?
I am not clear with 15 parameters out of 19 (put in question mark above). Please help me!!
Copy link to clipboard
Copied
This is all answered in the JavaScript API Reference. Are you having trouble understanding what is written in the documentation, or are you having trouble finding the documentation?
Copy link to clipboard
Copied
I am a new user to Adobe SDK programming using Excel VBA. Earlier I could not navigate JavaScript API reference. Now I am comfortable. Thanks
Copy link to clipboard
Copied
Based on your inquiry I have to assume that you are trying to do this without using the documentation. You cannot google your way around the Acrobat SDK! All this information is in the SDK documentation. Here is the link to the page that describes all parameters: Current page: http://livedocs.adobe.com/acrobat_sdk/10/Acrobat10_HTMLHelp/JS_API_AcroJS.88.437.html
Do yourself a favor and read not just this page, but everything Adobe has published about creating IAC applications and how to use the JavaScript object.
Karl Heinz Kremer
PDF Acrobatics Without a Net
PDF Software Development, Training and More...
http://www.khkonsulting.com
Copy link to clipboard
Copied
Hi Karl,
Thanks a lot for providing references. I am new user to community and failed to navigate and the refer parameters existed in the livedocs. As advised going forward I will try to get the information from API references.
Thanks a lot for your time and suggestions.
Regards,
Purna Pani
Copy link to clipboard
Copied
Purna, are you trying to do something using VBA or JavaScript? If VBA, send me a PM and I can help you get going.
Copy link to clipboard
Copied
Hello "I Love Mustange",
Now I got the references and able to work around with Excel VBA. Thanks a lot for your help.
Regards
Purna Pani
Copy link to clipboard
Copied
I know this is an old post, but I am trying to do the same thing. Can you provide me some sample code that got you going?
Copy link to clipboard
Copied
A while ago I wrote a blog post about how to use the JSObject from VBA:
http://khkonsulting.com/2009/03/acrobat-javascript-and-vb-walk-into-a-bar/
This will not address your exact problem, but you should find enough
information about how to get started.
Karl Heinz Kremer
PDF Acrobatics Without a Net
PDF Software Development, Training and More...
khk@khk.net
http://www.khkonsulting.com
On Fri, Jul 26, 2013 at 12:45 PM, I Love Mustangs

