jasper-reports
Экспорт в pdf
Поиск…
замечания
Для правильного отображения шрифтов в pdf шрифтовые расширения всегда должны использоваться (в classpath)
С интегрированной средой разработки (IDE)
Студия JasperSoft
В окне «Предварительный просмотр» запустите отчет, нажав зеленую стрелку, если нет ошибок в меню экспорта, нажмите кнопку «Экспорт» (образ диска) и выберите «Экспорт как Pdf»,
С Java
Для экспорта вам необходимо заполнить отчет, чтобы получить объект JasperPrint .
Экспорт одного JasperPrint (одного jrxml) в файл
// 1. Create exporter instance
JRPdfExporter exporter = new JRPdfExporter();
// 2. Set exporter input document
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
// 3. Set file path for exporter output
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("/path/filename.pdf"));
// 4. Create configuration instance
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
// 5. Associate configuration with exporter
exporter.setConfiguration(configuration);
// 6. Fill export and write to file path
exporter.exportReport();
Экспортировать несколько JasperPrint (несколько jrxml) в один файл
Только первые шаги отличаются от предыдущих:
List<JasperPrint> jasperPrintList = new ArrayList<>();
jasperPrintList.add(jasperPrint1);
jasperPrintList.add(jasperPrint2);
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList));
Остальные шаги одинаковы:
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("/path/filename.pdf"));
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
exporter.setConfiguration(configuration);
exporter.exportReport();
См. API-интерфейс SimplePdfExporterConfiguration для получения сведений о конфигурации.
Modified text is an extract of the original Stack Overflow Documentation
Лицензировано согласно CC BY-SA 3.0
Не связан с Stack Overflow