许多生成PDF的人需要绑定它们。良好的绑定要求每个其他页面在其左侧和右侧都支持一个可选边距大小。我知道JasperReports在3.x系列中不支持这一点。这是在4.x系列中支持的吗?JasperReports是否支持交替排水边距呢?
5
A
回答
4
您可以完成由Dave提到的marginMirroring,通过继承JRPdfExporter,覆盖方法exportReportToStream。不幸的是,您需要将此方法的源代码复制到您的覆盖中。在覆盖中,您将修改页面循环,就像这样:
for(int pageIndex = startPageIndex; pageIndex <= endPageIndex; pageIndex++)
{
int margin = marginLeft;
if (pageIndex % 2 == 1) margin = marginRight;
parameters.put(JRExporterParameter.OFFSET_X, margin);
setOffset();
...
我的子类的构造函数中的边距:
public MirroringJRPdfExporter(int left, int right, int top, int bottom) {
this.marginLeft = left;
this.marginRight = right;
this.marginTop = top;
this.marginBottom = bottom;
}
我把在顶部和底部的过,万一我需要镜像页面翻转。
另一个不幸的消息是,exportReportToStream使用助手JRPdfExporterTagHelper,并调用2个方法,init和setPdfWriter,这些方法都是受保护的,所以除非您也将助手子类化并将这些方法暴露给您的子类,否则您的子类将无法编译。我这样做:
public class JRPdfExporterTagHelper extends
net.sf.jasperreports.engine.export.JRPdfExporterTagHelper {
protected JRPdfExporterTagHelper(JRPdfExporter exporter) {
super(exporter);
}
public void setPdfWriter2(PdfWriter pdfWriter) {
setPdfWriter(pdfWriter);
}
public void init2(PdfContentByte pdfContentByte) {
init(pdfContentByte);
}
}
然后,我把它称为是这样的:
MirroringJRPdfExporter exporter = new MirroringJRPdfExporter(72, 36, 44, 31);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, output);
exporter.exportReport();
0
要与碧玉5.6工作之外的答案,@bigspotteddog我所做的:
@Override
protected PdfReportConfiguration getCurrentItemConfiguration() {
SimplePdfReportConfiguration config = new SimplePdfReportConfiguration();
PdfReportConfiguration currentItemConfiguration = super.getCurrentItemConfiguration();
config.setCollapseMissingBookmarkLevels(currentItemConfiguration.isCollapseMissingBookmarkLevels());
config.setForceLineBreakPolicy(currentItemConfiguration.isForceLineBreakPolicy());
config.setForceSvgShapes(currentItemConfiguration.isForceSvgShapes());
config.setIgnoreHyperlink(currentItemConfiguration.isIgnoreHyperlink());
config.setOverrideHints(currentItemConfiguration.isOverrideHints());
config.setSizePageToContent(currentItemConfiguration.isSizePageToContent());
config.setEndPageIndex(currentItemConfiguration.getEndPageIndex());
config.setExporterFilter(currentItemConfiguration.getExporterFilter());
config.setHyperlinkProducerFactory(currentItemConfiguration.getHyperlinkProducerFactory());
config.setPageIndex(currentItemConfiguration.getPageIndex());
config.setProgressMonitor(currentItemConfiguration.getProgressMonitor());
config.setStartPageIndex(currentItemConfiguration.getStartPageIndex());
config.setOffsetX(margin);
return config;
}
和:
margin = marginLeft;
if (pageIndex % 2 == 1) margin = marginRight;
在循环中。
1
在JasperReports中6.x中,你可以通过设置
<property name="net.sf.jasperreports.export.pdf.odd.page.offset.x" value="10"/>
<property name="net.sf.jasperreports.export.pdf.even.page.offset.x" value="-10"/>
一个例子指定单独偶数和奇数页的报告模板(JRXML)利润率从JasperReports的示例文件demo/samples/query/reports/QueryReport.jrxml
找到。我在an issue中找到了此解决方案。
同样可以在Java导出报表为PDF时使用JRPdfExporter
类设置:
JRPdfExporter exporter = new JRPdfExporter();
SimplePdfReportConfiguration configuration = new SimplePdfReportConfiguration();
configuration.setOddPageOffsetX(10);
configuration.setEvenPageOffsetX(-10);
exporter.setConfiguration(configuration);
相关问题
- 1. JasperReports/iReport是否支持Hibernate注释?
- 2. OS X是否支持3x缩放呢?
- 3. gwt是否支持i18n距离格式?
- 4. Alamofire是否支持HTTP流水线?
- 5. com.sun.net.httpserver.HttpServer是否支持流水线?
- 6. S3是否支持HTTP流水线?
- 7. Android支持工具栏标题边距
- 8. CORBA是否支持ASCII数据交换?
- 9. Mercurial是否支持空提交消息?
- 10. DisplayTag PaginatedList是否支持外部排序?
- 11. WIX是否支持框架4.6的检测呢?
- 12. 替代负边距
- 13. 是否支持MSNP9?
- 14. 是否支持DataGrid?
- 15. 是否支持ARC?
- 16. 支持JasperReports和BIRT的通用框架
- 17. PDF亚洲字符支持 - JasperReports
- 18. 大多数浏览器(包括IE6)是否支持TD行距?
- 19. JasperReports中的交叉表排序
- 20. 是否有支持esmtp流水线的java api?
- 21. Firefox是否支持enablePrivilege(“UniversalBrowserRead”)?
- 22. Xcode 4.3是否支持distcc?
- 23. GCC是否支持C++ AMP
- 24. PySide是否支持Python 3?
- 25. AlertDialog是否支持WebView?
- 26. GWT是否支持php?
- 27. 是否正式支持android.speech.extra.DICTATION_MODE?
- 28. Android 4.0.3是否支持SIP?
- 29. 是否支持WSE 3.0?
- 30. logback是否支持log4j appenders?
你的意思JasperReports的iReport的还是? – 2011-04-22 18:47:07