Recent

Author Topic: excluding page from export before PrepareReport  (Read 926 times)

calm_sea

  • New member
  • *
  • Posts: 7
excluding page from export before PrepareReport
« 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?

Zvoni

  • Hero Member
  • *****
  • Posts: 737
Re: excluding page from export before PrepareReport
« Reply #1 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?
One System to rule them all, One IDE to find them,
One Code to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
People call me crazy, because i'm jumping out of perfectly fine aircraft

GetMem

  • Hero Member
  • *****
  • Posts: 3491
Re: excluding page from export before PrepareReport
« Reply #2 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.

Zvoni

  • Hero Member
  • *****
  • Posts: 737
Re: excluding page from export before PrepareReport
« Reply #3 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)
One System to rule them all, One IDE to find them,
One Code to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
People call me crazy, because i'm jumping out of perfectly fine aircraft

calm_sea

  • New member
  • *
  • Posts: 7
Re: excluding page from export before PrepareReport
« Reply #4 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.

Zvoni

  • Hero Member
  • *****
  • Posts: 737
Re: excluding page from export before PrepareReport
« Reply #5 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*
One System to rule them all, One IDE to find them,
One Code to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
People call me crazy, because i'm jumping out of perfectly fine aircraft

calm_sea

  • New member
  • *
  • Posts: 7
Re: excluding page from export before PrepareReport
« Reply #6 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