acostache Posted July 1, 2010 Share Posted July 1, 2010 Hi, I am trying to fill a report and export it as a pdf and within the report, I have some elements that use certain fonts, using the "fontName" property, fonts which are not available to my OS. Therefore, I package the font/fonts using iReport to export as a font extension. That font extension is placed in a location which I try to make available to my application using the REPORT_CLASS_LOADER, with a code as follows (FYI, the font is called 'Corbel'): ClassLoader cl = new URLClassLoader( new URL[] {new URL("file:///D:/path/to/Corbel_jar_folder/")} );param = new HashMap();param.put(JRParameter.REPORT_CLASS_LOADER, cl);jasperReport = JasperCompileManager.compileReport("d:/path/to/Report_with_Corbel_font.jrxml");jasperPrint = JasperFillManager.fillReport(jasperReport, param, new JREmptyDataSource()); Then after filling, which seems to go on without errors (no error saying that the font is not available to my JVM), when I export this is a pdf (via JRPdfExporter), the pdf does not show up as using my requested font, i.e. the part of the report, that should use that font, does not use it.What's even more strange is that, if I place just the .TTF file in the location indicated above as "D:/path/to/Corbel_jar_folder", I get the error with the font not being available to the JVM.I am using JasperReports 3.7.1 and also the font extension I mentioned earlier has been exported via iReport 3.7.1. I have been reading all posts I could find on this topic of "fonts" and I have used the code indicated in previous posts. I am attaching the report also, in case it is needed. Any help on this would be greatly appreciated. Best regards,Andrei Link to comment Share on other sites More sharing options...
indhira Posted July 1, 2010 Share Posted July 1, 2010 Hi Andrei, I understood from the attached jrxml that u have used different fonts for each text component. But the pdf font which u have chosed is Helvitica. So if u export the jrml to pdf and view it in acrobat reader the font will be helvitica and not the one specified by u. But u can see the fonts specified by u by viewing the jrxml in reports viewer. Regards,Indhira P Link to comment Share on other sites More sharing options...
acostache Posted July 1, 2010 Author Share Posted July 1, 2010 Thank you for your reply!Indeed, when I export to pdf, my chosen/specified font ('Corbel') is not rendered on the pdf, when viewing it with, for instance, Acrobat Reader. But, in the internal iReport viewer it shows up ok.And I am not sure how to make Jasper aware of my extensions, from within my application, other than the ideas I have tried (without success) as REPORT_CLASS_LOADER (and also setting the JRExporterParameter.CLASS_LOADER to a class loader, as was an idea on a previous post) or setting the "net.sf.jasperreports.export.pdf.fontdir.jasper" property to the absolute path of my font extension/resource directory.Not sure what else to try/do. Regards,Andrei Link to comment Share on other sites More sharing options...
lucianc Posted July 2, 2010 Share Posted July 2, 2010 JasperReports extension jars are resolved from the thread context classloader, and not from REPORT_CLASS_LOADER or JRExporterParameter.CLASS_LOADER. So what you need to do is Thread.currentThread().setContextClassLoader(cl) (and revert to the original thread classloader when JR is done).You can also log an enhancement request to consider REPORT_CLASS_LOADER and JRExporterParameter.CLASS_LOADER when looking for extensions.Regards,Lucian Link to comment Share on other sites More sharing options...
acostache Posted July 2, 2010 Author Share Posted July 2, 2010 Hi Lucian, Great! Thank you for the reply and the explanation. I will try that! Regards,Andrei Link to comment Share on other sites More sharing options...
acostache Posted July 5, 2010 Author Share Posted July 5, 2010 Lucian, Thank you for the explanation: indeed the context classloaders' switch solved our problem. Best regards,Andrei Link to comment Share on other sites More sharing options...
C-Box Posted May 6, 2011 Share Posted May 6, 2011 Hi Lucian,I'm currently (re)implementing the font support to our ERP-System and try to use the font-extenion logic as well.We work in J2EE environment (JBoss) and switching the context-classloader is not a good idea. (and also doesn't work)As we need individual fonts at server (while filling) and client side (for viewing/printing) I do store the font-extensions as jar-files in database. So I wrote a "FontsClassLoader" ( already some years ago - initially for loading ttf's to PDF-Exporter -> now for font-extension as jar/zip) that loads that font (extension) from database when needed (and caches of course).But as expected my FontsClassLoader is not used for checking fonts, as the JRFontUtil doesn't use any specific classloader.As the font's could change at runtime (e.g. when user change/redesign templates) it must be dynamically - so just putting the font (extension) to classpath would cause an server-restart. Also deploying to clients classpath would be difficult - that's why I need the FontsClassLoader.Is there any workaround to get the font-extension loaded from database instead just from classpath?(I'm using still 3.7.6) regards from sunny GermanyChristian Link to comment Share on other sites More sharing options...
diogopaludo Posted July 26, 2012 Share Posted July 26, 2012 Hi CBox,I'm currently developing a Report Service that receives requests from different systems, compiles, fills and returns the reports in the file format wanted. The service is running fine, compiling all kinds of reports, but the fonts are a problem. I work at a University and some reports serve as certificates, with different lettering and styles, so fonts are unusual and not present in JVM or in the OS.I tried to export the fonts from iReport 4.5.1 as font-extensions and put them on my classpath, also trying to change the ClassLoader of the Thread as seen in this topic, but it didn't work.I'd appreciate any help that you can give me and I thank you in advance.Diogo Link to comment Share on other sites More sharing options...
C-Box Posted July 26, 2012 Share Posted July 26, 2012 Hi,I implemented my own "AfpsDruckFontExtensionRegistry" that implements the ExtensionsRegistry interface and also "AfpsDruckFontExtensionsRegistryFactory" that implements the ExtensionsRegistryFactory interface JasperReports provides.So these two classes (and some other) helps me to load the fonts dynamically from database at runtime without a server restart. To let the JasperReports enginge know that I use my own FontExtensionRegistry I set a property: net.sf.jasperreports.extension.registry.factory.fonts=de.ibees.jasperreports.extensions.fonts.AfpsDruckFontExtensionsRegistryFactoryAs for performance reason I hold all fonts within a Map<String, InputStream> in my AfpsDruckFontExtensionRegistry to not load the ttf everytime from database when something is printed. (the tffs are sometimes quite big)The clients lookup to the server cache and loads the fonts if there has been changed any of them (so if one font is deleted/moved/added) so that the server uses my "AfpsDruckFontExtensionRegistry" when filling and the client also use it for viewing/printing.Works fine for now more than one year. So in detail I don't know how it works exactly but you shoud have a point how to start. :-)hthC-Box Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now