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
Related
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
I am using Jaspersoft Studio final version (v6.1.1). I have designed my report and it contains Turkish characters. When exporting the report from Studio as PDF Turkish characters are not shown although I've set the Studio workspace encoding to UTF-8. Also I have embed the jrxml report file in my JSF app and export the report, the result is the same.
Do I have to configure something more?
I was able to solve the problem. In the Jaspersoft Studio IDE, change encoding to UTF-8 in Window/Prefrences/General/Workspace. Afterwards click any field, parameter, or text in the IDE and from the Properties/Advanced menu select PDF/PDF Encoding. I hope it will help.
I think i have found an easier and more general solution. Instead of changing encoding of every field, you can do it using java coding from your web application`s controller. Below is my solution, i hope it helps a bit. Just put the font to your webapp folder. And change the encoding programatically. BTW greetings from turkey :)
JRDesignStyle jrDesignStyle = new JRDesignStyle();
/*Set the Encoding to UTF-8 for pdf and embed font to arial*/
jrDesignStyle.setDefault(true);
String fontPath = req.getSession().getServletContext().getRealPath("/jasper/arial.ttf");
jrDesignStyle.setPdfFontName(fontPath);
jrDesignStyle.setPdfEncoding("Identity-H");
jrDesignStyle.setPdfEmbedded(true);
jasperPrint.addStyle(jrDesignStyle);
JRPdfExporter exporter = new JRPdfExporter();
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.
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 :)
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.