Link to home
Start Free TrialLog in
Avatar of jjafferr
jjafferrFlag for Oman

asked on

convert pdf to jpg

Hi Guys,

I have the full Adobe Acrobat 7 professional installed, and I want through VB (I am using Access) to convert the pdf file to individual images.

And if possible, can I do it with another Free program.

Can some one help me with the code please,

thanks

jaffer
Avatar of jjafferr
jjafferr
Flag of Oman image

ASKER

After making Reference to Adobe acrobat 7.0 type Library,
I used this code:

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

Private Sub Command0_Click()
        gApp = CreateObject("AcroExch.App")
        gPDDoc = CreateObject("AcroExch.PDDoc")
        If gPDDoc.Open("C:\test.pdf") Then
            jso = gPDDoc.GetJSObject
            jso.SaveAs("c:\test.jpg", "com.adobe.acrobat.jpeg")   <==  Not accepted by Access
        End If
        gPDDoc.Close()       <==  Not accepted by Access
end sub

even after I remake these line, I get this message:
Object variable OR with block variable not set
and this line is high lighted:
gApp = CreateObject("AcroExch.App")
ASKER CERTIFIED SOLUTION
Avatar of Karl Heinz Kremer
Karl Heinz Kremer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Should have typed a bit faster :-)

Do you have more than one version of Acrobat installed on your system? Are you running 7.0.0 or 7.0.1?
Hi Karl,
Thanks for your help,

>When you say "individual images", do you mean individual files?
Yes

>Would it be sufficient to create files with the page number in the file name?
Yes

>You will not have any control over the resolution or the quality of the image, is this OK?
I don't mind not having control over the resolution as long as it is the same page size as the pdf is, but I do mind the quality, I want the quality to as the pdf file (more or less)

>I figure that you've never used the JSObject
You are right, I never looked under the hood of Acrobat, I always used the interface.

>Do you have more than one version of Acrobat installed on your system?
No

>Are you running 7.0.0 or 7.0.1?
at home, I am running 7.0.1, at work I am running 5 along with ghostscript.

>Please let me if you've managed to load the reference
Yes I did, thanks to your earlier comment showing me the path of the file.
Although in the reference, it says Acrobat when you first select the reference, but when you close it and come back again, it shows "Adobe Acrobat 7.0 Type Library"

But still the above code is not working.

This is what I want to do:
We recieve tenders to fill,
We have a program in Access that will fill the prices (manually)  and all the other terms,
I don't want the users to print an Access Report, then sit infront of the typewriter to fill the tender pages,
so after thinking for a solution for sometime, I came with this solution:
The user will scan the tender pages to pdf,
with the solution I am seeking now, I will extract the pdf file to images (doesn't matter which type as long as the quality is good and Access can read it),
I will import these images as individual Records, and will place each image as a background picture in the Form,
somehow with either a drag and drop or mouse click, the user will indentify the location of the the areas where Access should print that field,
Print the Form with the backgroud.

The main purpose is to cut the time and automate the process.

jaffer
Unfortunately, this does not work: The saveAs() method needs a privileged context to run, and it looks like VBA does not provide this. This dicussion thread offers a workaround: http://groups-beta.google.com/group/adobe.acrobat.sdk/browse_thread/thread/aff6ead347b682c/d5741ff466a994e3?q=acrobat+saveas+jsobject&rnum=4&hl=en#d5741ff466a994e3
But this again does not work in Acrobat 7 because menu events are no longer privileged. You need to create a privileged function when you setup the menu callback so that it runs with the correct permissions. Your VBA code would then execute this menu item. This does however require that your document gets actually displayed in Acrobat (which is not the case for a PDDoc, so you have to open an AVDoc instead).

Do you have access to the scanned PDF file? If so, you don't have to export it to JPG, just so that you can import them again into Access and use them as form backgrounds. You can use the scanned PDF, and as long as you know where to put the information, you can create a form field with the JSObject, and then just assign a value from your DB to this field. The crucial point is that you need to know where to put this form field. If it's not always the same place, and you expect the user to do some interactive work anyways, you can place the form field in a default location, and then have the user move the form field (already filled in around). Does this sound feasible?
it does, provided the whole process is automated (in terms of pulling the data from Access to the pdf Form),
but does that mean every user should have Adobe Acrobat 7 professional installed on his PC?

jaffer
Who's doing the merging of form with Access data? Is this one person who receives all the froms from the users, or is this done by every user?
I want everyuser to do it by himself.
Hey Karl,

I found a solution outside pdf:
instead of:
The user will scan the tender pages to pdf,

I will make them:
The user will scan the tender pages to TIFF,
then I will use my best graphics program "Irfanview" which is FREEWARE, through command line to extract these multipage Tiff to individual jpg, like this:
C:\Program Files\IrfanView>i_view32.exe i:\testing\spec03.tif /extract=(c:\temp,jpg)

and Viola, I have my individual images.

Thanks for you time and effort, I appreciate it.

jaffer
I will accept Ghostscript as an answer, as I am sure it can do it.

jaffer