-
Notifications
You must be signed in to change notification settings - Fork 14
PDFReporter API
The single point of entry into the PDFReporter library for desktop and Android is the class
org.oss.pdfreporter.PdfReporter
getExporter(DESIGN_REPORT_JSON_CUSTOMERS, "jsondatasource","extra-fonts")
.addSubreport("JsonOrdersReport", "JsonOrdersReport.jasper")
.addJSONParams("yyyy-MM-dd", "#,##0.##", Locale.ENGLISH, Locale.US)
.setJsonSource()
.exportPdf();
getExporter(DESIGN_REPORT_HORIZONTALLIST, "list", "extra-fonts")
.setSqlSource(testProvider.databasePath(), SQL_USERNAME, SQL_PASSWORD)
.exportPdf();
getExporter(DESIGN_REPORT_CDBOOCKLET, "cdbooklet","extra-fonts")
.setXmlSource(XML_DATA_CDBOOKLET, XPATH_DATA_CDBOOKLET)
.exportPdf();
getExporter(DESIGN_REPORT_CUSTOMERS, "xmldatasource","extra-fonts")
.setXmlSource(XML_DATA_NORTHWIND, XPATH_DATA_NORTHWIND_CUSTOMERS)
.addSubReportXMLDocument(XML_DATA_NORTHWIND)
.addXMLParams("yyyy-MM-dd", "#,##0.##", Locale.ENGLISH, Locale.US)
.exportPdf();
getExporter(DESIGN_REPORT_I18N, "i18n")
.addFillParameter("number", new Double(1234567 + Math.random()))
.newResourceBundle("test.org.oss.pdfreporter.resourcebundle.i18n", locale)
.exportPdf();
getExporter(DESIGN_REPORT_PDFCRYPT, "misc", null)
.addEncryption(true, "pdfreporter", "reports", IDocument.PERMISSION_COPY | IDocument.PERMISSION_PRINT)
.exportPdf();
PdfReporter getExporter(String jrxml, String reportFolder, String extraFolder) {
RepositoryManager repo = PdfReporter.getRepositoryManager();
repo.reset();
repo.setDefaultResourceFolder(resourceFolder);
repo.setDefaulReportFolder(rootFolder + RepositoryManager.PATH_DELIMITER + "jrxml" + RepositoryManager.PATH_DELIMITER + reportFolder);
if (null != extraFolder) {
repo.addExtraReportFolder(resourceFolder + RepositoryManager.PATH_DELIMITER + extraFolder);
}
repo.addExtraReportFolder(resourceFolder);
return new PdfReporter(jrxmlPath, getOuputPdfFolder(), getFilenameFromJrxml(jrxmlPath));
}
PdfReporter getExporter(String jrxml, String reportFolder, String extraFolder) {
RepositoryManager repo = RepositoryManager.getInstance();
repo.setDefaultResourceFolder(inputPath(JRXML_RESOURCE_FOLDER));
repo.setDefaulReportFolder(
inputPath(JRXML_REPORT_FOLDER + RepositoryManager.PATH_DELIMITER + reportFolder));
if (null != extraFolder) {
repo.addExtraReportFolder(
inputPath(JRXML_REPORT_FOLDER + RepositoryManager.PATH_DELIMITER + extraFolder));
}
repo.addExtraReportFolder(inputPath(XML_DATASOURCE_FOLDER));
return new PdfReporter(jrxml, outputPath(PDF_OUTPUT_FOLDER), getFilenameFromJrxml(jrxml));
}
DefaultIRegistryExtensionsRegistryFactory
is the registry for implementations that can be substituted based on platform and and even if another for example another xml library for parsing should be used. Here the implementation of such a class:
public class DefaultIRegistryExtensionsRegistryFactory implements ExtensionsRegistryFactory {
private final static Logger logger =
Logger.getLogger(DefaultIRegistryExtensionsRegistryFactory.class.getName());
private static boolean isInitialized = false;
@Override
public ExtensionsRegistry createRegistry(String registryId,
JRPropertiesMap properties) {
initializeIRegistry();
return new NullExtensionsRegistry();
}
private static class NullExtensionsRegistry implements ExtensionsRegistry {
@Override
public <T> List<T> getExtensions(Class<T> extensionType) {
return null;
}
}
synchronized private void initializeIRegistry() {
if (!isInitialized) {
Logger.getLogger("").setLevel(Level.FINEST);
XmlParserFactory.registerFactory();
NetFactory.registerFactory();
SimpleFormatFactory.registerFactory();
DefaultFormatFactory.registerFactory();
FallbackFormatFactory.registerFactory();
JsonDataSourceFactory.registerFactory();
BeansFactory.registerFactory();
FontFactory.registerFactory();
ImageFactory.registerFactory();
GeometryFactory.registerFactory();
PdfFactory.registerFactory();
isInitialized = true;
logger.info("Initialized IRegistry");
}
}
}
All properties should be provided in a folder so that the PDFReporter library will find them.
All default settings that comes with a typical installation. You will find examples at the project pdfreporter-testdata or at our connector for bonitasoft.
Basically any extension like the configuration class from above and any font that need to be shipped with the app.
Create a ReporterConfiguration object then call setSqlSource or setXmlSource. Optionally call addExportParameterValue, addSubreport or addEncryption then call PDFReporter.exportPdf(reporterConfiguration). The code snipets below show how the ReporterConfiguration is used to call the ReportExporter directly.
[ReportExporter exportReportToPdf:_reporterConfiguration.outputPdfFilePath
withJrxml:_reporterConfiguration.jrxmlFileName withResourceFolders:_reporterConfiguration.resourceFolders
withXml:_reporterConfiguration.dataSourceFileName
andXPath:_reporterConfiguration.selectExpression
withParameters:_reporterConfiguration.exportParameters
withSubreports:_reporterConfiguration.subreportsDefinition];
[ReportExporter exportReportToPdf:_reporterConfiguration.outputPdfFilePath
withJrxml:_reporterConfiguration.jrxmlFileName
withResourceFolders:_reporterConfiguration.resourceFolders
andSqlite3:_reporterConfiguration.dataSourceFileName
withParameters:_reporterConfiguration.exportParameters
withSubreports:_reporterConfiguration.subreportsDefinition];
[ReportExporter exportReportToPdf:_reporterConfiguration.outputPdfFilePath
withJrxml:_reporterConfiguration.jrxmlFileName
withResourceFolders:_reporterConfiguration.resourceFolders
withParameters:_reporterConfiguration.exportParameters
withSubreports:_reporterConfiguration.subreportsDefinition];
(coming soon)