WPCubed Product Support

Mechanism to convert existing rtf file to pdf

support

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;
#2 ♥ 0
4.4k Views 2 users read 2 min

I can create a pdf from the WPRichText component utilizing the code below.

WPPDFExport:= TWPPDFExport.Create(nil);
WPPDFExport.Source := WPRichText1;
try
begin
WPPDFExport.FileName := tempEMailAttachment;
WPPDFExport.Print;
end;
finally
WPPDFExport.Free;
end;

Is there a mechanism to create a pdf by directly loading the rtf file that was created from the WPRichText1 component? This would be more direct than reloading the rtf file into the WPRichText1 component and then using this component as the WPPDFExport.Source as in the code above.

TIA

John

#1 ♥ 0