Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

translate a PDF file to JPG format HELP!

320 views
Skip to first unread message

zhan...@adobeforums.com

unread,
Mar 2, 2004, 5:30:15 AM3/2/04
to
I am trying to programmatically translate a PDF file to JPG format using VB6 and the Adobe 5.0 Type Library. Opening a PDF file and saving as JPG manually works just fine, so it stands to reason that the same can be done through VB6.

THANKS!

Aandi_...@adobeforums.com

unread,
Mar 2, 2004, 6:05:07 AM3/2/04
to
Many things that "stand to reason" don't hold up to the cold light of
day. Consider, just to start with - the Core API, for plug-ins, is
around 3000 pages, while the IAC Reference, for VB use, is less than a
tenth of that.

There is no supported interface to doing this.

There are many things in Acrobat that have no automation interface.

Aandi Inston

Reinhar...@adobeforums.com

unread,
Mar 2, 2004, 8:24:31 AM3/2/04
to
You may tray OLE MenuItemExecute("SaveAs") or JS saveAs, but I didn't use it up to now.

HTH, Reinhard

Tem...@adobeforums.com

unread,
Mar 2, 2004, 4:21:16 PM3/2/04
to
You will need to use a menu item if you use the JS 'saveAs' and then you can use the VB JSObject to execute it.

~T

HIM...@adobeforums.com

unread,
Mar 4, 2004, 6:51:26 AM3/4/04
to
hi

Using OLE Method 'SaveAs' ,It is converting to jpg.
But I Think Internal Jpeg format is not valid..
Because when i loading that file from Tpicture Component
in Delphi Its not Opening.

So we have to find another way

Himaja,INDIA

Aandi_...@adobeforums.com

unread,
Mar 4, 2004, 7:17:37 AM3/4/04
to
>Using OLE Method 'SaveAs' ,It is converting to jpg.

I do not see a method SaveAs in the IAC Reference. Please post more
details.

Aandi Inston

Jeroen...@adobeforums.com

unread,
Mar 4, 2004, 7:16:30 AM3/4/04
to
My company has a commercial component that can be called from the command line or via VB/C++ API to programmatically convert PDF to JPEG at any resolution you specify. It's standalone and self-contained software. Other output formats include TIFF, GIF and a host of vector graphics formats.

More info available at the URL below. You're welcome to contact me directly if interested.

Jeroen Dekker
--
Square One - The Graphics Connection
Visit <http://www.square1.nl/index.htm>
jer...@square1.nl

Aandi_...@adobeforums.com

unread,
Mar 4, 2004, 7:19:27 AM3/4/04
to
Ok, I assume you are using JavaScript... what cConvId are you using?

Aandi Inston

HIM...@adobeforums.com

unread,
Mar 4, 2004, 10:48:58 PM3/4/04
to
Hi

Sorry I Type 'saveas' instead 'Save'

In Acrobat.Lib there is
save method in interface of CAcroPDDoc

Iam using Delphi

HIM...@adobeforums.com

unread,
Mar 8, 2004, 7:06:55 AM3/8/04
to
hi

we can convert pdf to jpeg using
method menuitemexecute('extractimages:jpeg') which is in AcroExch.App object.
then a savedialogbox will be opened.
by mentioning the name the images in pdf will be saved to jpeg.
but now my problem is how to give filename with out invoking of save dialogbox

Thanks in advance,
Himaja,INDIA

Aandi_...@adobeforums.com

unread,
Mar 8, 2004, 8:05:51 AM3/8/04
to
When you execute a menu item, it always does exactly that, and no
more. It is as if you execute the menu item, so if the menu item would
prompt, you will get a prompt.

I do not understand how you could specify JPEG format for
PDDoc.SaveAs. What does your SaveAs call look like?

Aandi Inston

HIM...@adobeforums.com

unread,
Mar 8, 2004, 9:19:09 AM3/8/04
to
Hi

i given
PDDoc.save(PDSaveFull,'c:\Temp.jpg');
then it is saved.
but jpeg format is not valid in this case.
thats the problem.
so i try using menuitemexecute. its ok.
but my problem is savedialogbox is invoking.
pls tell me
if u know
how to use api files in other programming languages.

Aandi_...@adobeforums.com

unread,
Mar 8, 2004, 10:31:06 AM3/8/04
to
>Hi
>
>i given
> PDDoc.save(PDSaveFull,'c:\Temp.jpg');

So, you are saving a PDF file.
You choose to call it temp.jpg, but it is still a PDF file.

Just as, if you put a label on a banana saying "orange", it is still a
banana.

This method is for saving PDF files. It does not give access to the
"save as format" options of Acrobat.

> how to use api files in other programming languages.

You mean plug-ins? These must be written in Visual C++.


Aandi Inston

HIM...@adobeforums.com

unread,
Mar 9, 2004, 4:52:46 AM3/9/04
to
hi
yes i want tp use plug-ins
in my application(delphi).
but i dont how to interact with api files.
so plz help me in that
Himaja

Aandi_...@adobeforums.com

unread,
Mar 9, 2004, 6:05:31 AM3/9/04
to
The plug-in must run as part of Acrobat. You would need to find a way
to send messages between applications. Simplest: the application
writes a file, and executes a menu item with OLE. This menu item tells
the plug-in to read the file and process the request there.

Aandi Inston

Aandi_...@adobeforums.com

unread,
Mar 9, 2004, 8:46:38 AM3/9/04
to
But you do understand now?

Aandi Inston

HIM...@adobeforums.com

unread,
Mar 9, 2004, 8:44:03 AM3/9/04
to
sorry, i dint understant how todo

Himaja

Tem...@adobeforums.com

unread,
Mar 9, 2004, 12:15:41 PM3/9/04
to
You need to create a menu item as follows and place it in the JavaScripts folder:

//Saves file as a jpg
app.addMenuItem({ cName: "Save As>JPEG", cParent: "File",
cExec: "this.saveAs('/c/JPGFolder/NewJPEG.jpg', 'com.adobe.acrobat.jpeg');",
cEnable: "event.rc = (event.target != null);",
nPos: 0
});

Then you need to execute it from VB or as the examples below shows VBScript:

'create the script object
Set WshShell = WScript.CreateObject("WScript.Shell")
'use the wshell to launch Acrobat
WshShell.Run ("Acrobat.exe")
WScript.Sleep 7000

'Open a file
' This is a necessary evil... due to the then next item in the script.
WshShell.run "Acrobat.exe C:\Program Files\Adobe\Acrobat 6.0\Help\ENU\ACROHELP.PDF"
WScript.Sleep 1000

'If Acrobat or no document is open you get an error message about file not found... doh!
set WshShell = CreateObject ("Wscript.Shell")
WshShell.AppActivate("Adobe Acrobat")
WScript.Sleep 500

'open a file
'Get the active Document for use with JSObject
Set AcroApp = CreateObject("AcroExch.App")
Set AVDoc = AcroApp.GetActiveDoc
Set PDDoc = AVDoc.GetPDDoc
set jso = PDDOC.GetJSObject

'Do something with jso
jso.app.execMenuItem("Save As>JPEG")

However the issue is with 'control'. There is no controlling resolution or compression using this process.

~T

Reinhar...@adobeforums.com

unread,
Mar 10, 2004, 3:22:40 AM3/10/04
to

"this.saveAs('/c/JPGFolder/NewJPEG.jpg', 'com.adobe.acrobat.jpeg');"


This works not in versions before v6x. In v5x you may consider to use simple "SendKeys", perhaps with special window control/check (WinAPI, AutoitX.dll).

Best regards, Reinhard Franke

HIM...@adobeforums.com

unread,
Mar 10, 2004, 5:51:40 AM3/10/04
to
Hi

"this.saveAs ('/c/JPGFolder/NewJPEG.jpg', 'com.adobe.acrobat.jpeg');"
is not working in Acrobat5.

please explain in detail how to use "sendkeys"
as iam new to acrobat sdk programming

Thank U
Himaja

Aandi_...@adobeforums.com

unread,
Mar 10, 2004, 6:28:51 AM3/10/04
to
You cannot do this with the Acrobat SDK in Acrobat 5.

SendKeys is a method with VB of sending key presses to dialogs.
Suppose you do something and expect a dialog to appear. You might wait
a few seconds then send a ENTER, which is the same as clicking OK. It
is a very messy and unreliable way to program, and I couldn't
recommend it. If you want to know more about it, I suggest VB forums,
as it has no Acrobat connection.

Aandi Inston

Reinhar...@adobeforums.com

unread,
Mar 10, 2004, 7:50:54 AM3/10/04
to
Yea, Aandis comment is fully right.

Anyway, attached a simple working sample in VBS. Copy it via clipboard to an editor. Save it as AcSvAsJPG.vbs to your Desktop or Sendto directory and start with any PDF via Drag&Drop or right mouse click.

Be aware that this is a quick example, where I considered that you may not have an english version, which I also don't have (regional version independent :-)).

HTH, Reinhard

AcSvAsJPG.vbs :
----------------

REM: Save a Pdf as JPEG.
REM:Also Multipage PDF will can be changed. Then every page will be saved as single JPEG
REM: The Filename you can change to your needs.
REM: If you use Drag&drop or Filename as command
REM: line argument the script will work with this file.

'*********Settings in File**************************
FileNM = "C:\x.pdf" '//Filename for File to transfer if NO argument is given
'****************************************************

set WshShell = CreateObject ("Wscript.Shell")

set fs = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
if objArgs.Count = 1 then FileNM = ObjArgs(0)

Info = "Save as JPEG"&VbCr&_
"File Name: "&FileNM &vbCr&" Delete existing JPEG FILES with the same Name before!"&vbcr&" Start now?"
OK = MsgBox(Info, vbQuestion+vbYesNo,"Insert Files") : if OK = vbNo then WScript.quit

'//Start or switch to Acrobat
WshShell.run "Acrobat.exe"
While not WshShell.AppActivate("Adobe Acrobat") : Wscript.Sleep 1000 : Wend
Set gApp = CreateObject("AcroExch.App")

if not fs.FileExists(FILENM) then
MsgBox "Ups! " & FileNM & " doesn't exist? " & "Try new!", vbExclamation
WScript.quit
end if

Set BASFL = CreateObject("AcroExch.pdDoc")
OK = BASFL.Open(FileNM) '//Open the PDF-File
if not OK Then if MsgBox("Error open Basic File") then Wscript.quit
BASFL.OpenAVDoc(mid(FileNM,InstrRev(FileNM,"\")+1)) '// get the PDF-File into view
WScript.Sleep 1000

'// to get this part working reliable(!) use WinAPI, WMI, or AutoITX.dll to check the forground window

WshShell.SendKeys "^+s" '// send keys for SaveAs
WScript.Sleep 1000
WshShell.SendKeys "{tab}" '// goto Filetype
WScript.Sleep 500
WshShell.SendKeys "J" '// switch filetype zu JPEG
WScript.Sleep 500
WshShell.SendKeys "{tab}{Enter}" '// switsch to "Save" and save
WScript.Sleep 1000

Set BASFL = nothing : set gApp = nothing

HIM...@adobeforums.com

unread,
Mar 11, 2004, 2:28:57 AM3/11/04
to
Hi,
Thanks alot.
I implemented the sendkeys in delphi application.
its working.
but i think its not the permanent solution for converting pdf to jpeg,because if user clicks any other application then sendkeys action will be executed for that application.

i think , writing plugin is permanent solution for that.
i read the example in (acrobat sdk ->invoke command ).
But i dint understand how to add that plugin to acrobat.

Please Help me in that.

Thank U.
Himaja,INDIA.

Aandi_...@adobeforums.com

unread,
Mar 11, 2004, 3:17:04 AM3/11/04
to
> i read the example in (acrobat sdk ->invoke command ).
> But i dint understand how to add that plugin to acrobat.

A plug-in is compiled with Visual C++. Use the original project files.

The result is a *.API file, that you put in the Acrobat PLUG_INS
folder.

You should investigate the "FromPDF" methods.

Aandi Inston

HIM...@adobeforums.com

unread,
Mar 26, 2004, 5:14:43 AM3/26/04
to
Hi

Thank u very much Andi Inston

Iam able to add plug in acrobat.

i used the following command for conversion of pdf to jpeg
ASAtomFromString (kAVCommandExtractAsJpeg).

Here the problem is , it is
converting each image of that page to jpeg.

what command i have to use to convert pdf
to jpeg by page by page

Thanks in Advance
HimajaG

Aandi_...@adobeforums.com

unread,
Mar 26, 2004, 5:50:56 AM3/26/04
to
I don't know what you are doing with that code, but Extract As JPEG is
supposed to do that. What you need to do is the equivalent to save as
JPEG, which is (confusingly) not related to the normal Save methods.
Instead, this calls on the "FromPDF" converters, and that is the area
you need to investigate.

The parameters and keys to the FromPDF converters are not documented,
and may change between Acrobat releases. But at least it can be done.

Aandi Inston

HIM...@adobeforums.com

unread,
Mar 26, 2004, 11:12:03 PM3/26/04
to
Hi
Actually what i did is..

In example
\Acrobat 5.0SDK\PluginSupport\Samples\AVCommands\InvokeCommand\sources
they given how to convert pdf to tiff.

but in that also , each object in that page is converting to tiff
They passed the command kAVCommandExtractAsTIFF
For JPEG i passed the command kAVCommandExtractAsJpeg.
so here also , each object in that page is converting to JPEG.
Thats it.

do u mean FROMPDF convertors ,
[AVConversion methods - AVConversionConvertFromPDFWithHandler]

Thank u
HimajaG

Aandi_...@adobeforums.com

unread,
Mar 27, 2004, 3:12:28 AM3/27/04
to
Ok, AVCommands are roughly equivalent to the components of batch
sequences. Set up a batch sequence and look at the available
commands: you will see extract images as {jpeg,png,tiff}. This is
working as designed, but is not what you want.

Yes, the AVConversion methods are what you want.

Aandi Inston

HIM...@adobeforums.com

unread,
Mar 31, 2004, 3:30:51 AM3/31/04
to
Hi,

I dint understand how can i convert pdf to jpeg using
avconversion methods.
In example they given to convert from pdf to
uncompress pdf file.
but iam not getting any idea fro the conversion of pdf to jpeg

plz help me in that

thank u
Himaja

Aandi_...@adobeforums.com

unread,
Mar 31, 2004, 3:45:01 AM3/31/04
to
It is not straightforward. The basic method is

Enumerate the FromPDF handler to find the correct name of the PDF to
JPEG converter.

Set up this converter and get the default parameters.

Examine these parameters using guesswork to decide what parameters are
needed for your task. This is release dependent! Especially, options
like resolution exist in 5.0 but not 6.0.

You now have enough information to create and run a conversion.

Aandi Inston

Dick_V...@adobeforums.com

unread,
Apr 15, 2004, 3:09:31 PM4/15/04
to
Here's some of the code I use to save each page as a JPEG. NOTE WELL: As Aandi mentioned, the Resolution setting is irrelevant to 6.0. The images alway save at the resolution they were scanned as (for bitmap-based pages). (That's a very bad change, if I may editorialize.)

/* fromPDFEnumProc
* * ----------------------------------------------------------------------
* *
* * Called by Acrobat as it cycles through each FromPDF handler.
* *
* / static ACCB1 ASBool ACCB2 fromPDFEnumProc(AVConversionFromPDFHandler handler,
AVConversionEnumProcData data)
{
DURING
//Get the name of this filter
ASInt32 len = 255;
AVFileFilterRec filterRec = handler->convFilter;
char * filterName = ASTextGetPDTextCopy(filterRec.filterDescription, &len);

//If it's the JPEG handler, then set our global handler to it.
//Name changed to just "JPEG" in 6.0
if (!strcmp(filterName, "JPEG Files"))
{
gConversionHandler = handler;
}

HANDLER
return false;
END_HANDLER
return true;
}

/* GetJPEGHandler
* * ----------------------------------------------------------------------
* *
* * Enumerate all conversion handlers so we can find the JPEG one.
* *
* /

void GetJPEGHandler()
{
AVConversionFromPDFEnumProc fromPDFEnumProcCB =
ASCallbackCreateProto(AVConversionFromPDFEnumProc, &fromPDFEnumProc);
AVConversionEnumFromPDFConverters (fromPDFEnumProcCB, NULL);
ASCallbackDestroy(fromPDFEnumProcCB);

}

/* INSERT THE REST OF THIS IN THE APPROPRIATE PLACE IN YOUR PLUG-IN */

GetJPEGHandler();

// Create the setting cabinet and provide the settings.
volatile ASCab settings = NULL;
settings = ASCabNew();
ASCabPutInt (settings, kExtractImgCmdKeyConvFormat, kImgConversionFormatJpeg);
ASCabPutInt (settings, kExtractJpegCmdKeyCompression, kJpegCompressionLow);
ASCabPutInt (settings, kExtractJpegCmdKeyFormat, kJpegFormatOptimized);
ASCabPutInt (settings, kExtractImgCmdKeyColorSpace, kColorSpaceGrayscale);
ASCabPutInt (settings, kExtractImgCmdKeyResolution, kImgResolution96);

// Call the converter.
AVConversionStatus thisStatus = AVConversionConvertFromPDFWithHandler (gConversionHandler,
settings, flags, thisPDDoc, thisASPathName, thisASFileSys, NULL);

// Clean up.
ASCabDestroy(settings);

walid...@adobeforums.com

unread,
May 29, 2004, 4:43:02 PM5/29/04
to
Dear HIMAJAG.
Any success in this project "translate a PDF file to JPG format" using Delphi language?
0 new messages