Wednesday, 7 August 2013

iText PdfDictionary encoding issues?

iText PdfDictionary encoding issues?

When I create a PDF file, I attach some info to it with this code to make
it readable to my program:
PdfDictionary dictionary = new PdfDictionary();
PdfObject object;
PdfName index;
ArrayList<String> content = getCompactData(document);
for (int i = 0; i < content.size(); i++)
{
object = new PdfString(content.get(i));
index = new PdfName(Integer.toString(i+1));
dictionary.put(index, object);
}
writer.getExtraCatalog().putAll(dictionary);
When I'm opening the program, I use this code to extract the data:
PdfDictionary dictionary = reader.getCatalog();
PdfName index;
PdfObject line;
ArrayList<String> data = new ArrayList<String>();
for (int i = 1; i < dictionary.size()-2; i++)
{
index = new PdfName(Integer.toString(i));
line = dictionary.getAsString(index);
data.add(line.toString());
}
That all works great except for one little detail. Characters such as
èšðæž are not passing to the process properly for some reason. Once I try
to extract data, my program gets confuset and can't recognize the letters.
Several notes:
My workspace encoding is UTF-8
When working with my program i can enter those letter with no problems,
they'll be displayed properly.
I use custom .ttf (truetype) font which I know supports these characters
I tried printing out contents of the catalog after the last line of the
save-code I provided, everything was printed out properly.
I also tried printing out the contents of catalog a line before the first
one in the open-code, characters were not displayed.
So I have no idea where could it all go wrong. Do you?

No comments:

Post a Comment