Hi,
I'm new to wPDF.
Is it possible to convert a PDF to GIF,BMP or JPG? with wPDF-products?
Hi,
I'm new to wPDF.
Is it possible to convert a PDF to GIF,BMP or JPG? with wPDF-products?
With the licensed version of WPViewPDF do this:
var pdf : TWPViewPDF;
meta : TMetafile;
page : Integer;
bit : TBitmap;
jpeg: TJPEGImage;
path : String;
begin
path := ExtractFilePath(Application.EXEName);
// Set WPViewPDF DLL name:
WPViewPDFDLLNAME := 'wPDFView01.dll';
// Install PDF License
WPPDFViewerStart('LICNAME','LICKEY',LICCODE);
// Create a Viewer
pdf := TWPViewPDF.Create(nil);
// Currently we need a parent
pdf.SetBounds(-10,-10,1,1);
pdf.Parent := Self;
page := StrToIntDef( PageNr.Text, 1);
try
pdf.LoadFromFile(FileName.Text);
meta := pdf.GetMetafile(page);
if meta<>nil then
try
if (FormatName.Text='BMP') or (FormatName.Text='JPEG') then
begin
bit := TBitmap.Create;
try
bit.Width := Round(meta.MMWidth /10);
bit.Height := Round(meta.MMHeight /10);
bit.Canvas.StretchDraw(bit.Canvas.ClipRect, meta);
if FormatName.Text='JPEG' then
begin
jpeg := TJPEGImage.Create;
try
jpeg.Assign(bit);
jpeg.Compress;
jpeg.SaveToFile(path + PageNr.Text + '.JPG');
Image1.Picture.Assign(jpeg);
finally
jpeg.Free;
end;
end else
begin
Image1.Picture.Assign(bit);
bit.SaveToFile(path + PageNr.Text + '.BMP');
end;
finally
bit.Free;
end;
end
else
begin
Image1.Picture.Assign(meta);
meta.SaveToFile(path + PageNr.Text + '.EMF');
end;
finally
meta.Free;
end;
finally
pdf.Parent := nil;
pdf.Free;
end;
end;
Alles anzeigen
In this code we first retrieve a metafile from the PDF viewer and then render that metafile on a bitmap. This bitmap can then be assigned to a TJPEGImage and finally to a TImage.Picture.
The complete project is available here:
https://www.wpcubed.com/ftp/ex/WPViewPDF_BMP.zip