AFIK没有
configuration
在jasper report中设置视图首选项(页面模式)。我唯一的解决方案是用itext(用于导出为pdf的库,已经在classpath中)发布pdf
实例
我们将jasper作为PDF导出到内存流(
ByteArrayOutputStream
)然后使用itext
PdfStamper
添加查看器首选项
PageModeUseOutlines
1.
//Get the JasperPrint object (exact code to achieve this intentional left out since command depends on application)
JasperPrint jasperPrint = JasperFillManager.fillReport(...);
//Export to pdf into a memory stream
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
ByteArrayOutputStream memoryStream = new ByteArrayOutputStream();
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(memoryStream));
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
exporter.setConfiguration(configuration);
exporter.exportReport();
//Use stamper to set viewer prederence
PdfReader pdfReader = new PdfReader(new ByteArrayInputStream(memoryStream.toByteArray()));
PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileOutputStream("my.pdf"));
pdfStamper.getWriter().setViewerPreferences(PdfWriter.PageModeUseOutlines);
pdfStamper.close();
pdfReader.close();
链接到itext5 api,但请注意jasper reports实际上使用了itext 2.1.7的一个特殊版本请参见maven dependence以获取更多信息