Lazarus

Programming => Packages and Libraries => LazReport => Topic started by: calm_sea on August 31, 2021, 09:33:57 am

Title: excluding page from export before PrepareReport
Post by: calm_sea on August 31, 2021, 09:33:57 am
Hello everybody! I have a multi-page report. How can I exclude a page from export at run time?
Title: Re: excluding page from export before PrepareReport
Post by: Zvoni on August 31, 2021, 10:13:21 am
So, basically you're looking for an option like

"Print Pages: 1-10;12-20" --> Exclude Page 11

and the Result is a PDF with 19 Pages, missing page 11?
Title: Re: excluding page from export before PrepareReport
Post by: balazsszekely on August 31, 2021, 10:19:26 am
Hi calm_sea,

Quote
I have a multi-page report. How can I exclude a page from export at run time?
You can't, it's much easier to exclude a page when you generate the report by filtering the dataset. However if you still wish to go with your idea, please take a look at ($LazarusDir)\components\lazreport\source\lr_class.pas, line 11215, you will see the following:
Code: Pascal  [Select][+][-]
  1. procedure TfrReport.ExportBeforeModal(Sender: TObject);
  2. var
  3.   i: Integer;
  4. begin
  5.   if IsMainThread then Application.ProcessMessages;
  6.   for i := 0 to EMFPages.Count - 1 do
  7.   begin
  8.     FCurrentFilter.OnBeginPage;
  9.     EMFPages.ExportData(i);
  10.     InternalOnProgress(i + 1);
  11.     if IsMainThread then Application.ProcessMessages;
  12.     FCurrentFilter.OnEndPage;
  13.   end;
  14.   FCurrentFilter.OnEndDoc;
  15.   if frProgressForm<>nil then
  16.     frProgressForm.ModalResult := mrOk;
  17. end;    

The thing is you have to prevent the execution of EMFPages.ExportData(i) for a specific page i. There are many ways to implement this, like a public variable SkipPages. You also have to adjust the page count of the exported document.
Title: Re: excluding page from export before PrepareReport
Post by: Zvoni on August 31, 2021, 10:43:21 am
Hi calm_sea,

Quote
I have a multi-page report. How can I exclude a page from export at run time?
You can't, it's much easier to exclude a page when you generate the report by filtering the dataset. However if you still wish to go with your idea, please take a look at ($LazarusDir)\components\lazreport\source\lr_class.pas, line 11215, you will see the following:
Code: Pascal  [Select][+][-]
  1. procedure TfrReport.ExportBeforeModal(Sender: TObject);
  2. var
  3.   i: Integer;
  4. begin
  5.   if IsMainThread then Application.ProcessMessages;
  6.   for i := 0 to EMFPages.Count - 1 do
  7.   begin
  8.     FCurrentFilter.OnBeginPage;
  9.     EMFPages.ExportData(i);
  10.     InternalOnProgress(i + 1);
  11.     if IsMainThread then Application.ProcessMessages;
  12.     FCurrentFilter.OnEndPage;
  13.   end;
  14.   FCurrentFilter.OnEndDoc;
  15.   if frProgressForm<>nil then
  16.     frProgressForm.ModalResult := mrOk;
  17. end;    

The thing is you have to prevent the execution of EMFPages.ExportData(i) for a specific page i. There are many ways to implement this, like a public variable SkipPages. You also have to adjust the page count of the exported document.
Could he use a Class-Helper overriding that Procedure?
In that way he could use "for..In...Do" with a set (see also Wiki about Defensive Programming)
Title: Re: excluding page from export before PrepareReport
Post by: calm_sea on August 31, 2021, 11:10:59 am
I'm sorry, I didn't explain well. I have a lrf with 3 pages, the first two contain general data and are contained in a sheet for each, the third is a dataset that can occupy many pages in the export. I would like to allow the user to exclude the insertion of one or both of the first two pages of the lrf with checkboxes.
Title: Re: excluding page from export before PrepareReport
Post by: Zvoni on August 31, 2021, 11:27:50 am
Well, since we don't know, HOW you're exporting (and into what, but i guess to PDF), there is the PrinterDialogue with the From/To-Properties designating the From/To-Pages to print/export *shrug*
Title: Re: excluding page from export before PrepareReport
Post by: calm_sea on August 31, 2021, 11:48:04 am
I am using
Code: Pascal  [Select][+][-]
  1.   if frreport1.PrepareReport then
  2.   begin
  3.     frreport1.ExportTo(TFrTNPDFExportFilter, savedialog1.FileName);
  4.     showmessage(' message for ok');;
  5.   end;
ps: i am beginner with lazreport
TinyPortal © 2005-2018