Hi,
wPDF needs a TWPRichText or a TWPCustomRTFEdit to render the RTF.
You can also use a temporary TWPCustomRTFEdit.
Please do not forget to call "ReformatAll" before the export.
Example:
procedure TForm1.CreatePDFClick(Sender: TObject);
var wp: TWPCustomRTFEdit; // Central component of WPTools 5 or 6
pdf: TWPPDFExport; i: Integer;
s : string;
begin
if SaveDialog1.Execute then
begin
wp := TWPCustomRTFEdit.CreateDynamic;
pdf := TWPPDFExport.Create(nil);
pdf.Filename := SaveDialog1.FileName;
pdf.Source := wp;
// Now set some propeties for the PDF file
case FontModeCombo.ItemIndex of
0: begin pdf.FontMode := wpUseTrueTypeFonts;
pdf.CidFontMode := wpCIDOff;
end;
1: begin pdf.FontMode := wpEmbedTrueTypeFonts;
pdf.CidFontMode := wpCIDOff;
end;
2: begin pdf.FontMode := wpEmbedSubsetTrueType_UsedChar;
pdf.CidFontMode := wpCIDUnicode;
end;
end;
// Do we need PDF Level A Support ?
if UsePDFAMode.Checked then
pdf.PDFAMode := wpdfaLevelA
else pdf.PDFAMode := wpdfaOff;
// Now we compression, encryption etc
pdf.CompressStreamMethod := wpCompressFlate;
Screen.Cursor := crHourGlass;
// Show it when completed
pdf.AutoLaunch := TRUE;
try
s := 'some_rtf_file.rtf'
wp.LoadFromFile(s,true,'AUTO');
wp.ReformatAll(true,false);
// We use the first file to set some info items and then start the PDF file
if not pdf.Printing then
begin
pdf.Info.Author := wp.RTFVariables.Strings['Author'];
pdf.Info.Subject := wp.RTFVariables.Strings['Subject'];
pdf.Info.Keywords := wp.RTFVariables.Strings['Keywords'];
pdf.BeginDoc;
end;
pdf.Print;
end;
finally
if pdf.Printing then pdf.EndDoc;
pdf.Free;
wp.Free;
Screen.Cursor := crDefault;
end;
end;