Solved

Insert graphic into pdf with vbscript

Posted on 2013-02-05
4
1,573 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The Adobe PDF proprietary file format is recognized as secure and formulated. But these PDF files are also prone to corruption and any external threat like virus attacks, improper storage can hit PDF file integrity.This type of damages can make cruc…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

632 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