Unicode characters in Jasper Report [duplicate] - internationalization

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

Can anyone share a chinese supported pdf template sample

Is there anything we need to change on pdf template level to support Chinese or Japanese . I am using a fillable template. While writing it with my pdf library(using tcpdf) it is giving some garbled text. While copy pasting Chinese text to this template field also gives some squares where as English is filling perfectly. Does anyone out there have a sample fillable pdf template that supports Chinese to share?
generally you need to embed font to properly display foreign characters in a PDF. I've not tried using tcpdf but saw posts that say embedding a TTF (true type font) of the correct language seems to do the trick.

Cyrillic and GhostScript

I am struggling to convert my PCL file to PDF using GhostScript. The conversion itself is not issue, but it appears that Cyrillic is problem. As you can see on attached picture, it considers only the colon and period symbol.
I tried different fonts and symbol sets, but I never got correct result.
I was also trying to convert cyrillic TTF to soft font via PCL Paraphernalia but I was not successfull with using the font in my PCL.
Using following command:
gpcl6win64.exe -dNOPAUSE -sDEVICE=pdfwrite -dNOCACHE -dRENDERTTNOTDEF -sOutputFile=output.pdf CYR.prn
My file:
PDF output:
Please advise.
Thank you
At a guess, you have not supplied the font, or the font you are using does not contain Cyrillic glyphs. Colon and period are obviously going to be present in any Latin font, Cyrillic glyphs generally are not. Any glyphs not present in the font will be replaced by the /.notdef glyph, which is usually a non-marking glyph (except for TrueType fonts where it's usually a hollow square).
If that's your entire PCL file then I can't say I'm surprised it doesn't work as you expect, you haven't downloaded a font. I don't know PCL well enough to say exactly what that minimal file is doing but here's a thought: try using gpclwin64 to render the PCL to the display. If that doesn't work then there's no way it's going to result in a PDF file which works.
Basically you're going to have to download a soft font containing the glyphs you want to use encoded at the character codes you want to use.
NB: I'd strongly advise against using -dNOCACHE because that will hurt performance on large text-heavy files.

Italic and bold Latin, and Greek letters using custom unicode font in gnuplot to produce (e)ps or pdf

I would like to create a postscript or pdf figure with enhanced notations, italic or bold Latin characters, and sometimes (regular) Greek characters. How to do that in general?
Let's say I downloaded CMU Sans Serif, a font that has glyphs for all the strange characters I ever want to use. I converted them to pfa with an online tool and copied the files to the path of working directory.
Expectations
Let's say I'd like to produce the following notation somewhere.
What I tried: original
I create a gnuplot script encoded in a utf-8 file (without BOM) with the content
set term postscript eps enhanced "CMUSansSerif" 15 fontfile add 'CMUSansSerif.pfa' fontfile add 'CMUSansSerif-Oblique.pfa' fontfile add 'CMUSansSerif-Bold.pfa'
set encoding utf8
set o "print.eps"
p x t "Label: {/CMUSansSerif-Bold important }{/CMUSansSerif-Oblique note}: ∫⟨α₂ + β²⟩ = äßű"
set o
and executed with the newest gnuplot, version 5.2.6.
What I got
I used a vector graphics editor to open the eps file and relevant part looks like this:
What I also tried
According to Ethan's answer I added adobeglyphnames to the termoptions. It made at least the letters available but other Unicode symbols are still unavailable. The result is:
Question
What went wrong? How could I produce the desired output?
So many possibilities, where things can go wrong: Is the font not suitable for this task? Did I download a wrong version of it? Did the pfa converter do a bad job? Did I include the font files incorrectly? Was there something wrong with the set encoding? Do I use a bad vector graphics editor? Do I have wrong fonts installed and the vector graphics editor tries to use them?
I am afraid that the answer is that in general PostScript is the wrong tool for this. If it is at all possible for you to work with PDF output instead, I suggest you do that. It is even possible the resulting PDF file can be translated to a PostScript file by standard tools (e.g. pdf2ps). That is likely to work if the non-ascii characters are limited to Greek and other relatively common symbols but I don't know how much of the full unicode tables are covered by those standard tools.
If you really need to produce PostScript with additional unicode characters directly from gnuplot, you can find full instructions and sample character encoding tables in the gnuplot distribution files:
.../term/PostScript/unicode_maps.README
.../term/PostScript/unicode_big.map
.../term/PostScript/unicode_small.map
I am not familiar with the online tool font conversion you used but probably it failed because it did not have, or at any rate did not use, suitable character encoding tables for the desired conversion.
===
One other thought. There are two ways that a *.pfa font can encode unicode characters that are common enough to have a name assigned by Adobe for use in PostScript. (1) It may use generic names like uni0439 for Unicode code points. (2) It may use Adobe-specific names from the list here:
agl-aglfn glyph list
When selecting PostScript output from gnuplot you can tell it which of these two conventions is used by the font you provide. The default is "noadobeglyphnames".
set term postscript {no}adobeglyphnames
==
(recipe for using "set term pdfcairo")
Font handling is unfortunately system-specific, so I cannot tell you how to install or configure fonts on all your target machines. I will show you a procedure that works on a linux desktop that uses the fontconfig utilities for system font handling.
Create directory /home/share/fonts/CMUSans
Add this directory to the search list in file /etc/fonts/local.conf
Copy *.ttf files into this directory from the CMU Sans Serif zip archive you link to in your original query. The system fontconfig system tools should now be able to find these fonts. By inspection they self-report as "CMU Sans Serif"
in gnuplot (tested with version 5.2.6)
set term pdfcairo font "CMU Sans Serif,15"
set output 'enhanced_utf8.pdf'
load 'enhanced_utf8.dem'
convert output pdf file to PostScript with the following command
pdf2ps enhanced_utf8.pdf enhanced_utf8.ps
Screenshot of the result is shown below
It seems that CMU Sans Serif doesn't contain the UTF-8 characters you are asking for. Check the font with a font editor like Birdfont. Although the webpage shows symbols you want to use, the font itself does not contain them. However, your browser may show symbols, but they are just fallback representations from other fonts.

How to use French Accented Characters in PDFLib 7?

I am using PDFLib 7 to generate mailing labels. I am having issues displaying French accented characters. For example, Maître Corbeau is displayed as Maître Corbeau. Similarly, SadÖ is displayed as SADÃ.
The simplified code that I am using is like this:
$pdfDoc = new PDFlib();
$pdfDoc->set_info("Creator", "Kits Communications");
// more document info settings
$pdfDoc->begin_page_ext($PageWidth, $PageHeight, "");
$font = $pdfDoc->load_font("Helvetica", "auto", "");
$pdfDoc->setfont($font, 9.0);
// get data in variables
$pdfDoc->show(strtoupper($NameLine1));
$pdfDoc->continue_text($AddressLine1);
If I display the contents on the page with echo, the string is displayed correctly. I believe that perhaps I need to define default character set to PDFLib. Could someone please advise the required command to be used for PDFLib 7?
The text I was writing into a PDFLib document is in UTF-8 format. If I send the text in ANSI format, the mailing labels appear correctly. I added the following command to convert text to the ANSI format.
$NameLine1 = iconv("UTF-8", "Windows-1252",$NameLine1);
This fixed the issue on Windows PC. Not tested on Mac.

Magento - strange characters in invoice PDF

Getting a strange character appearing at the end of each custom option in a PDF invoice. See the image below. Any ideas what this character might be?
It might be the case that the current PDF's font library that is used, doesn't support certain characters.
By default it uses the following Font library for PDF Generation: LinLibertineC_Re-2.8.0.ttf
In order to change the default PDF Font:
Get the desired font library's TTF-file and place it in the lib folder of your Magento installation.
Edit the following files (better mirror it instead of editing core files directly) in order to switch the font:
/app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php
/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Abstract.php

Resources