Recent

Author Topic: [SOLVED] Squares instead of spaces while export report to pdf  (Read 4471 times)

artem101

  • Full Member
  • ***
  • Posts: 114
[SOLVED] Squares instead of spaces while export report to pdf
« on: December 27, 2024, 06:42:16 pm »
I use TlrPdfExportFilter to export report created with LazReport to PDF file. After recent changes I discovered that squares (like unknown symbol sign) began to be added to every spaces. Have a look at attached screenshot.
« Last Edit: December 28, 2024, 11:58:09 am by artem101 »

artem101

  • Full Member
  • ***
  • Posts: 114
Re: Squares instead of spaces while export report to pdf
« Reply #1 on: December 27, 2024, 06:48:42 pm »
Attached LRF files

zeljko

  • Hero Member
  • *****
  • Posts: 1881
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Squares instead of spaces while export report to pdf
« Reply #2 on: December 27, 2024, 09:55:17 pm »
Maybe square isn't space,  but eg char #1

artem101

  • Full Member
  • ***
  • Posts: 114
Re: Squares instead of spaces while export report to pdf
« Reply #3 on: December 28, 2024, 09:54:11 am »
but eg char #1
And how did he get here?

I digged out what changes in version control broke PDF and attach this diff file.
« Last Edit: December 28, 2024, 10:09:55 am by artem101 »

artem101

  • Full Member
  • ***
  • Posts: 114
Re: Squares instead of spaces while export report to pdf
« Reply #4 on: December 28, 2024, 10:07:05 am »
I give more information and code which may helps to find solution.

I use two frPeport components combined to one result with frCompositeReport. LRF file contents loads from RC_DATA recources.

Code: Pascal  [Select][+][-]
  1. // ### Create report ###
  2.  
  3. procedure TForm1.ReportsTabSheetShow(Sender: TObject);
  4. var
  5.   i:integer;
  6.   ReportResStream: TResourceStream;
  7.   Report: TfrReport;
  8. begin
  9.   // Resfresh data in SQLQuery
  10.   DataModule1.GeneralStatsSQLQuery.Active:=False;
  11.   DataModule1.GeneralStatsSQLQuery.Active:=true;
  12.   DataModule1.SourcesStatsSQLQuery.Active:=False;
  13.   DataModule1.SourcesStatsSQLQuery.Active:=true;
  14.   DataModule1.MonthlyStatsSQLQuery.Active:=False;
  15.   DataModule1.MonthlyStatsSQLQuery.Active:=true;
  16.   DataModule1.YearlyStatsSQLQuery.Active:=False;
  17.   DataModule1.YearlyStatsSQLQuery.Active:=true;
  18.  
  19.  
  20.   // Make report
  21.   frCompositeReport1.Reports.Clear;
  22.   for i := 1 to 2 do
  23.   begin
  24.     // Load report contents from resource
  25.     ReportResStream := TResourceStream.Create(HINSTANCE, 'REPORT_' + IntToStr(i), RT_RCDATA);
  26.     try
  27.       Report := (FindComponent('frReport' + IntToStr(i))) as TfrReport;
  28.       Report.LoadFromXMLStream(ReportResStream);
  29.       frCompositeReport1.Reports.Add(Report);
  30.     finally
  31.       ReportResStream.Free;
  32.     end;
  33.   end;
  34.   frCompositeReport1.ShowReport;
  35. end;        
  36.  
  37. // ### Save to pdf ###
  38.  
  39. procedure TForm1.SavePDFButtonClick(Sender: TObject);
  40. var
  41.   SaveDlg: TSaveDialog;
  42. begin
  43.   SaveDlg:=TSaveDialog.Create(nil);
  44.   try
  45.     SaveDlg.FileName:=Format('report %s %s.pdf', [DateToStr(Now),
  46.                                         StringReplace(TimeToStr(Now), ':', '-', [rfReplaceAll])]);
  47.     SaveDlg.Filter:='PDF|*.pdf';
  48.     SaveDlg.DefaultExt:='pdf';
  49.     if SaveDlg.Execute and frCompositeReport1.PrepareReport then
  50.     begin
  51.       frCompositeReport1.ExportTo(TlrPdfExportFilter, SaveDlg.FileName);
  52.     end;
  53.   finally
  54.     SaveDlg.Free;
  55.   end;
  56. end;  
  57.  
  58. // ### Set several variables to report ###
  59.  
  60. procedure TForm1.frReport1GetValue(const ParName: String; var ParValue: Variant
  61.   );
  62. begin
  63.   case ParName of
  64.     'Кол-во бронирований', 'Кол-во дней', 'Общий доход', 'Общая комиссия',
  65.     'Средняя продолжительность', 'Кол-во продлений':
  66.        ParValue := DataModule1.GeneralStatsSQLQuery.FieldByName(ParName){.AsString}.Value;
  67.   end;
  68. end;  

artem101

  • Full Member
  • ***
  • Posts: 114
Re: Squares instead of spaces while export report to pdf
« Reply #5 on: December 28, 2024, 11:01:57 am »
I found what brokes PDF - some variables in report has non-breaking space (nbsp) in their format:
Code: Pascal  [Select][+][-]
  1. Number = [[num] #N# ##0]
  2.                    ^-- nbsp, not normal space

If replace them to normal spaces problem disappears.

Seems this is a bug. I`ll make a report to Lazarus bug tracker.

 

TinyPortal © 2005-2018