CLI/* contains source code for .NET 5 CLI (default target to make it work on win7, there is also .net 8 sync fusion example).
Delphi/* contains source code for delphi wrapper parsing the CLI output, along with error handling, so you can easily integrate it into your delphi application, by checking error types below.
Delphi/RtfToPdf.pas contains ExecRtfToPdf function, which is used to convert RTF to PDF. It accepts two arguments, input file path and output file path.
Delphi/IPC.pas contains ExecAndCapture function, which is internally used to execute CLI and capture its output via anonymous pipe. It is slightly modified version of this code in order to support utf8 strings by casting cli output to PAnsiChar and then to UTF8String. It is important to note that AnsiStrings page code is based on the system code page (windows settings) so beware of that if your CLI output is using non-english characters. Also, pipe buffer size has it's own limits, default buffer size set in function is 4096 bytes, but you can change it to your needs (maximum safe limit is considered to be 64 kB).
-
EFileNotFound - Input file not found
-
EConversionErr - Error while converting file
-
EInvalidJsonResponse - Error while parsing JSON response
-
EUnknownStatus - Unknown status returned in JSON response
-
EInvalidArgLength - Error while parsing arguments
-
EUnknownErrType - Unknown error type returned in JSON response
SyncFusion supports a wide range of input formats (including RTF, DOCX, DOC, TXT, HTML, etc.).
Supported input formats are available here.
All you need is compiled .NET CLI, Delphi/* content in your Delphi project, and RtfToPdf in your uses clause.
Notes: on CLI publish .pdb file can be removed.
uses RtfToPdf;
procedure TForm1.Button1Click(Sender: TObject);
begin
try
RtfToPdf.ExecRtfToPdf(Edit1.Text, Edit2.Text);
ShowMessage('Conversion completed successfully');
except
on E: EFileNotFound do
ShowMessage('Error: ' + E.Message);
on E: EConversionErr do
ShowMessage('Error: ' + E.Message);
on E: EInvalidJsonResponse do
ShowMessage('Error: ' + E.Message);
on E: EUnknownStatus do
ShowMessage('Error: ' + E.Message);
on E: EInvalidArgLength do
ShowMessage('Error: ' + E.Message);
on E: EUnknownErrType do
ShowMessage('Error: ' + E.Message);
on E: Exception do
ShowMessage('Error: ' + E.Message);
end;
end;
SyncFusion is prioprietary software, so you need to have a license to use it (there is also a community version available)
In order to set your license, you need uncomment the following line in CLI/CLI/Program.cs and replace the license key with yours:
// Syncfusion.Licensing.SyncfusionLicenseProvider RegisterLicense("Your License Key");