supplimentry chinese characters not showing in jasper pdf [duplicate] - java

I am trying to export jasper as pdf but It does not show the cyrillic values. When I export it as excel it does show and the output is fine, but when I try to export is as PDF it does not export the cyrillic values. The cyrillic values are not written in cyrillic font, they are written as cyrillic keyboard.
The code I use to export is:
JRExporter e = new JRPdfExporter();
e.setParameter(JRPdfExporterParameter.JASPER_PRINT, jasperPrint);
e.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, outStream);
e.setParameter(JRPdfExporterParameter.OUTPUT_FILE_NAME, NAME);
I even tried to specift the parameter below:
e.setParameter(JRPdfExporterParameter.CHARACTER_ENCODING, "UTF-8");
but did not succeed. Any suggestions?

Jasper report uses iText and always when a char is not rendered in pdf this should be the checklist:
Is my actual .tff supported (OpenType) and can the font actually render the character. Not all fonts render
all characters in UTF-8, see How can I test if my font is rendered correctly in pdf?
Do I pass correct encoding to iText. In doubts (or in general) use the encoding Identity-H this is recommend for newer PDF standards and gives you the ability to mix different encoding.
Is my font embedded so that if I share the pdf also computers not having this font can display the content?
How can I ensure this is JasperReport?
The deprecated method was to set attributes on the textElement
<textElement>
<font pdfFontName="Helvetica" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
<paragraph lineSpacing="Single"/>
</textElement>
The current non deprecated method v 3-6, is to add Font Extensions and this is easily achieved by using tools like iReport or JasperSoft Studio that can generate a .jar of your font extension so that you can include it in your classpath directly.
How to generate font extension .jar using iReport or JasperSoft Studio.
EDIT: The problem of OP was 1 on checklist (.ttf font could not render), but surely he should consider both 2 and 3 using non deprecated method.

Related

InvalidPDFException when viewing the Chinese content PDF using Primeface DefaultStreamedContent

Using Primefaces 6.0 and
JAVA 1.8
Using below code to view the PDF document using DefaultStreamedContent.
<pe:documentViewer locale="en" height="600" value="#{documentMBean.pdfFile}" id="pdfDocViewer" >
Below code to get the Stream as pdfFile.
byte[] documentData = null;
setPdfFile(new DefaultStreamedContent());
documentData =//Getting the byte array from DB
getPdfFile().setStream(new ByteArrayInputStream(documentData));
getPdfFile().setContentType("application/pdf");
getPdfFile().setContentEncoding("UTF-8");
When I upload and store a PDF file which contents Chineese charactes getting below exception in PDF Viewer.
PDF.js v1.0.21 (build: f954cde) Message: InvalidPDFException
Note: Plain text PDF which contents English characters working fine and able to view the PDF.
I have tried to set different character-encoding such as UTF-8,UTF-16
Please assist me how to resolve above exception. Where I can find PDF.js for further analysis ?

How to display Unicode (Hex) characters in Generated PDF file from ITextRenderer and Thymeleaf HTML tamplate

I am using code to generate PDF file from Thymeleaf HTML template from this website [Convert Thymeleaf to PDF][1].
I am getting very nice PDF but facing one minor issue. I am showing price of products in PDF for multiple currency and using this reference website [currency symbols with Unicode(Hex)][1] to get Unicode (Hex) value for different currency.
Following is my .java file code
context.setVariable("currencySymbol","₹"); // this is Unicode for Indian rupee sysmbol
following is my thymeleaf template code
<td th:utext="${currencySymbol} + ' ' + ${#numbers.formatDecimal(product.price, 0, 'COMMA', 2, 'POINT')}"> </td>
it is working fine and showing currency symbols for all, except Indian Rupee and United Arab Emirates Dirham.
Please suggest me how can I display Indian Rupee and United Arab Emirates Dirham currency Symbols in my Generated PDF.
Thanks in Advance.
**Note :- If is there any new way to generate PDF from HTML Thymeleaf template, please inform me **
The issue is that the font used by default doesn't support the characters you want to print. To make it work, you can embed another font which can display this character, for example DejaVu.
You must first download the DejaVu font file, then declare this font in your java class:
ITextRenderer renderer = new ITextRenderer();
renderer.getFontResolver().addFont("font/dejavu-sans/DEJAVUSANS.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
And use this font in your HTML document, for example with:
td {font-family: DejaVu Sans;}

Keep font when converting DOCX to PDF using Docx4j

Here's a code to convert docx to pdf
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(is);
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setWmlPackage(wordMLPackage);
Docx4J.toPDF(wordMLPackage, baos);
The problem here is that the generated PDF font is always Times New Roman, which is not the case, the docx template font is actually different, Garamond.
What could be missing or wrong here?
If a font is not installed on the system or embedded in the document, MS Word performs a silent font substitution. To check whether this is happening for your document, open it in Word, go to Word Options > Advanced > Show Document Content and press the Font Substitution button. (Word 2007)
If the font is embedded in the document, or you already have the font installed on your system, then I do not know what to tell you because ideally docx4j should use that font.
If that isn't the case, i.e. Word is using font substitution (which you can determine using the steps above), you can embed the Garmond font in the document using Word Options > Save > Embed Fonts in File. Run through your conversion program and check again.

Show an image in a pdf generated from a xsl

I am trying to pass a 64 base image to my xsl via parameters.
based in this question (XSLT show a base64 as a image) I wrote:
<fo:external-graphic src="data:image/png;base64,$sign_2"/>
and any image is output (to a PDF)
I also tried
<fo:external-graphic src="url('data:image/png;base64,$sign_2')"/>
with same results!!! (No image output in my pdf)
Any hint for this ?
TIA,
Yamil

Hindi fonts not appearing properly in pdf when using Dynamic reports [duplicate]

I am using i-report 5.5.0 for jasper reports. I need to export Hindi text into PDF format, but Hindi part is getting converted to ???????.
I have already used font extension but it didn't helped:
font name: "lohit Devanagari" PDF embedded: checked PDF
encoding:Identity-H
I have also tried other Hindi fonts but nothing worked so far..
<textField>
<reportElement x="111" y="26" width="100" height="20" uuid="5a471a16-de7b-4f55-9c9f-b01d37938b9f"/>
<textElement>
<font fontName="Lohit Devanagari" pdfEncoding="Identity-H" isPdfEmbedded="false"/>
</textElement>
<textFieldExpression><![CDATA[$F{DISTRICT_NAME}]]></textFieldExpression>
</textField>
this worked for me
IndicLigaturizer  hindi = new DevanagariLigaturizer();
String result = hindi.process(string);
The correct way to go is using font-extensions. pdfEncoding="Identity-H" is deprecated.
First clear this checklist to render font in pdf:
Is my actual .tff supported (OpenType) and can the font actually render the character. Not all fonts render
all characters in UTF-8
Once you have created correctly font extension and its not working this is probably your problem..
Do I pass correct encoding to iText. In doubts (or in general) use
the encoding Identity-H this is recommend for newer PDF standards
and gives you the ability to mix different encoding.
Identity-H seems ok
Is my font embedded so that if I share the pdf also computers not
having this font can display the content.
Embed your font (otherwise if you make it work on your computer it may
not work on others), note in your jrxml is isPdfEmbedded=false, remove tag and in font-extension select true or set tag to true.
Now just generate the font-extension correctly and add it to your classpath,
How to add font extensions
EDIT: After user passed font
The font Krutidev_011.TTF is not a valid ttf font it maybe because unfortunately the standard according to Apple and the standard according to Microsoft diverged (my guess your font is an apple ttf not an open type ttf).
Caused by: net.sf.jasperreports.engine.JRRuntimeException: java.awt.FontFormatException: java.nio.BufferUnderflowException
at net.sf.jasperreports.engine.fonts.SimpleFontFace.setTtf(SimpleFontFace.java:178)
I tried to download a valid ttf font Lohit Devanagari from the web and add it as font extension, fontName="Lohit Devanagari" this is my result:
It is rendering the fonts but the result may have Ligaturizer problem, for how to solve these see for example Why is the Gujarati-Indian text not rendered correctly using Arial Unicode MS?
If you like to try this is the font-extension I used font extension jar for Lohit Devanagari, remember to set fontName="Lohit Devanagari"
I have same problem I solve it with gargi.ttf font. download here
with this configuration
"gargi" => array(
'R' => "gargi.ttf",
'useOTL' => 0xFF,
),
Jasper Report:- You can use Arial Unicode MS for Hindi and same font jar include in java build path
Jasper Font Arial Unicode MS
Arial unicode jar exported from ireport tool import in STS
Output same as input

Categories