Frequently Asked Question:
Problem converting TIFF image to PDF using Delphi
Question
I'm trying to convert a TIFF image to PDF using the following code. However, the resulting PDF has the dimensions of the TIFF image, but it is completely empty.
What's wrong in this code?
procedure TForm2.Button1Click(Sender: TObject);
var PDFLibrary: TQuickPDF0718;
UnlockResult: Integer; ImageID: Integer;
begin PDFLibrary := TQuickPDF0713.Create;
with PDFLibrary do try UnlockResult := UnlockKey('mytrialkey');
Label1.Caption := LicenseInfo;
if UnlockResult = 1 then
begin ImageID := AddImageFromFile('AValidBWTifImage.tif', 0);
if ImageID > 0 then
begin SelectImage(ImageID);
SetPageDimensions(ImageWidth, ImageHeight);
if DrawImage(0, 0, ImageWidth, ImageHeight) = 1 then SaveToFile('C:\HelloFromDelphi.pdf');
end; end else begin ShowMessage('Invalid license key');
end;
finally Free;
end;
end;
Answer
It looks like AddImageFromFile('AValidBWTifImage.tif', 0); is wrong in your code, you have to do AddImageFromFile('AValidBWTifImage.tif', -1); for TIFF image.