Solved

Insert graphic into pdf with vbscript

Posted on 2013-02-05
4
1,349 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Update 21-May-2015: I temporarily removed the source code and the code snippets to make major changes to the program. Regards, Joe A recent question here at Experts Exchange piqued my interest, so I decided to provide a thorough solution and publ…
In a previous article published here at Experts Exchange, Signature Image with Transparent Background (http://www.experts-exchange.com/Web_Development/Document_Imaging/A_12380-Signature-Image-with-Transparent-Background.html), I explained how to cre…
In this second video of the Xpdf series, we discuss and demonstrate the PDFimages utility, which, in a single command, is able to extract all the images from a PDF file and save each one in a separate image file (PBM, PPM, or JPG). Download and inst…
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…

863 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

24 Experts available now in Live!

Get 1:1 Help Now