Okay, the problem is solved.

the thing that confused me that was the BaseFont.createFont() method
when fails to load the fonts it doesn't throw an IOException (as the
javadoc sais), but it falls back to Helvetica. (and this method can't
load fonts from classpath /jar/, so I had no clue what's wrong)

The correct way to embedding fonts loaded from jars is loading them
with FontFactory:

Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        try {
                // step 2
            PdfWriter.getInstance(document, new
FileOutputStream("encoding.pdf"));
            // step 3
            document.open();
            // step 4
            String text = "Árvíztűrő tükörfúrógép .\u0150\u0151\u0170\u0171.";
            Font font = FontFactory.getFont(FontFactory.TIMES, 10, Font.NORMAL);
            Font font2 =
FontFactory.getFont("/fonts/linuxlibertine/LinLibertine_Re-4.1.8.ttf",BaseFont.IDENTITY_H,BaseFont.EMBEDDED,10);


            document.add(new Paragraph(text, font));
            document.add(new Paragraph(text, font2));

        }
        catch (Exception de) {
            de.printStackTrace();
        }
        // step 5
        document.close();



On Sun, Jan 25, 2009 at 12:35 AM, mister bean
<abinst...@pacificdataworks.com> wrote:
>
> The font must permit embedding for this to work. Most fonts do, but many do
> not. Have you checked this particular font file?
>
> ---mr. bean
>
>
>
> Balázs Grill wrote:
>>
>> I've loaded the fonts using
>> BaseFont.createFont("file.ttf",BaseFont.IDENTITY_H,true);
>> The last parameter says that this font should be embedded in the
>> document, isn't it?
>>
>> Do i need explicitly embed the fonts above this?
>>
>> 2009/1/24 Leonard Rosenthol <leona...@pdfsages.com>:
>>> Not only do you have to pick a font where those characters (glyphs) exist
>>> in
>>> teh font - BUT you also need to embed the font in the PDF so that
>>> everyone
>>> can see them...
>>>
>>> Leonard
>>>
>>> 2009/1/24 Balázs Grill <balag...@gmail.com>
>>>>
>>>> Hi!
>>>>
>>>> I tried to create PDFs in hungarian language therefore it contains
>>>> characters such as ő (\u0151) or ű(\u071). These characters are not
>>>> displayed in the resulting PDF.
>>>>
>>>> I created a snippet, which tries to add such characters to the
>>>> document. Am i doing it wrong?
>>>>
>>>> public static void main(String[] args) {
>>>>                System.out.println("Start");
>>>>                Document document = new Document(PageSize.A4, 50, 50, 50,
>>>> 50);
>>>>        try {
>>>>                // step 2
>>>>            PdfWriter.getInstance(document, new
>>>> FileOutputStream("encoding.pdf"));
>>>>            // step 3
>>>>            document.open();
>>>>            // step 4
>>>>            String text = "Árvíztűrő tükörfúrógép
>>>> .\u0150\u0151\u0170\u0171.";
>>>>            document.add(new Paragraph(text,
>>>> FontFactory.getFont(FontFactory.TIMES, 10, Font.NORMAL)));
>>>>        }
>>>>        catch (Exception de) {
>>>>            de.printStackTrace();
>>>>        }
>>>>        // step 5
>>>>        document.close();
>>>>        System.out.println("Done.");
>>>> }
>>>>
>>>> I tried to use third-party ttf (and otf) font files, thinking that
>>>> maybe the built-in font files does not contain these characters. The
>>>> font files are loaded and used perfectly, except the mentioned
>>>> characters. Could someone help me solving the problem?
>>>>
>>>> Thanks
>>>>
>>>> Balage;
>>>>
>>>>
>>>> ------------------------------------------------------------------------------
>>>> This SF.net email is sponsored by:
>>>> SourcForge Community
>>>> SourceForge wants to tell your story.
>>>> http://p.sf.net/sfu/sf-spreadtheword
>>>> _______________________________________________
>>>> iText-questions mailing list
>>>> iText-questions@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/itext-questions
>>>>
>>>> Buy the iText book: http://www.1t3xt.com/docs/book.php
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> This SF.net email is sponsored by:
>>> SourcForge Community
>>> SourceForge wants to tell your story.
>>> http://p.sf.net/sfu/sf-spreadtheword
>>> _______________________________________________
>>> iText-questions mailing list
>>> iText-questions@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/itext-questions
>>>
>>> Buy the iText book: http://www.1t3xt.com/docs/book.php
>>>
>>
>> ------------------------------------------------------------------------------
>> This SF.net email is sponsored by:
>> SourcForge Community
>> SourceForge wants to tell your story.
>> http://p.sf.net/sfu/sf-spreadtheword
>> _______________________________________________
>> iText-questions mailing list
>> iText-questions@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/itext-questions
>>
>> Buy the iText book: http://www.1t3xt.com/docs/book.php
>>
>>
>
> --
> View this message in context: 
> http://www.nabble.com/Can%27t-display-%22%C5%91%22-and-%22%C5%B1%22-characters-in-PDF-tp21644421p21646666.html
> Sent from the iText - General mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> SourcForge Community
> SourceForge wants to tell your story.
> http://p.sf.net/sfu/sf-spreadtheword
> _______________________________________________
> iText-questions mailing list
> iText-questions@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
> Buy the iText book: http://www.1t3xt.com/docs/book.php

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Reply via email to