PDF Instant Image

I want to take a snapshot from an arbitrary page (i.e. not necessarily the first one) in a PDF document. Any free tools for this? I am using Delphi.
TIA
Stephen

+4
source share
7 answers

Stephen

I had the same problem a couple of years ago, and the only reliable solution was to buy Acrobat Professional (7) and use it to extract the page, copy it to the clipboard and create a thumbnail. I would be very interested to know if there are available methods for extracting 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, Peter

0
source

You can do it 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, I converted the complaint about invalid PDF formatting caused by pdftk, but that didn't seem to affect the result.

+4
source

Here is a comparison of some Delphi-related PDF management tools: Top 9 PDF Tools Tools . So far, I have never used it myself, so I can not give recommendations.

There is also PDFlib Lite , which is open source.

PS: can you clarify whether you want a one-time (manual) solution or software? You mention Delphi in your question, but in your comment on Pieter van Wyk, you seem to be pleased with the solution for the guide. For manual, I suggest, like others, Ghostscript (engine) with Ghostview (UI) . Ghostscript has an API that Delphi can access , but it can be problematic (size, license, etc.) for deployment with a commercial program.

ยง You need to install Ghostscript first than Ghostview. Open the PDF file, menu File / Convert / as device select pdfwrite (or another image format that you need / prefer) / select your resolution (72 may be enough for the screen) / select your page number / OK / select the folder and file name / Save, and you're done.

+1
source

You might want to check out the QuickPDF Library . I used the library for about 5 years. It has a good support group that has stood before him through a long and painful abandonment of the original publisher and is now supported by one who has been an important name in the PDF world for many years, Carl De Abri. They have a downloadable reference guide for their product on the download page, and I think they have something like ClonePage or something like that. In any case, if you cannot find the answer in the manual, contact support and you will probably get a full explanation of how to accomplish what you are trying to do.

Unfortunately. I just noticed this "free" requirement. Their toolbox is fairly priced at $ 249, and if your project is what you sell, at least it will be free for your users, or at least not individually.

Jack

0
source

If you are not looking for a high-resolution snapshot, you can simply open the pdf file with the Acrobat ActiveX component in a special form (full-screen mode, without borders), go to the page, and then get a screenshot . You can immediately close this form so that it simply flares up and disappears.

ImageMagick can also be used on Windows, it has very simple commands that you could invoke (hidden using ShellExec), create a JPEG (or any other type of image).

0
source

Ghostscript from the command line (no ActiveX components available) gswin32c.exe .... options ..... (see the documentation, this is very easy)

0
source

I would like to use your code, but I do not know how you can help me?

I am under D6.

My project is compiling, but what should you put at the click of a button?

Best wishes,

JM (Belgium)

0
source

Source: https://habr.com/ru/post/1285797/


All Articles