本文介绍了如何在运行时更改页面格式?(jasperreport)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iReport4.5中创建了一个A4格式的报表页面,并在java应用程序中使用。

I created a report page with A4 format in iReport4.5 and use in java application.

如何在Java应用程序中将运行时的A4格式更改为A5格式? / p>

how to change A4 to A5 format on runtime in java application?

推荐答案

在我向您展示如何执行此操作之前,请注意只是更改页面大小可能不会给您带来什么想。它会根据您的需要使页面变大或变小,放置元素的位置不会改变。在您的情况下,报告甚至可能无法编译,具体取决于您所放置项目的位置。

Before I show you how to do this, please note that just changing the Page Size is probably not going to give you what your want. It will make the page larger or smaller depending on what you want, put the positioning of elements will not change. IN your case the report may not even compile depending on where you have items laid out.

您确实有几个选项:


  1. 首先,您可以为A5格式创建第二个报告,然后在运行时
    根据您的需要获取相应的报告。
    这可能是最简单的解决方案,但它确实意味着您最终获得
    ,几乎有2个相同的报告。这意味着未来
    的任何变化都需要在两个地方进行。

  2. 其次,如果它是一个相当简单的报告,你可以使用典型的
    布局像这样的东西,用java代码生成
    报告。

  3. 最后,您可以直接针对Jasper Report的API工作,以
    在运行时生成您的报告。

  1. First you could create a second report for the A5 format, and thenat run time grab the appropriate report depending on what you want.This is probably the easiest solution, but it does mean you end upwith almost 2 identical reports. Meaning any changes in the futureyou would have to do in two places.
  2. Second if it is a fairly straight forward report with a typicallayout you could use something like Dynamic Jasper to generate yourreport in java code.
  3. Lastly you could work directly against the Jasper Report's API togenerate your report at run time.



现在回答你的问题。首先将JRXml文件加载到 JasperDesign 对象中:

//Note JRXMLLoader could also take a File object or
//InputStream instead of a String as the parameter.
JasperDesign design = JRXmlLoader.load("report.jrxml");

一旦你拥有 JasperDesign ,你可以设置页面大小到你想要的。据我所知,A5纸是5.83×8.27。要将此转换为JasperReports理解的大小,每个乘以72,得到420 x 596(我舍入,因为我们必须设置整数)。

Once you have the JasperDesign you can set the page size to what ever you want. A5 paper from what I can tell is 5.83" × 8.27". To convert this to a size that JasperReports understands multiply each by 72, getting you 420 x 596 (I rounded as we have to set Integers).

design.setPageHeight(596);
design.setPageWidth(420);

从那里你可以像往常一样对你的出口冒险进行讽刺。

From there you cointinue on your exporting adventure as you normally would.

这篇关于如何在运行时更改页面格式?(jasperreport)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 16:47