2

For now I use version 5.5.3 and it works without problems, but I try to update to newest one and I have problem with polish characters (they are just missing). I make conversion from rtf to html and from html to pdf like this:

 private ElementList htmlToElementList(string htmlText)
    {
     ICSSResolver cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(true);

        // HTML
        HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
        htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());
        htmlContext.AutoBookmark(false);
        // Pipelines
        ElementList elements = new ElementList();
        ElementHandlerPipeline end = new ElementHandlerPipeline(elements, null);
        HtmlPipeline html = new HtmlPipeline(htmlContext, end);
        CssResolverPipeline css = new CssResolverPipeline(cssResolver, html);
        // XML Worker
        XMLWorker worker = new XMLWorker(css, true);
        XMLParser p = new XMLParser(worker);

        p.Parse(new StringReader(htmlText));

        return elements;
     }

It work like it should on 5.5.3. I try to investigate and I found one difference between them (5.5.3 vs 5.5.7): On each chunk in elements inside font BaseFont is not null only: ({itextSharp.text.pdf.TrueTypeFontUnicode})

image

on version 5.5.7 BaseFont is null.

I use only Century Gothic font (in html) (registered in FontFactory).

What is missing to get it work in new version?

Andreas_k
  • 103
  • 8

1 Answers1

4

I have also a same issue, my Turkish character are missing in my PDF. i have fix it by this.

String htmlText = html.ToString();

    Document document = new Document();

    string filePath = HostingEnvironment.MapPath("~/Content/Pdf/");
    PdfWriter.GetInstance(document, new FileStream(filePath + "\\pdf-"+Name+".pdf", FileMode.Create));
    document.Open();

    iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
    FontFactory.Register(Path.Combine(_webHelper.MapPath("~/App_Data/Pdf/arial.ttf")),  "Garamond");   // just give a path of arial.ttf 
    StyleSheet css = new StyleSheet();
    css.LoadTagStyle("body", "face", "Garamond");
    css.LoadTagStyle("body", "encoding", "Identity-H");
    css.LoadTagStyle("body", "size", "12pt");

    hw.SetStyleSheet(css);

    hw.Parse(new StringReader(htmlText)); 

please look here Missing Character issue in PDF using Itext

Regards, Vinit patel

Community
  • 1
  • 1
Vinit Patel
  • 2,408
  • 5
  • 28
  • 53