Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to add text to a pdf file using Access VBA??

New Here ,
Jul 26, 2013 Jul 26, 2013

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

TOPICS
Acrobat SDK and JavaScript
25.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Jul 26, 2013 Jul 26, 2013

You should look at the JSObject and how to call JavaScript methods from VB(A). Then look at the addWatermark method.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 26, 2013 Jul 26, 2013

I've looked at that stuff until I'm blue in the face, and still don't get it. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 26, 2013 Jul 26, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 26, 2013 Jul 26, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Jul 26, 2013 Jul 26, 2013

Jso.addWatermarkFromText( - parameters as defined in the JS docs - )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 26, 2013 Jul 26, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 27, 2013 Jul 27, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 22, 2013 Nov 22, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 22, 2013 Nov 22, 2013

Which ones of the 19 parameters are not clear in the documentation?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 25, 2013 Nov 25, 2013

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!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 25, 2013 Nov 25, 2013

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 26, 2013 Nov 26, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 25, 2013 Nov 25, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 26, 2013 Nov 26, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 25, 2013 Nov 25, 2013

Purna, are you trying to do something using VBA or JavaScript?  If VBA, send me a PM and I can help you get going.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 26, 2013 Nov 26, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 17, 2023 Aug 17, 2023
LATEST

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 26, 2013 Jul 26, 2013

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

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