Examples Delphi

Title: PDF Thumbnail
Question: A procedure to convert a PDF into bitmap
Answer:
Hello,
Add to the uses: ClipBrd and ComObj
procedure GetPDFThumb(const sFileName: WideString; nWidth, nHeight: Integer; var Bitmap: TBitmap);
var
PDRect,
PDDoc,
PDPage: Variant;
begin
if Bitmap = nil then
Exit;
PDDoc := CreateOleObject('AcroExch.PDDoc');
PDRect := CreateOleObject('AcroExch.Rect');
try
PDDoc.Open(sFileName);
PDPage := PDDoc.AcquirePage(0); //Get the first Page
PDRect.Top := 0;
PDRect.Left := 0;
PDRect.Right := PDPage.GetSize.x;
PDRect.Bottom := PDPage.GetSize.y;
Bitmap.Width := PDRect.Right;
Bitmap.Height := PDRect.Bottom;
//Move to the ClipBoard
PDPage.CopyToClipboard(PDRect, 0, 0, 100);
Bitmap.LoadFromClipboardFormat(cf_BitMap, ClipBoard.GetAsHandle(cf_Bitmap), 0);
//Resize
Bitmap.Canvas.StretchDraw(Rect(0, 0, nWidth, nHeight), Bitmap);
Bitmap.Width := nWidth;
Bitmap.Height := nHeight;
except end;
VarClear(PDRect);
VarClear(PDDoc);
end;
usage:
procedure TForm1.Button2Click(Sender: TObject);
var
Bitmap: TBitmap;
begin
Bitmap := TBitmap.Create;
GetPDFThumb('d:\pdf\pdf\pdf_teste.pdf', 100, 100, Bitmap);
Image1.Picture.Bitmap.Assign(Bitmap);
Bitmap.Free;
end;