How to display Euro sign in pdf using jasper report? - jasper-reports

I'm using XML to produce a jasper report with Java and Intellij IDE, jasper version is 5.0.4.
On the xml file there is Euro sign € but when the report is created on pdf, I see € instead of €
On the top of xml file I have the following encoding <?xml version="1.0" encoding="UTF-8"?>
And this is how I add Euro symble to the xml:
<textFieldExpression>
<![CDATA["Please send the amount of " + $V{total}.setScale(2, BigDecimal.ROUND_HALF_UP) + " € to the bankaccount ..."]]>
</textFieldExpression>
How does it come and what should I add to the xml file to resolve this problem?

I have changed the jasperreports version from 5.0.4 to 6.17.0 and it solved the issue. In my opinion the reason why it doesn't display the symbol on correct why was that I changed java from 1.7 to 11 but I did not touche the jasperreports version.
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.17.0</version>
<scope>compile</scope>
<dependency>

Related

Apache FOP: The file format is not supported. No ImagePreloader found for

I'm trying to generate PDF using Apache FOP with version 2.7. But unfortunately i got the following error, when i try to insert a jpg image into PDF:
14:43:02.322 [main] ERROR org.apache.fop.apps.FOUserAgent - Image not available. URI: . Reason: org.apache.xmlgraphics.image.loader.ImageException: The file format is not supported. No ImagePreloader found for (No context info available)
org.apache.xmlgraphics.image.loader.ImageException: The file format is not supported. No ImagePreloader found for at org.apache.xmlgraphics.image.loader.ImageManager.preloadImage(ImageManager.java:181)
Here is my added FOP dependency POM.XML:
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>fop</artifactId>
<version>2.7</version>
</dependency>
Thanx a lot in advance!

Replace JasperReport iText 2.1.7 with latest iText 7.0.1

We are using JasperReport 6.1.0 which has a dependency to com.lowagie:itext:jar:2.1.7.js2. It looks like iText 2.1.7 has IP issue, and iText is asking all users to use the latest version which requires a commercial license. So we would like to buy iText license. Now iText latest version is 7.0.1. I tried did below steps to replace JasperReport's iText 2.1.7 with latest iText 7.0.1:
1. Exclude default itext 2.1.7 dependency in pom.xml
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.1.0</version>
<exclusions>
<exclusion>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
</exclusion>
...
2. Add new iText jars in pom.xml
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>barcodes</artifactId>
<version>7.0.1</version>
<!-- barcodes depends on kernel -->
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>font-asian</artifactId>
<version>7.0.1</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>forms</artifactId>
<version>7.0.1</version>
<!-- forms depends on kernel and layout -->
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>hyph</artifactId>
<version>7.0.1</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>io</artifactId>
<version>7.0.1</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>kernel</artifactId>
<version>7.0.1</version>
<!-- kernel depends on io -->
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>layout</artifactId>
<version>7.0.1</version>
<!-- layout depends on kernel -->
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>pdfa</artifactId>
<version>7.0.1</version>
<!-- pdfa depends on kernel -->
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>sign</artifactId>
<version>7.0.1</version>
<!-- sign depends on kernel, layout and forms -->
</dependency>
3. Run mvn and test report function, I got below error:
2016-11-17 14:43:36,520 ERROR [c.i.c.d.DeferredOperationManager] [ Thread-49] Exception on Deferred Operation. Operation UUID: 2a647922-d6d0-450d-9b2d-4d97638ba03f. UI Error key:d9a16093-be20-4278-9f8b-93120c0a2231 - Error: java.lang.NoClassDefFoundError: com/lowagie/text/SplitCharacter
It looks like JasperReport is trying to find old iText classes which namespace is "com.lowagie...".
I tried to unzip the new iText 7.0.1 jar, the classes are in package "com.itextpdf...".
How can I make the JasperReport call the new iText jar?
You can not replace iText 2.1.7 with iText 7 because the differences between the two versions are too big. We do know of some people who moved to using iText 5 with JasperReports. That requires a number of changes to JasperReports such as changing the package names from com.lowagie to com.itextpdf (*) and changing references to com.lowagie.text.Color to com.itextpdf.text.BaseColor.
At iText, we noticed that we were hitting the ceiling with iText 5. For instance: we store text using char which means that each character is stored using only 2 bytes. That wasn't sufficient if we wanted to support Hindi. We had to rewrite the complete font layer if we wanted to add support for Indic languages to iText. "Replacing the font layer" in iText 5 would have been really difficult since the font layer is the foundation on which all the rest of the code is built. Hence our decision to rewrite the complete API.
You can watch a video that goes into more detail regarding this decision here: Devoxx 2016: "Oops I broke my API"
However: the biggest problem with replacing iText 2.1.7 with iText 7, is that JasperReports depends on PdfGraphics2D and we haven't ported that part to iText 7 (yet). We might even decide not to port that part ever, because it is impossible to create PDF/UA if you choose to use PdfGraphics2D (and PDF/UA is getting more and more important).
(*) In 2009, I decided to remove my name from the package names. When I first released iText, I only owned the lowagie.com domain, and I used com.lowagie packages for all the Java code I wrote. I didn't expect iText to become such a success. When everyone started to use iText, everyone started to ask me questions personally. I didn't have a life anymore. Hence I created a company, we professionalized iText and replacing com.lowagie with the more neutral com.itextpdf was one of those professionalizations.

xml file issue while importing my source code into My Eclipse Blue 2014

I was using RAD and WAS to run my ear application. Now I am migrating RAD to Eclipse Blue and facing a compilation error as:
Referenced file contains errors (file:/C:/DEVTOOLS/MyEclipseBlue2014/configuration/org.eclipse.osgi/bundles/1128/1/.cp/dtds/loose.dtd).
For more information, right click on the message in the Problems View and select "Show Details..."
My XML file is as :
<?xml version="1.0" encoding="UTF-8"?>
<application-bnd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://websphere.ibm.com/xml/ns/javaee"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-application-bnd_1_0.xsd" version="1.0">
<security-role name="ValidUser">
<special-subject type="ALL_AUTHENTICATED_USERS"/>
</security-role>
Could any one of you help me to figure the cause for this error and how can I resolve it?

javax.xml.bind.JAXBException while generating word document from XHTML in cq5

I am trying to convert HTML> XHTML to word document, using docx4j library. While hitting the servlet I get this exception.
I have converted docx4j jar to OSGi bundle and in my classpath 1.7.0_21 is set.
java.lang.RuntimeException: javax.xml.bind.JAXBException: JAXB: neither Reference Implementation nor Java 6 implementation present?
at org.docx4j.XmlUtils.marshaltoString(XmlUtils.java:546)
at org.docx4j.XmlUtils.marshaltoString(XmlUtils.java:478)
at org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart.createVirtualStylesForDocDefaults(StyleDefinitionsPart.java:330)
at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.getStyleTree(MainDocumentPart.java:172)
at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.getStyleTree(MainDocumentPart.java:161)
at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.stylesToCSS(XHTMLImporterImpl.java:424)
at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.getRenderer(XHTMLImporterImpl.java:218)
at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.convert(XHTMLImporterImpl.java:620)
It reports JRE 1.7 only:
java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)
This issue is now resolved, we had to deploy two more bundles( org.apache.servicemix.bundles.ant-1.7.0 and JAXB).
This might help others !
Thanks
I had the very same issue regarding the exception, and what helped me was to introduce following into my pom.xml
<dependency>
<groupId>com.googlecode.jaxb-namespaceprefixmapper-interfaces</groupId>
<artifactId>JAXBNamespacePrefixMapper</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.2</version>
</dependency>

DynamicJasper and Asian characters

My PDF generated by DynamicJasper now looking exactly as it's supposed to, I am facing only one more problem: Asian characters are not displayed at all in the resulting PDF. Any other characters work fine. I can verify in the debugger that the Strings are properly placed in the JRDataSource, and Jasper does in fact generate lines for them in the report, but the text itself is completely missing.
Are there some additional encoding settings to be considered when using DynamicJasper with Asian text elements?
Thanks for any advice and best regards
Okay, so this is what fixed the issue, step by step:
1.) Add the Arial Unicode MS font extension JAR to your classpath (or any other equivalent unicode font). An "official" one can be found here, I ended up using this one, however. If you're using maven, you can use the following mvn command line and POM entry to add the file to your classpath:
mvn install:install-file -Dfile=DynamicJasper-arial-unicode-fonts-1.0.jar -DgroupId=ar.com.fdvs -DartifactId=DynamicJasper-arial-unicode-fonts -Dversion=1.0 -Dpackaging=jar
<dependency>
<groupId>ar.com.fdvs</groupId>
<artifactId>DynamicJasper-arial-unicode-fonts</artifactId>
<version>1.0</version>
</dependency>
2.) Add, if not already present, spring-core and spring-beans to the project:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.2.2.RELEASE</version>
</dependency>
3.) Enable "Identity-H" Jasper PDF encoding:
static {
JRProperties.setProperty("net.sf.jasperreports.default.pdf.encoding", "Identity-H");
}
4.) Configure Arial Unicode MS as your DynamicJasper font (e.g. for rows):
// ...
final DynamicReportBuilder dynamicReportBuilder = new DynamicReportBuilder();
final Style style = new Style();
style.setFont(new Font(Font.MEDIUM, "Arial Unicode MS", false));
dynamicReportBuilder.setDefaultStyles(null, null, null, style);
// ...
That was some annoying crap :-/ ...
you may have to configure jasper report exporter to embed special fonts on the pdf file. also check ck the pdf character encoding