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.
Related
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.
I have a ruby script to generate a pdf document with some text. The text contains emojis in it.
The problem with the first line of text is that it prints the three emojis separated by something that looks like a cross when they should be a single emoji(family of three members).
The problem with the second line is that it just prints a square instead of the intended emoji(shush face).
I've tried with some other fonts but it still won't work. These are the fonts:
DejaVuSans
ipam
NotoSans-Medium
I can't find the problem
Is there anything missing?
Am I doing something wrong?
The gems are installed and the fonts are in the right place
require "prawn"
require "prawn/emoji"
require "prawn/measurement_extensions"
$pdf = Prawn::Document.new(:page_size => [200.send(:mm),200], :margin => 0)
$pdf.font "./resources/Montserrat-Medium.ttf"
st = "\u{1F468}\u200D\u{1F469}\u200D\u{1F466}".encode("UTF-8")
st2="\u{1F92B}".encode("UTF-8")
$pdf.draw_text st,:at => [10, 100]
$pdf.draw_text st2,:at => [10, 80]
$pdf.render_file "test.pdf"
Turns out Prawn doesn't know how to parse the joined emojis (those formed by the a set of simple emojis joined by \u200D). Prawn/emoji is supposed to do that but there is a bug on the regex used to identify the emojis that causes the joined emojis to be drawn separately.
Also the index and the image gallery used is a little bit outdated.
The solution is to substitute #emoji_index.to_regexp in the class Drawer , in the prawn/emoji source code for a regex that can recognize the joined emojis and update the emoji gallery, after that run the task to update the index and you are good to go.
The fonts have nothing to do with it.
I'm creator of prawn-emoji.
Certainly prawn-emoji v2.1 or older can't draw joined-emojis like 👨👨👦 and 1️⃣.
https://github.com/hidakatsuya/prawn-emoji/issues/24
So today, i released prawn-emoji v3.0. This release includes support for joined emoji like 👨👨👦(ZWJ Sequence) and 1️⃣(Combining Sequence), and switch to Twemoji.
Please see below for further details.
https://github.com/hidakatsuya/prawn-emoji/blob/master/CHANGELOG.md
Please try to use prawn-emoji v3.0 if you'd like.
Hope this help.
It does work. You can look up the character codes for deja vu sans.
You can also search for which fonts support which Unicode characters. If you are seeing an empty box with Montserrat-Medium, that means that unicode character is not supported, for example the character, \u200D
Here is a helpful link to search which fonts support that character - http://www.fileformat.info/info/unicode/char/200d/fontsupport.htm
Here is another link for code \u{1F92B}, which is your shush emoji- http://www.fileformat.info/info/unicode/char/1F92B/fontsupport.htm
Both DejaVuSans and Montserrat-Medium dont support it.
require 'prawn'
require 'prawn/emoji'
Prawn::Document.generate 'foo.pdf' do
font "./resources/Montserrat-Medium.ttf"
text "For Montserrat-Medium"
text "\u{1F468}\u200D\u{1F469}\u200D\u{1F466}".encode("UTF-8")
text "\u{1F92B}"
text " "
font './resources/DejaVuSans.ttf'
text " For DejaVuSans"
text "\u{1F468}\u200D\u{1F469}\u200D\u{1F466}".encode("UTF-8")
text "\u{1F92B}"
end
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.
I'm not expert in Delphi and I'm trying to add "Extended ASCII String" broken into individual character and then add into the TSgringGrid.Cells[x,y]. Some of the characters are getting displayed but rest of the characters are not shown in these cells. Another way for me is to convert these characters in Hex-Mode and then show it but this is not Required.
ChartSet used was OEM_CHARSET and Font = Terminal. I simply wish to display all 255 characters in Cell. Basically I wanted to created the Binary Editor like Edit.com in Delphi/ Lazarus which is available in XP.
I used AnsiToUtf8(chr(i)) and it was solved.
I'm trying to generate images through RMagick that contain Arabic text that has been parsed from an excel spreadsheet. Arabic letters change shape depending on their neighbors and this seems to happen in excel for displaying purposes only. The letters are not stored in their modified form, so they print out incorrectly. Does anyone know of a library that addresses this? TIA
What version of Ruby are you using? Also, is ImageMagick supposed to render Arabic text correctly in the first place? If not, you might want to use Prawn or something to generate a PDF file...
You need to reshape Arabic text in Ruby for ImageMagick/RMagick to render it correctly.
This is already solved for Java(Better-Arabic-Reshaper) and Python(arabic_reshaper). Do the same task in Ruby text before passing it to ImageMagick. linux CLI: how to render Arabic text into bitmap