2

I've tried to send the text of my Rich Edit to FastReport so that I can save the output as a PDF.

I used the OnGetValue

    procedure TfrmEmediaInvoice.frxReport1GetValue(const VarName: string;
  var Value: Variant);
begin
 value := redInvoice.Text;
end;

Problem is it retains no tabbing #9.

Can someone show me the correct way to print or export contents of a rich edit to a PDF. Thanks

  • To clarify, I can print redInvoice to FastReport via the OnGetValue event. However, the output does not retain the tab spacing that was set in the RichEdit component. – Brent Coetzee Mar 05 '21 at 14:24

1 Answers1

1

I managed to export the contents of my formatted Rich Edit component with custom tab spacing.

In FastReports I used a tfrxRichView box. This problem is that when you send it to FastReports via the OnGetValue Event, it loses its custom tab spacing.

I solved this by saving the contents of my Rich Edit to a .rtf file

redInvoice.Lines.SaveToFile('Invoice - ' + sInvoice + '.rtf');

Then I opened the .rtf file in FastReports tfrxRichView box.

RichView := TfrxRichView(frxReport1.FindObject('Rich1'));
  if RichView = nil then
    Exit;
  Stream := TMemoryStream.Create;
  try
    Stream.LoadFromFile('Invoice - ' + sInvoice + '.rtf');
    SetLength(Str, Stream.Size);
    Stream.Read(Str[1], Stream.Size);
    RichView.RichEdit.Text := Str;
  finally // wrap up
    Stream.Free;
  end;    // try/finally

Finally, I exported it to PDF. "ExportPDF" is method I made to hold the lengthy export code.

 frxUserDataSet1.RangeEnd := recount;
 frxUserDataSet1.RangeEndCount := redInvoice.Lines.Count;

  try
  ExportPDF;
  Showmessage('Invoice published.');
  except
  showmessage('Error - Invoice not published.');
  end;

Yes you need to use a frxUserDataSet on your MasterData section in FastReports.