I was wondering if there was an easy of generating thumbnails of PDF files in Delphi. Basically I want to render the first page of a PDF to a small bitmap (say 100x100 or similar).
I see two options 1 use a PDF component, 2 somehow tap into how explorer generates previews/thumbnails.
Delphi supports the display of Adobe PDF files from within an application. As long as you've got Adobe Reader installed, your PC will automatically have the relevant ActiveX control you'll need to create a component you can drop into a Delphi form. Start Delphi and select Component | Import ActiveX Control...
He is also proficient in XML, DHTML, and JavaScript. Delphi supports the display of Adobe PDF files from within an application. As long as you've got Adobe Reader installed, your PC will automatically have the relevant ActiveX control you'll need to create a component you can drop into a Delphi form.
Start Delphi and select Component | Import ActiveX Control... Look for the "Acrobat Control for ActiveX (Version x.x)" control and click Install. Select the Component palette location into which the selected library will appear. Click Install.
.thumb files are ordinary png files, just with a different file suffix. Knowing this one can display them in a TImage. First the .thumb extension needs to be registered as new file format. For this include PngImage in your uses and call this: Thanks for contributing an answer to Stack Overflow!
Using a library like QuickPDF or Gnostice is really the easiest option. I'm fairly sure that the PDF thumbnails in explorer are actually generated by whatever PDF software is installed such as Adobe. Unless you can guarantee that a proper PDF reader is installed on every workstation the idea of using thumbnails might not be valid.
Edit: Here's a complete application using QuickPDF to render the first page of a given PDF file into a BMP file. At 10 DPI my output BMP file is 85 pixels wide by 110 pixels high.
program PDFToBMP;
{$APPTYPE CONSOLE}
uses
SysUtils, QuickPDF;
var
Q : TQuickPDF;
begin
Q := TQuickPDF.Create;
try
Q.LoadFromFile(ParamStr(1), '');
Q.RenderPageToFile(10 {DPI}, 1 {PageNumber}, 0 {0=BMP}, ChangeFileExt(ParamStr(1),'.bmp'));
finally
Q.Free;
end;
end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With