Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Special characters in iText

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?

like image 541
barroco Avatar asked Sep 20 '10 17:09

barroco


People also ask

Is iText free for commercial use?

This license is a commercial license. You have to pay for it. To answer your question: iText can be used for free in situations where you also distribute your software for free. As soon as you want to use iText in a closed source, proprietary environment, you have to pay for your use of iText.

Is iText same as iTextSharp?

iText vs iTextSharp As you can tell from the historical overview, iTextSharp has always been kept in sync with iText, but before version 5, there was a difference in version numbers. Starting with version 7, the name iTextSharp is no longer used in favor of using the name iText.

What is iText format?

iText is a Java library originally created by Bruno Lowagie which allows to create PDF, read PDF and manipulate them. The following tutorial will show how to create PDF files with iText. This tutorial assumes that you have basis Java and Eclipse knowledge.

What is chunk in iText?

Chunk class in IText represents the smallest possible "chunk" of text. A Chunk can contain as little as a single character, up to several sentences. Notice how sentence 1 and sentence 6 are printed ontop of each other. The IText Chunk object does not add line breaks, paragraph spacing or any other kind of spacing.


2 Answers

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.

like image 83
Mark Storer Avatar answered Oct 03 '22 04:10

Mark Storer


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?

like image 35
Neo Avatar answered Oct 03 '22 06:10

Neo