Import custom font in jasper - java

I'm developing an aplication that generates a PDF using Jasper. To do this I have a custom font that I generate in Jasper but the problem is I can't put this working. Every time that I try to generate the document gives me the following error:
Caused by: net.sf.jasperreports.engine.util.JRFontNotFoundException: Font "reportFonts" is not available to the JVM. See the Javadoc for more details.
I'm on IntelliJ and I already setup the font jar in the project path like the this
And the library looks like this
What am I missing here?
Thanks

Related

Font extensions does not work for JasperReports

I am trying to add Tahoma font to jasper report in my web app. I use font extension mechanism.
This exception was thrown:
net.sf.jasperreports.engine.util.JRFontNotFoundException: Font 'TahomaFont' is not available to the JVM. See the Javadoc for more details.
Here is my font.xml file:
<fontFamiles>
<fontFamily name="TahomaFont">
<normal>export/fonts/BTahoma.ttf</normal>
<pdfEncoding>Identity-H</pdfEncoding>
<pdfEmbedded>true</pdfEmbedded>
</fontFamily>
<fontFamiles>
and here is my jasperreports.properties file :
net.sf.jasperreports.extension.registry.factory.simple.font.families=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.TahomaFont=export/fonts/fonts.xml
Also i have put Tahoma.ttf font file in my classpath.
Here is the style tag in jasper report:
<style fontName="TahomaFont" name="tahoma"/>
Please let me know where i am going wrong. Thanks in advance.
Putting the Tahoma.ttf font in your class path is not the way to go.
You are right to use font extensions, it's a good practice - but you need to package your fonts as font extension, into a jar and add that jar to your classpath.
In jasperReport, manage your fonts, in options, in the Font tab, select the font and click export as extension.
Package your jar and things should work fine without having to install the physical font on the JVM.
More information documented here.
maybe you have to copy your jar file to your java_home/fonts directory. and if you are usinng maven project you have to package your jar file within a maven project with pom properties to add dependency to pom.xml
You put "Tahoma.ttf" font file in classpath, but declare "BTahoma.ttf" in fonts.xml
<normal>export/fonts/BTahoma.ttf</normal>
Let's change them to the same.
I think that exception will be disappea.

NoClassDefFoundError: com/itextpdf/text/DocumentException when exporting jasper to pdf

I created a jasper report and now I need to export that report to pdf format. This is my code for that.
// compiles jrxml
JasperCompileManager.compileReportToFile(reportName + ".jrxml");
// fills compiled report with parameters and a connection
JasperPrint print = JasperFillManager.fillReport(reportName + ".jasper", parameters, connection);
// to view the report
//JasperViewer.viewReport(print, false);
// export repor to pdf
JasperExportManager.exportReportToPdfFile(print, "fromXml.pdf");
When I view the report using JasperViewer, it works fine. But When I exporting the report into pdf format, it gives me the following exception.
Exception in thread "main" java.lang.NoClassDefFoundError: com/itextpdf/text/DocumentException
But I have put the iText jar into my libraries.
But one thing, I had another version of iText jar before. It gave me the same exception. I thought that there may be some issues with the version of it.(I followed a tutorial, so I added the same jar as they had used in the tutorial replacing the new jar I had used).
but still the problem remains. I thought this may be the issue now(the accepted answer of the question). But I do not know how to fix it. I removed the entire library and added it again with iText jar which had been used by the tutorial. But I had no luck.
Could you please help me to overcome this issue.
Thank you!
You need to upgrade your iText-2.1.7.jar file to latest version as earlier the package that was used by jar is com.lowagie...
See the change list here which says it has changed the package name.

Could not load the following font

I have a problem that have been already asked, but there are some specific differences in my case.
I'm supporting a web application (EJB 2, PostgreSQL 9.2.4, running on a JBoss 4.2.3) that have an issue.
Sometimes, when we try to generate a specific report, we get this error:
javax.servlet.ServletException: net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font :
pdfFontName : DejaVu Sans
pdfEncoding : Cp1252
isPdfEmbedded : false
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
stirq.scan.util.NoCacheFilter.doFilter(NoCacheFilter.java:38)
jcifs.http.NtlmHttpFilter.doFilter(NtlmHttpFilter.java:118)
stirq.scan.util.TimeoutFilter.doFilter(TimeoutFilter.java:57)
stirq.scan.util.SecurityFilter.doFilter(SecurityFilter.java:82)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
I searched in many sites.
http://community.jaspersoft.com/questions/525505/could-not-load-following-font
Could not load the following font issue in iReport
JasperReports - font extensions does not work - can't find font while exporting to PDF
(And others)
As suggested in many answers, I am using font extension jar but still got the issue.
There are two fields of a table in the application's database that can contains html code.
I found that the bug occurs when there is a "font" tag in one of those two fields or the two.
Even if the specified font in this "font" tag is Arial the message I got is still concerning the font DejaVu Sans.
Every textfield of all my jrxml files are in font DejaVu Sans.
When I tested the preview mode of my report in IReport 4.1.1 every thing was fine.
I deleted every "font" tags of the two database fields containing HTML code for an occurrence that got the issue and it worked.
But the application is in production.
As you can see I can't delete every "font" tags in the database.
Any help would be appreciated.
Thanks.
In iReport if you set up a repository for your JasperServer you will be able to get the effective production version of a report xml into iReport. Then you can edit your file and replace by the edited version production one.
try setting up these system properties:
import net.sf.jasperreports.engine.util.JRProperties;
JRProperties.setProperty("net.sf.jasperreports.default.pdf.font.name", "Helvetica")
JRProperties.setProperty("net.sf.jasperreports.default.pdf.encoding", "UTF-8")
JRProperties.setProperty("net.sf.jasperreports.default.pdf.embedded", "false")
see here for more: http://www.77dev.com/2014/07/could-not-load-following-font-solved.html
Copy the fonts files (*.ttf) into the folder:
/path/to/app/WEB-INF/classes/
You app will get the fonts from here :)

Issues with embedding PDF in pptx using docx4j

I have to attach a pdf file in a pptx slide during runtime.
Tried the following:
Attached a pdf file in the pptx slide (Insert -> Object -> Adobe Acrobat Document).
Accessed the oleobject using the following code :
OleObjectBinaryPart oleObjectBinaryPart = new OleObjectBinaryPart(new PartName("/ppt/embeddings/oleObject1.bin"));
Updating the oleObjectBinaryPart using the following code:
oleObjectBinaryPart.setBinaryData(reportBlob.getBinaryStream());
Updating the pptx with the new oleobject:
pptMlPackage.getParts().getParts().put(new PartName("/ppt/embeddings/oleObject1.bin"), oleObjectBinaryPart);
pptMlPackage.save(new File("C:/test_report/pptx_out.pptx"));
After executing this code the pptx_out.pptx file got generated without any errors. But while trying to open the embedded pdf in powerpoint 2010 I'm getting following error:
The server application, source file, or item can't be found, or returned an unknown error. You may need to reinstall the sever application.
Is it a problem with the oleobject when updating?
You can't just attach the PDF as a binary blob; it has to be in the correct OLE format.
See further this discussion.

Specifying a base or default font with PDFBox

Is there a system property or other parameter that can be passed to PDFBox when attempting to convert from a PDF document into an Image? I am utilizing the provided PDF2Image class like so:
String[] args = new String[]{"-imageType", "jpg", "myfile.pdf"};
org.apache.pdfbox.PDFToImage.main(args);
It works great on Windows and fails with this warning on Ubuntu:
[org.apache.pdfbox.util.PDFStreamEngine] java.lang.NullPointerException java.lang.NullPointerException at org.apache.pdfbox.pdmodel.font.PDType1Font.getawtFont(PDType1Font.java:261)
I assume from my research that this is a problem with a "missing" font, but I've found very little help so far using google and the projects website.
I've tried both versions 1.7.1 and 1.8.2 of PDFBox.
Similar question here: setting ttf for PDF to Image on PDFbox

Categories

Resources