I need do conver a RTF file to PDF.
Its works fine til I update the wPDF component to version 5.
My RTF was created with WPTool6 from another application that we cant to update to WPTool9...
But the result PDF generated - with RTF by WPTool6 e converted to PDF with wPDF5 - have font encode problems.
Then I tried develeper a DLL with Delphi 12 - with WPTool9 and wPDF5 - where I get another problem: beffore the convertion, I need to put a image at the top of document, but the image dont appears in a PDF file. If I compile a test .exe app and try to execute the same code, it works fine, the image appears.
Use the component in a DLL is a problem? I neep only the PDF convertion then I set visible = False;
Example 1 (no access violation):
procedure TConvertToPDF.Convert(pFileNameIn, pFileNameOut, pParams: PAnsiChar);
var
WPRichText : TWPRichText;
WPPDFExport: TWPPDFExport;
begin
WPDF_Start(wPDFName, WPDFCode);
WPRichText := TWPRichText.Create(nil);
try
WPRichText.Visible := False;
WPRichText.LoadFromFile(pFileNameIn);
WPRichText.ReformatAll();
WPRichText.MovePosition(wpmHome, False);
WPRichText.FastInsertParagraph;
WPRichText.MovePosition(wpmHome, False);
WPRichText.FastInsertParagraph;
WPRichText.InsertGraphic('D:\Desenv\VilaRica\Docs\Logotipo\logo.bmp', False, []); // access violation here
WPRichText.Refresh;
// Export to PDF
WPPDFExport := TWPPDFExport.Create(nil);
try
WPPDFExport.Source := WPRichText;
WPPDFExport.FileName := pFileNameOut;
WPPDFExport.Print;
finally
FreeAndNil(WPPDFExport);
end;
finally
FreeAndNil(WPRichText);
end;
end;
Example 2 (no access violation, but no add the image):
procedure TConvertToPDF.Convert(pFileNameIn, pFileNameOut, pParams: PAnsiChar);
var
WPRichText : TWPRichText;
WPPDFExport: TWPPDFExport;
begin
WPDF_Start(wPDFName, WPDFCode);
WPRichText := TWPRichText.Create(nil);
try
WPRichText.Visible := False;
WPRichText.OnRequestHTTPImage := RequestHTTPImage;
WPRichText.LoadFromFile(pFileNameIn);
WPRichText.ReformatAll();
WPRichText.MovePosition(wpmHome, False);
WPRichText.FastInsertParagraph;
WPRichText.MovePosition(wpmHome, False);
WPRichText.FastInsertParagraph;
WPRichText.InsertGraphic('D:\Desenv\VilaRica\Docs\Logotipo\logo.bmp', True, []);
WPRichText.Refresh;
// Export to PDF
WPPDFExport := TWPPDFExport.Create(nil);
try
WPPDFExport.Source := WPRichText;
WPPDFExport.FileName := pFileNameOut;
WPPDFExport.Print;
finally
FreeAndNil(WPPDFExport);
end;
finally
FreeAndNil(WPRichText);
end;
end;
procedure TConvertToPDF.RequestHTTPImage(RTFData: TWPRTFDataCollectionBase; Reader: TWPCustomTextReader; const LoadPath, url: string; TextObject: TWPTextObj; var Ok: Boolean);
begin
TextObject.LoadObjFromFile(url);
Ok := True;
end;