I want to make a snapshot image from an arbitrary page (i.e. not necessarily the first) in a PDF document. Any free tools for this? I'm using Delphi.
TIA
Steven
Steven
I had the same problem a couple years ago and the only reliable solution was to buy Acrobat Professional (7) and use that to extract the page, copy it to the clipboard and then create a thumbnail from that. I'd be very interested to see if there are free methods available to extract pages from a pdf document.
procedure TFormMain.LoadPDFDoc(Filename: TFilename; var Bitmap: TBitmap);
var
PDPage : variant;
PdApp, PdDoc, PdRect: variant;
begin
try
PdApp := CreateOleObject('AcroExch.App');
PdDoc := CreateOleObject('AcroExch.PDDoc');
PdRect := CreateOleObject('AcroExch.Rect');
//Open the pdf document
PDDoc.Open(FileName);
PDPage := PDDoc.AcquirePage(0);
//Define the rectangle to fit the page
PDRect.Top := 0;
PDRect.Left := 0;
PDRect.Right := PDPage.GetSize.x;
PDRect.Bottom := PDPage.GetSize.y;
//Set the bitmap proportions
with Bitmap do
begin
Width := PDRect.Right;
Height := PDRect.Bottom;
end;
//Copy the rectangle to the ClipBoard
PDPage.CopyToClipboard(PDRect, 0, 0, 100);
if not VarIsEmpty(PDPage) then
PDPage := UnAssigned;
//Close the pdf document
PDDoc.Close;
//Paste the image from the clipboard
with Bitmap do
begin
LoadFromClipboardFormat(CF_BITMAP, ClipBoard.GetAsHandle(CF_BITMAP), 0);
PixelFormat := pf24Bit;
HandleType := bmDIB;
end;
Except on E: Exception do
ShowMessage(E.Message);
end;
end;
Regards, Pieter
You can do this in 2 steps using pdftk and ImageMagick/Ghostscript
Step 1: Create a new pdf file with the page you are interested in:
pdftk.exe file.pdf cat 2 output page2_only.pdf
Step 2: Convert the new pdf to jpg:
convert -geometry 1600x1600 -density 200x200 -quality 100 page2_only.pdf page_snapshot.jpg
convert is an ImageMagick command.
ImageMagick requires Ghostscript to be installed in order for this to work. When I tested this, convert complained about invalid formatting of the PDF, caused by pdftk, but this did not seem to affect the output.
Here a comparison of some Delphi-related tools to manage PDF: Top 9 PDF Managing Tools. Until now, I never used one myself, so I cannot give a recommendation.
There is also PDFlib Lite which is open source.
P.S.: can you clarify if you want a "one-shot" (manual) solution or a programmatic one? You mention Delphi in your question, but in your comment to Pieter van Wyk you seem happy with a manual solution. For a manual one I suggest, as others, Ghostscript (engine) with Ghostview (UI)§. Ghostscript has an API that can be accessed by Delphi, but it can potentially be problematic (size, license and so on) to deploy with a commercial program.
§ You need to install Ghostscript first than Ghostview. Open your PDF, menu File / Convert / as device select pdfwrite (or another image format that you need/prefer) / choose your resolution (72 can be enough for screen) / choose your page number / OK / select folder and file name / Save and you are done.
It might be worth your time to check out The QuickPDF Library. I have used the library for about 5 years. It has a good support group that has stood by it through a long and painful abandonment by the original publisher and is now supported by someone who has been an important name in the PDF World for many years, Karl De Abrew. They have a downloadable reference manual to their product on their download page and I think they have something like ClonePage or something. Anyway, if you can't find the answer in the manual, contact their support and you will probably get a complete explanation of how to accomplish what you are trying to do.
Oops. I just noticed that "free" requirement. Their toolbox is fairly priced at $249 and if your project is something you would sell, at least it would be free to your users or at least not separately priced.
Jack
If you're not looking for a high-res snapshot, you could just open the pdf file with Acrobat's ActiveX component, in a special form (Fullscreen, No borders), Navigate to the page, then get a screenshot of the screen. You could immediately close that form, so it would just flash, and disappear.
ImageMagick could also be used on Windows, it has very simple commands that you could invoke in (hidden, using ShellExec), create a JPEG (or any other image type).
Ghostscript from the command line (no ActiveX compenent available) gswin32c.exe .... parameters..... (see documentations, it's very easy)
来源:https://stackoverflow.com/questions/955238/snapshot-image-from-pdf-document