Generate ZEN report, PDF file programmatically
Hi All,
I have a ZEN report, which gives a PDF output, i want to generate this report programmatically, save to a location in the disk. Here is my method so far
ClassMethod GenerateReport(ReportID, ReportClass, P1, P2, P3, P4, P5, P6, P7, P8, P9, PUser, PUserID, PUserProfileID, mode = 2, ByRef outputfile = "") As %Status { set filename="" set ZenClassName=$piece(ReportClass,".cls") set oRpt=$classmethod(ZenClassName,"%New") set oRpt.RUID=##class(websys.Report).GetRUID(P1,P2,P3,P4,P5,P6,P7,P8,P9,PUser,PUserID,"",PUserProfileID) set FileExt=..GetModeExt(mode) if outputfile="" { set filepath=..getTempPath() set pdffile=ZenClassName_"_"_$zstrip($piece(##class(Ens.Util.File).CreateTimestamp(),"_",3),"*P")_"_"_$random(9999)_"."_FileExt set filename=filepath_pdffile } else { set filename=outputfile } if (FileExt="PDF"){ set renderserver="" if $get(^%SYS("zenreport","renderserverport"))'="" { set renderserver=##class(websys.Report).RenderServerCheck() } if ReportID { set ZenSplitMerge=0 set (ZenSplitMergeElement, ZenSplitMergeElementCount)="" &SQL(SELECT ZenSplitMerge, ZenSplitMergeElement, ZenSplitMergeElementCount INTO :ZenSplitMerge, :ZenSplitMergeElement, :ZenSplitMergeElementCount FROM websys.report WHERE ID= :ReportID) if SQLCODE set ZenSplitMerge=0 if $get(ZenSplitMerge)=1,$get(ZenSplitMergeElement)="" set ZenSplitMerge=0 } if $get(ZenSplitMerge)=1 { set oRpt.SplitAndMerge=1 set oRpt.RepeatingElement=$get(ZenSplitMergeElement) if $get(ZenSplitMergeElementCount)'="" set oRpt.CountRepeatingElement=$get(ZenSplitMergeElementCount) } //Generates pdf to file on DB server if renderserver="" { set tSC=oRpt.GenerateReport(filename,2) } else { set tSC=oRpt.GenerateReport(filename,2,0,renderserver) } } else{ try { set tSC=oRpt.GenerateReport(filename,mode) } catch (err) { set tSC = $$$ADDSC(sc,err.AsStatus()) } } set outputfile=filename quit tSC }
This method generates a .xsl and .xml file which has my output, how can i get a pdf?
Thanks in Advance.
Rizmaan
set tSC=oRpt.GenerateReport(filename,2) - generates a .pdf in filename
if $get(ZenSplitMerge)=1 {
see ZenSplitMerge, if ZenSplitMerge<> 1 then
set tSC=oRpt.GenerateReport(filename,mode)
and generates other files .
thank you,
I am using the following method
set tSC=oRpt.GenerateReport(filename,2)
which the filename is a .pdf file, and when i check the output folder a .xml, which has my output and a .xsl file
tSC returns this
any idea why
Looks like you implemented that method yourself. Did you try using the predefined method in %ZEN.Report.reportPage?
https://cedocs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GRPT_report_running#GRPT_command_line_generatereport