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
6 Answers
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.

- 461
- 3
- 3
-
1You can tell imageMagick to convert just the page you want with `[]`, something like `convert -geometry 1600x1600 -density 200x200 -quality 100 file.pdf[2] page_snapshot.jpg` – isalgueiro Jan 09 '15 at 13:17
-
For me it was sufficient to just say `convert -density 600 input.pdf output.jpg` – Joerg S Dec 16 '21 at 07:54
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.

- 4,078
- 1
- 25
- 20
Ghostscript from the command line (no ActiveX compenent available) gswin32c.exe .... parameters..... (see documentations, it's very easy)

- 2,284
- 20
- 24
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

- 2,316
- 9
- 48
- 65
-
Thanks Pieter, best answer so far! (er.. being the *only* answer so far :-)). I have Acrobat on my system, so I could test the code. Works fine. (Acrobat may not be on the target system, however). We'll see if someone comes up with a cheaper alternative. In the mean time, thanks again. HANWE – stevenvh Jun 05 '09 at 14:56
-
1Looks silly and wasting a lot of time to pass the image via the clipboard. Isn't there a way to copy it directly to the bitmap? – Joris Groosman Aug 08 '17 at 08:17
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

- 2,237
- 1
- 21
- 31
-
8 years on that QuickPDF library costs $1500, that's 6 times as much, and way too much, at least for me. (That's an inflation of 25% per year.) – Joris Groosman Aug 08 '17 at 08:21
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).

- 5,654
- 5
- 28
- 48