Solved

Insert graphic into pdf with vbscript

Posted on 2013-02-05
4
1,307 Views
Last Modified: 2013-02-21
Hello,

I have a small diagram (jpg) that I need to insert into a pdf on a daily basis. I am sick of going through the menus so I would like to automate it. I 've seen some code to do something similar  on EE, but it was far too complicated. The requirement is that the jpg file goes at the back layer and is positioned at 7.5 inches from the top and 1,25 inches from the left.

Thanks,

Bruce
0
Comment
Question by:Diaphanosoma
  • 2
  • 2
4 Comments
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 500 total points
ID: 38864111
The only way you can do this is by adding a watermark. The VB interface does not have access to the "real" PDF objects, so you cannot insert an image directly. The following code shows how to use the JSO object to accomplish this from VB:

        Dim gApp As Acrobat.CAcroApp
        Dim gPDDoc As Acrobat.CAcroPDDoc
        Dim jso As Object

        Set gApp = CreateObject("AcroExch.App")
        Set gPDDoc = CreateObject("AcroExch.PDDoc")
        If gPDDoc.Open("c:\temp\test.pdf") Then
            Set jso = gPDDoc.GetJSObject

            i = jso.addWatermarkFromFile("c:\temp\watermark.jpg", 0, 0, 99999, False, True, True, 0, 3, 1.25 * 72, -7.5 * 72, False, 0.5, False, 0, 1#)
            If gPDDoc.Save(PDSaveFull, "C:\temp\watermark.pdf") = False Then
                MsgBox ("Cannot save the file!")
            End If

        End If

Open in new window


To get more information about the JSO object, take a look at this blog post: http://khkonsulting.com/2009/03/acrobat-javascript-and-vb-walk-into-a-bar/ It contains more links to relevant information

To understand the call to addWatermarkFromFile, take a look at it's documentation:
ttp://livedocs.adobe.com/acrobat_sdk/10/Acrobat10_HTMLHelp/JS_API_AcroJS.88.436.html
0
 
LVL 1

Author Comment

by:Diaphanosoma
ID: 38874348
I will try this out this week. Backed-up with other things...
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 38874404
No problem, let me know how it goes.
0
 
LVL 1

Author Closing Comment

by:Diaphanosoma
ID: 38914598
That's sweet.  Thanks,

Bruce.
Been on Vacation!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Power PDF (http://www.nuance.com/for-business/document-imaging-and-scanning/power-pdf-converter/index.htm) is the newest product from the Document Imaging division of Nuance Communications (http://www.nuance.com/). It is available in two editions — …
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
In this third video of the Xpdf series, we discuss and demonstrate the PDFtoText utility, which converts PDF files into plain text files. Download and install the software.: You may have already downloaded and installed the Xpdf tools while watching…
We often encounter PDF files that are pure images, that is, they do not have text characters, but instead contain only raster graphics. The most common causes of this are document scanning software and faxing software/services that create image-only…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now