1 year ago
#71099
Pedro Zandonadi Menzel
TPDFImage.LoadFromFile makes printer screen show up and cuts off the rest of the function's execution
I am aiming to convert a PDF to JPEG, so I can show it in an image viewer that is embedded in my Delphi program. Here is the code for my function:
function TAnexo.loadFilePdf(AFile:String): Boolean;
Var FPicture:TPDFImage;
FStream: TMemoryStream;
PdfExist: Boolean;
jpeg: TJPEGImage;
begin
result := false;
PdfExist := fileExists(AFile);
if PdfExist then
begin
fResultFileNameBmp := AFile + '.jpg';
FPicture:=TPDFImage.Create;
Try
//set resolution and page before load so the first requested page is loaded
FPicture.Resolution:=300;
FPicture.PixelFormat := pf24bit;
FPicture.CurrentPage:=1;
FPicture.LoadFromFile(AFile);
jpeg := TJPEGImage.Create;
try
jpeg.CompressionQuality := 100;
jpeg.PixelFormat := jf24Bit;
jpeg.Scale := jsFullSize;
jpeg.Performance := jpBestQuality;
jpeg.GrayScale := False; {Apenas tons de cinza}
jpeg.ProgressiveDisplay := False; {Display Progressivo}
jpeg.Assign(FPicture);
jpeg.SaveToFile(fResultFileNameBmp);
finally
jpeg.Free;
end;
self.loadFileToBinary(fResultFileNameBmp);
finally
FPicture.Free;
DeleteFile(fResultFileNameBmp);
DeleteFile(AFile);
end;
end;
end;
But when the function reaches the line "FPicture.LoadFromFile(AFile);", it shows a screen requesting that I choose between the available printers to print the PDF and, no matter what I choose, the rest of the function will not execute.
What could be the solution? My intention is not to print the PDF, but only to make de PDF-JPEG conversion behind the scenes so I can visualize it in the image viewer whenever I would like.
Edit: Aparently there's another line responsible for making the printer dialog show up in my program. I have an instance of TChromium calling the PrintToPdf() function before my custom function executes, but I still don't know how to make my instance of TChromium save the PDF without bringing up the printer dialog. Here's the code where it executes:
procedure TfrmDarfOnline.actConfirmarExecute(Sender: TObject);
begin
Self.fDarfAvulso.FilePdf := ArquivoPDF{my PDF file's path};
Self.fDarfAvulso.Chrome.PrintToPDF(Self.fDarfAvulso.FilePdf,'DARF',Self.Chrome.Browser.MainFrame.GetURL);
sleep(2000);
Chrome.ClearCache;
Chrome.DeleteCookies('http://www31.receita.fazenda.gov.br');
inherited;
ModalResult := mrOk;
end;
delphi
jpeg
0 Answers
Your Answer