我正面临 BIRT 报告生成器的问题。我使用设计器创建了一个报表,并将其母版页方向设置为横向,页面类型设置为 A4,无法使用我的服务器的报表引擎使其工作(它始终以纵向呈现)。如果我省略pdfOptions
添加,问题仍然存在。
但是,当我使用设计器的预览选项时,它可以工作。
那是我的ReportRenderer
课:
import javax.servlet.ServletContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IPDFRenderOption;
import org.eclipse.birt.report.engine.api.IRenderOption;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.PDFRenderOption;
import org.eclipse.birt.report.engine.api.RenderOption;
import org.eclipse.birt.report.engine.api.ReportEngine;
import org.springframework.web.context.ServletContextAware;
public class ReportRenderer{
public ByteArrayOutputStream renderReport(ReportPath reportPath,
Map<String, Object> reportParams,
Locale locale) throws EngineException {
IReportEngine engine;
ByteArrayOutputStream os = new ByteArrayOutputStream();
EngineConfig config = new EngineConfig();
engine = new ReportEngine(config);
final IReportRunnable design = engine
.openReportDesign(this._ServletContext.getRealPath("/")
+ reportPath.get_Path());
// design.get
// engine.
// Create task to run and render the report,
final IRunAndRenderTask task = engine.createRunAndRenderTask(design);
//report arguments and language
task.setParameterValue("data_url", this._DataUrl);
task.setParameterValue("user_name", this._UserName);
task.setParameterValue("user_password", this._UserPassword);
for (Entry<String, Object> entry : reportParams.entrySet()) {
task.setParameterValue(entry.getKey(), entry.getValue());
}
task.setLocale(locale);
// Set parent classloader for engine
task.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY,
GenericReportRenderer.class.getClassLoader());
final IRenderOption options = new RenderOption();
options.setOutputFormat("pdf");
options.setOutputStream(os);
final PDFRenderOption pdfOptions = new PDFRenderOption(options);
pdfOptions.setOption(IPDFRenderOption.PAGE_OVERFLOW,
IPDFRenderOption.FIT_TO_PAGE_SIZE);
pdfOptions.setOption(IPDFRenderOption.PAGE_OVERFLOW,
IPDFRenderOption.OUTPUT_TO_MULTIPLE_PAGES);
task.setRenderOption(options);
// run and render report
task.run();
task.close();
return os;
}
}
正如这个链接所说,这似乎是一个使用javascript更改页面方向的选项,但我不知道在哪里应用它。我正在使用 birt 运行时 4.2.0。
任何想法?