jasper-reports
Exportar a pdf
Buscar..
Observaciones
Para representar correctamente las fuentes en pdf, siempre se deben usar extensiones de fuentes (en classpath)
Con IDE (entorno de desarrollo integrado).
JasperSoft Studio
En Vista previa, ejecute el informe haciendo clic en la flecha verde, si no hay errores, se habilitará el menú de exportación, haga clic en el botón de exportación (imagen de disco) y seleccione "Exportar como PDF"
Con java
Para exportar una, debe completar el informe para obtener el objeto JasperPrint .
Exportar JasperPrint único (solo jrxml) al archivo
// 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();
Exportar múltiples JasperPrint's (multiple jrxml) a un solo archivo
Solo los primeros pasos difieren del conjunto anterior:
List<JasperPrint> jasperPrintList = new ArrayList<>();
jasperPrintList.add(jasperPrint1);
jasperPrintList.add(jasperPrint2);
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList));
Los pasos restantes son los mismos:
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("/path/filename.pdf"));
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
exporter.setConfiguration(configuration);
exporter.exportReport();
Ver SimplePdfExporterConfiguration API para detalles de configuración.
Modified text is an extract of the original Stack Overflow Documentation
Licenciado bajo CC BY-SA 3.0
No afiliado a Stack Overflow