0

I want create pdf from html, I use the itext library I have problem with polish fonts in pdf I use this code:

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringReader;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.html.simpleparser.HTMLWorker;
import com.itextpdf.text.html.simpleparser.StyleSheet;
import com.itextpdf.text.pdf.PdfWriter;

public class PolishFont {
public static void main(String ... args ) throws DocumentException, IOException
{
    String html = "ąśżźćęó";
    StringReader reader = new StringReader(html);// step 1: creation of a document-object
    Document document = new Document(PageSize.LETTER);
    PdfWriter.getInstance(document, new FileOutputStream("c://temp//testpdf1.pdf")); 

    HTMLWorker worker = new HTMLWorker(document);

    document.open();
    FontFactory.register("C:\\Windows\\Fonts\\times.TTF", "arial unicode ms");

    StyleSheet styleSheet = new StyleSheet();
    styleSheet.loadTagStyle("body", "encoding", "Identity-H");
    worker.setStyleSheet(styleSheet);

    worker.parse(reader);
    document.close();
}
}

but pdf display only "ó", where is error?

user1957895
  • 31
  • 2
  • 6
  • HTMLWorker is has been abandoned quite some time ago. A lot of font fixes have been added over the years, try updating your iText dependency and use XMLWorker (also from the iText team). – Michaël Demey Apr 25 '13 at 11:42
  • See this post which addresses it in the .Net port: http://stackoverflow.com/a/4903223/231316 – Chris Haas Apr 26 '13 at 13:40

0 Answers0