BIRT报告为PDF,具有横向布局 [英] BIRT report as PDF with landscape layout

查看:170
本文介绍了BIRT报告为PDF,具有横向布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正遇到BIRT报告生成器的问题.我使用设计器创建了一个报告,并将其主页方向设置为 landscape ,并将页面类型设置为A4,无法使用服务器的报告引擎来使其正常工作(它始终以纵向方向呈现) ).如果我省略pdfOptions添加,问题仍然出现.

I'm facing an issue with BIRT report generator. I created a report using the designer and having set its masterpage orientation to landscape and page type to A4, there's no way to get it working using the report engine of my server (it always renders with the portrait orientation). If I ommit pdfOptions adding, the problem still appears.

但是,当我使用设计器的预览选项时,它可以工作.

However, it works when I use designer's preview option.

那是我的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作为

It seems to be an option to change the page orientation using javascript as this link says, but I don't know where to apply that. I'm using birt runtime 4.2.0.

有什么主意吗?

推荐答案

我终于设法在不为引擎设置类加载器且没有为pdf呈现设置特定选项的情况下使它工作:

I finally managed to get it working without setting the class loader for the engine and without specific options for pdf rendering:

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();

这篇关于BIRT报告为PDF,具有横向布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆