Special characters in iText - pdf

I need help in using these symbols ⎕, ∨, ๐, Ʌ, and so on. But when I create a PDF with iText these symbols do not appear.
What can I do so that these symbols appear?

You have to use a font and encoding that contains those characters. Your best bet is to use IDENTITY_H for your encoding, as this grants you access to every character within a given font... but you still have to use the right font.
There are several font-manipulation examples within "iText in Action's" chapter on fonts:
http://www.itextpdf.com/book/chapter.php?id=11
The examples are down the right side. Buying the book would probably help too.

I had the same problem too and I figured out using IDENTITY_H for encoding is working fine.
For example:
java.awt.Font f =...;
Font font = FontFactory.getFont(f.getName(),BaseFont.IDENTITY_H)
I don't understand why with BaseFont.WINANSI it doesn't work. Winansi is the standard Windows Cp1252 character set, that one used by my JVM. So, if the char is correctly displayed in Java, why it is not the case for PDF?

You can escape them according to the unicode escape sequence defined in the java language specification. See http://java.sun.com/docs/books/jls/first_edition/html/3.doc.html
If you are using IntelliJ IDEA for your code you can download the StringManipulation plugin, that does the escapes for you. In the settings of IDEA you can also set the "Transparent native-to-ascii conversion" checkbox under File encodings, and this should help do the trick.

square in pdf file by iText:
BaseFont bf = BaseFont.createFont("c:/windows/fonts/arialbd.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
question.add(new Phrase("\u25A1", new Font(bf, 26)));
You can see a pdf file exemple here

Related

Yii2 widget fileinput utf-8 charset problem

I would like to upload a filename with utf-8 characters such as greek, german etc. The upload occurs successfully for both file size and type, unfortunately its filename is being replaced by strange characters. However when english characters for filename are used, there is no problem at all.
Any idea what it might be wrong with utf-8 characters regarding filename for this specific Yii2 widget plugin?
I provide you with the filename being generated for utf-8 characters
and additionally the function source code that produces filename via _slugDefault (added extra line for no special characters).
Regards
I found that it actually depends on the server OS file system language settings and not by the widget itself. So i used the following php function in my controller:
$file_name=iconv('UTF-8', 'language//TRANSLIT',$model->field);
$file->saveAs('files/'.$file_name);
Thanks a lot and i am indeed very happy to solve it on myself!

Gujarati fonts not displaying in PDF properly using itext 5.5.5 and xmlworker 5.5.5

I am using arial .ttf file. I have tried different font file for gujarati such as lohit, padmaa, shruti but it not displaying properly. The characters are not getting substituted properly.
In PDF it displays as :
અરથ પરજ ડરમ વૈભવ સવગે
Originally it should display as:
અર્થ પ્રજા ડ્રમ વૈભવ સ્વર્ગે
I have tried using GlyphSubstitutionTableReader but its not working for me.
Please guide me. Thanks in advance.
iText 5 currently doesn't support any Brahmic scripts. The reason is that these require an implementation of a specific font table called GSUB, which simply isn't there yet. There is no way to get this to display correctly with iText 5.5.5, but anyone is welcome to try and implement it.

Convert unicode chars in xml to ascii

InDesign can export an XML file, and it will also "Remap break, whitespace, and special characters" if you check the box to do that. How can I do the same thing on text?
For example, if I have: •this is a bullet —long dash
InDesign exports as: &# 8226;this is a bullet &# 8212;long dash
I don't know what kind of encoding this is. Can a standard Objective-C class do this (working on OS X) or a third party library?
They are an HTML thing. People usually refer to as HTML encoding but technically, they are Numeric character references. There is nothing built into Foundation that decodes them, but if you look around you can find some code to handle it (for example, https://github.com/mwaterfall/MWFeedParser/blob/master/Classes/NSString+HTML.m).

Grails / RenderPdf Arabic Chars

We have a grails app, in which we are using the Render Plugin to render content in .pdf. It all works fine for English, but unfortunately for Arabic (which we must render) all the charactes seem "broken". Some numbers and spaces there...
The render plugin uses IText, and I have tried the approach with:
...
def renderer = new ITextRenderer()
FontResolver resolver = renderer.getFontResolver()
renderer.getFontResolver().addFont("/usr/share/fonts/truetype/ttf-arabeyes/ae_AlArabiya.ttf", BaseFont.EMBEDDED)
...
(the font used here is just an example), but in any case, it doesn't work.
Anybody any experience with this kind of issue?
Thank you in advance!
renderer.getFontResolver.addFont(fontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED_SUBSET);
The default encoding for fonts in iText is WinAnsiEncoding, AKA Code Page 1252. You need to specify an encoding that contains the characters you want...
Yep. Google Code produced this bit of code for the addFont you're using:
public void addFont(String path, boolean embedded)
throws DocumentException, IOException {
addFont(path, BaseFont.CP1252, embedded);
}
IDENTITY_H lets you address all the glyphs in a given font. I always recommend it, though there is a small drawback. Using IDENTITY_H forces the font to be an embedded subset in iText, no way around it.

zend_pdf can't read existing pdf

I'm using Zend_Pdf to generate PDF files, based on existing PDF templates. The problem is, I can't read any of the templates - I get a "File is not a PDF." error because the first 4 characters in the file are "%???" instead of "%PDF" (I used "head" to check this).
Is this a character encoding problem? I believe the templates are in ISO-8859-1, must I set something in Zend_Pdf_Parser to handle this?
Thanks
to answer my own question, I moved to Perl PDF::Extract and it's working.