如何移动整个布局以适应不同打印机上的预打印表单 [英] How can I move the whole layout to adapt to pre-printed form on different printers

查看:131
本文介绍了如何移动整个布局以适应不同打印机上的预打印表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用Java,Hibernate,Spring和Jasper Report 5.6开发了美国医疗保健医疗计费产品。使用CMS 1500和UB04表格进行打印。

We have US Healthcare Medical Billing Product developed using Java, Hibernate, Spring and Jasper Report 5.6. that are printing with CMS 1500 and UB04 Form.

我们希望以预先打印的表格打印值,即用户将保留此值打印机中的打印表格和我们需要打印框中值的应用程序。

We want to print the values in the pre printed form i.e user will keep the this pre printed form in the printer and from the application we need to print the values in the boxes.

因此,我们将图像附加到Jasper报告中,并将文本框放在每个框中。它打印正确,但如果用户更改打印机,则对齐将变为问题。作为备用脏选项,我们获取了该副本并为该打印机进行了对齐,因此现在对于每台打印机,我们都有单独的jasper报告文件,即使打印的值相同。

So we attached the image in the Jasper Report and put the text boxes in each of the boxes. It is printing correctly, but if the user change the printer, then alignment is becomes a problem. As a alternate dirty option, we took the copy and make the alignment for that printer, so now for every printer we have separate jasper report file even though the values that are printed are the same.

我的客户要求他们选择以单独的形式设置X和Y值,然后使用这些值正确打印。

My client is asking to give them a option to set the X and Y value in separate form and then use these values to print correctly.

所以问题是我们可以在jasper报告中这样做吗?

So the question is can we do this in jasper reports?

推荐答案

移动所有报表元素的最简单方法是修改报表边距

The easiest way to move all report elements is to modify the report margins

jrxml 加载到 JasperDesign 根据需要对象和切换边距。您可以在x中移动的最小值是原始报表边距,最大值取决于您的报表(当然columWidth不能变为0,但没有真正意义上检查这更好以定义最大值)

Load the jrxml in to the JasperDesign object and switch margins as desired. The minimum you can move in x is the original report margin, the maximum depends on your report (naturally the columWidth can not become 0, but has no really sense checking this better to define a max)

示例:

JasperDesign design = JRXmlLoader.load("YourReport.jrxml");
moveDesign(design,x,y);
JasperReport report = JasperCompileManager.compileReport(design);

private void moveDesign(JasperDesign design, int x, int y) {
    int maxX = 100; //I define it so that elements is not out of report
    int maxY = 100;

    int pageWidth = design.getPageWidth();
    int intitalLeftMargin = design.getLeftMargin();
    int intitalRightMargin = design.getRightMargin();
    int intitalTopMargin= design.getTopMargin();

    //Check that not less then 0 and not more then my max       
    int newLeftMargin = Math.min(Math.max(intitalLeftMargin+x,0),maxX);
    int newTopMargin = Math.min(Math.max(intitalTopMargin+y,0),maxY);

    //set our new margins
    int newColumWidth = pageWidth - newLeftMargin - intitalRightMargin;
    design.setLeftMargin(newLeftMargin);
    design.setTopMargin(newTopMargin);
    design.setColumnWidth(newColumWidth);
}

这方面的缺点是你需要重新编译你的报告(这将花费几毫秒)。

The down-side of this is that you need to recompile your report (this will take a couple of ms).

如果执行速度至关重要另一个解决方案(更复杂但可能更快)是移动所有 JasperPrint中每个页面中的元素

If execution speed is of fundamental importance another solution (more complex but probably faster) is to move all elements in every page in the JasperPrint

我会将完整的代码留给OP,但它会与此类似

I will leave the complete code to OP but it will be similar to this

List<JRPrintPage> pages = jasperPrint.getPages();
for (JRPrintPage jrPrintPage : pages) {
    List<JRPrintElement> elements = jrPrintPage.getElements();
    for (JRPrintElement jjpe : elements) {
        jjpe.setX(newX);
        jjpe.setY(newX);    
    }   
}

这篇关于如何移动整个布局以适应不同打印机上的预打印表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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