java - BIRT 报告为具有横向布局的 PDF

标签 java birt

我遇到了 BIRT 报告生成器的问题。我使用设计器创建了一个报告,并将其母版页方向设置为 landscape 并将页面类型设置为 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 作为 this link 更改页面方向说,但我不知道在哪里申请。我正在使用 birt runtime 4.2.0。

有什么想法吗?

最佳答案

我终于设法在没有为引擎设置类加载器和没有特定的 pdf 渲染选项的情况下让它工作:

ReportEngine engine = new ReportEngine(new EngineConfig());

// open design document
IReportRunnable runnable = engine.openReportDesign(this._ServletContext
    .getRealPath("/")
    + reportPath.get_Path());

IRunAndRenderTask task = engine.createRunAndRenderTask(runnable);

for (Entry<String, Object> ent : reportParams.entrySet()) {
    task.setParameterValue(ent.getKey(), ent.getValue());
}

task.setParameterValue("data_url", this._DataUrl);
task.setParameterValue("user_name", this._UserName);
task.setParameterValue("user_password", this._UserPassword);

task.setLocale(locale);

final IRenderOption options = new RenderOption();
options.setOutputFormat("pdf");
options.setOutputStream(os);

task.setRenderOption(options);
task.run();

task.close();

关于java - BIRT 报告为具有横向布局的 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17215978/

相关文章:

java - 使用 Java 写入文件

java - 如何在构建方法期间为 Java 类的 ArrayList 成员变量赋值?

java - PaintComponent 和 getTableCellRendererComponent 没有被调用

数据集查询返回零结果时 BIRT 报告异常

properties - 来自属性文件的 Birt 数据源参数

birt - 带有目录的 PDF 报告,其中包含 BIRT 中的页码

java - 为什么线程执行在下一行执行之前完成

java - onbackpressed() 从 Activity 到特定 fragment

java - Zend Server CE 和 BIRT 与 Javabridge 集成

java - 在netbeans中的strut2应用程序中仅生成birt图表