Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load ICC profile from classpath?

While trying to generate PDF that conforms to PDF/A standard using Jasper Reports, I got

net.sf.jasperreports.engine.util.JRPdfaIccProfileNotFoundException. 

This is easily fixed by configuring

<property name="net.sf.jasperreports.export.pdfa.icc.profile.path" value="/stuff/myicc.icc"/>

but I need to bundle the icc profile with rest of the WAR just like the fonts the report embeds. How can this be done? I'm looking something like

<property name="net.sf.jasperreports.export.pdfa.icc.profile.path" value="classpath:/jasper/someicc.icc"/>

But this did not work, nor did icc profile relative to the report itself. Can I pass the InputStream as a parameter to the PDFGenerator?

like image 819
user2644922 Avatar asked Feb 01 '26 06:02

user2644922


1 Answers

If you are exporting from java code you can use the getClassLoader().getResource() to get the absolute path to file.

Example with JRPdfExporter

JRPdfExporter exporter = new JRPdfExporter();
//... your input and output
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
URL path = this.getClass().getClassLoader().getResource("jasper/someicc.icc");
configuration.setIccProfilePath(path.getFile());
//other settings
exporter.setConfiguration(configuration);
exporter.exportReport();
like image 185
Petter Friberg Avatar answered Feb 02 '26 22:02

Petter Friberg