AL icon indicating copy to clipboard operation
AL copied to clipboard

[Event Request] Table 77 Report Selection, SaveReportAsPDF

Open sirhc101 opened this issue 8 years ago • 4 comments

Please add the following event to table object 77 Report Selection function SaveReportAsPDF(). This would help to merge stationery or add additional pdfs (e.g. general terms) to the created files.

An useful signature would be ReportID, RecordVariant, FilePath.

LOCAL SaveReportAsPDF(ReportID : Integer;RecordVariant : Variant;LayoutCode : Code[20]) FilePath : Text[250]
FilePath := COPYSTR(FileMgt.ServerTempFileName('pdf'),1,250);

ReportLayoutSelection.SetTempLayoutSelected(LayoutCode);
REPORT.SAVEASPDF(ReportID,FilePath,RecordVariant);
ReportLayoutSelection.SetTempLayoutSelected('');

COMMIT;
// ---New Code Begin---
OnAfterSaveReportAsPdf(ReportID, RecordVariant, FilePath);
// ---New Code End---

Thank you.

sirhc101 avatar May 25 '18 11:05 sirhc101

File usage is not allowed in the cloud. Would an event that passes the Stream with the PDF work instead?

StanislawStempin avatar Aug 03 '18 14:08 StanislawStempin

Well, that's a good question. The problem is, that I want to use the created pdf file. I can handle streams, that's not the problem, but SAVEASPDF at this point will create a file, isn't it?

Is there any way to get the stream instead of the pdf file to apply stationery paper?

The problem is really simple. Some of my customers are using printers with stationery paper tray. But if the use the Mail / Send method they would like to have stationery paper, even if the RDLC report don't have. Of course, I could set multiple layouts for my report, but it would be much easier to apply a stationery paper at the created pdf file.

sirhc101 avatar Aug 07 '18 20:08 sirhc101

Try to subscribe to the existing event COD9651.OnBeforeMergeDocument(..) that is called by all system SAVEAS... methods. There are parameters that seems to be enough for what you want to do:

  • ReportID : integer,
  • ReportAction : 'SaveAsPdf,SaveAsWord,SaveAsExcel,Preview,Print,SaveAsHtml'
  • InStrXmlData : instream
  • OutStream : outstream

You subscribe, do your changes to InStrXmlData and then

COPYSTREAM(OutStream,InStrXmlData);
Handled := TRUE;

on return from event this file will be exported, if OutStream has some value and file name is not blank.

Or you override the existing functionality by exporting all needed files in your subscriber, leaving OutStream blank, and setting Handled := TRUE;

StanPesotskiy avatar Aug 23 '18 12:08 StanPesotskiy

Yeah, I tried and it worked! Thanks a lot. Well, I needed to do some changes in my service to attach the stationery paper, but it worked.

sirhc101 avatar Aug 27 '18 14:08 sirhc101