如何在java中将边距设置为jasper报告? [英] How to set margins to jasper report in java?

查看:279
本文介绍了如何在java中将边距设置为jasper报告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在java中为jasper报告设置边距!

How to set margins to jasper report in java!

我有带边距的reports.jasper,但是打印时我必须更改边距!

I have reports.jasper with margins,but when print I must change margins!

JasperPrint.setTopMargins(myMarginsValue)不起作用!!!

我使用 JRPrintServiceExporter 发送给打印机!

I use JRPrintServiceExporter to send to the printer!

当前代码:

InputStream reportStream = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/rep‌​orts/" + "myReport"+".jasper"); 
JasperReport template = (JasperReport) JRLoader.loadObject(reportStream);
template.setWhenNoDataType(WhenNoDataTypeEnum.ALL_SECTIONS_NO_DETAIL);


推荐答案

加载 jrxml (注意不是.jasper)进入 JasperDesign 使用 JRXmlLoader

Load the jrxml (note not the .jasper) into the JasperDesign using the JRXmlLoader

JasperDesign design = JRXmlLoader.load(stream); //Location of jrxml file example FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/rep‌​orts/" + "myReport"+".jrxml");
design.setBottomMargin(bottomMargin); //set the margins
design.setTopMargin(topMargin)
design.setLeftMargin(leftMargin)
design.setRightMargin(rightMargin);
design.setColumnWidth(design.getPageWidth()-leftMargin-rightMargin);//if you change your left and right margin you need to set new correct columnWidth

//compile the report
JasperReport report = JasperCompileManager.compileReport(design); //this is what you called template

然后填充它和出口它如你所愿。

当然textField可能不在设计范围内,如果你将边距增加到很多,乐队可能不适合页面高度,这需要适当考虑。

Naturally textField may be out side of design, band may not fit the page height if you increase your margins to much, this needs to be attended to as appropriate.

如果目的是移动布局以适应预先打印的形式,这是另一个类似的完整代码问题:如何移动整个布局以适应不同打印机上的预打印表单

This is another similar question with full code if the purpose is moving layout to adapt to pre-printed form: How can I move the whole layout to adapt to pre-printed form on different printers

这篇关于如何在java中将边距设置为jasper报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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