【发布时间】:2018-01-30 08:14:22
【问题描述】:
如何在运行时使用 javascript 导出 birt 报告?
我尝试过的代码在 After Render 事件中:
importPackage(Packages.org.eclipse.birt.report.engine.api);
rptdoc = reportContext.getReportRunnable().getReportName();
// Open the rptDocument
reportDocument = getReportEngine().openReportDocument(rptdoc);
// Create the render task, configured for the wanted export format
IRenderTask renderTask = getReportEngine().createRenderTask(reportDocument);
IRenderOption options = new RenderOption();
options.setOutputFormat("pdf");
options.setOutputFileName("C:/test/myfile.pdf");
renderTask.setRenderOption(options);
// Launch the render task and close it
renderTask.render();
renderTask.close();
// Close the rptDocument
reportDocument.close();
它运行并且没有错误但没有生成pdf...
我的要求是使用 URL 运行 birt 报告,报告应在文件夹中生成为 pdf。
报告应该只执行一次。我不想执行 URL,然后在报告中它在工厂后执行另一个 runAndRender,报告应该自己导出。希望这是有道理的。
我正在使用 Birt 4.5。
更新的代码。 我可以在报告的 afterRender 事件中使用以下代码使其工作。
//Import Lib for birt this is standard, Import our custom birt report java lib
importPackage(Packages.org.eclipse.birt.report.engine.api);
importPackage(Packages.company.reports.data);
//Creates an instance of our custom class
st = new Packages.company.reports.data.MyStandardFunctions();
//Get Global vaiables
fileDir = reportContext.getGlobalVariable("fileDir");
sTcNumber = reportContext.getGlobalVariable("sTcNumber");
sTcRevNum = reportContext.getGlobalVariable("sTcRevNum");
sTcType = reportContext.getGlobalVariable("sTcType");
sPdfPath = reportContext.getGlobalVariable("sPdfPath");
bHasErrors = reportContext.getGlobalVariable("bHasErrors");
testCertError = reportContext.getGlobalVariable("testCertError");
var re = reportContext.getReportRunnable().getReportEngine();
//Get current dreport
var pathOfReport = reportContext.getReportRunnable().getReportName().replace("file:", "");
//Create a directory for temp export reports TempExport is my dir name.
fileDir = st.createOrGetDir(fileDir);
//Only export to pdf if there were no errors.
if(bHasErrors == false)
{
var des = re.openReportDesign(pathOfReport);
var ntask = re.createRunAndRenderTask(des);
//Set parameters ie. ntask.setParameterValue("sOpiid", params["sOpiid"].value);
ntask.setParameterValue("createPDF", false);
ntask.setParameterValue("TCNumber", sTcNumber);
ntask.setParameterValue("TCRevNum", sTcRevNum);
ntask.setParameterValue("TCType", sTcType);
//The ReportPath were you want to store the file on server(linux) test17.pdf is the name of your file. You can change this.
var outputfile = fileDir + "temp.pdf"; //***** test17.pdf you can change to your file name.
//This is the export options.. this will change when exporting to another format.
var options = new PDFRenderOption();
options.setOutputFileName(outputfile);
options.setOutputFormat("pdf");
ntask.setRenderOption(options);
ntask.run();
ntask.close();
问题在于,当从系统调用报告作为后调用时,它会生成两次报告。现在我知道它为什么这样做了,因为它再次执行 runandrender。我只希望它运行一次并导出为 pdf。
【问题讨论】:
-
嗯,afterRender 事件触发 after 渲染,顾名思义。所以它当然不能开始渲染,因为它永远不会被触发。而且您的代码根本不是有效的 javascript,它是 Java 和 Javascript 的混合体......
-
那你怎么导出呢?
-
我认为问题是为什么您想在运行时使用 javascript 导出报告?对我来说,这似乎是一个根本性的错误用法。
-
@hvb 好的,这是我的场景,我们有一个大系统,当材料出厂时,它应该自动生成材料的测试证书,现在我要做的是调用 birt 报告 URL( Post call) 及其参数形成 RPG 代码,以在网络上的 Windows 服务器上生成报告。从那里pdf将被其他系统使用。希望这能解释我想要达到的目标吗?所以它是对 url 的 post 调用来生成它,我们不希望 pdf 在网络浏览器中打开。
-
我可以创建一个包装 Java Web 服务来调用报告或生成报告,但这对我来说就像我正在创建一个程序来调用报告,而不是仅仅调用一个将生成报告...
标签: javascript pdf birt