1

I try to parse html file and to generate pdf. I use code

document.Open();
HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());
ICSSResolver cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(true);
IPipeline pipeline =
    new CssResolverPipeline(cssResolver,
        new HtmlPipeline(htmlContext,
                new PdfWriterPipeline(document, writer)));


XMLWorker worker = new XMLWorker(pipeline, true);
XMLParser p = new XMLParser(true, worker, Encoding.Unicode);

p.Parse((TextReader)File.OpenText(@"Template.html"));
document.Close();

How can I define base font, If i'd like use cyrillic/international words?

PlushEngineCell
  • 775
  • 1
  • 7
  • 14
  • See if this post help http://stackoverflow.com/questions/10329863/display-unicode-characters-in-converting-html-to-pdf – Chris Haas Jul 20 '12 at 13:45

2 Answers2

4

You should register font

string arialuniTff = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF");
FontFactory.Register(arialuniTff);

and modifed page's body

<body face='Arial' encoding='koi8-r' >
...
</body >

For somebody, who can read in russian, this article can be useful

PlushEngineCell
  • 775
  • 1
  • 7
  • 14
1

I propose the following variant

//connect the font
            String FONT_LOCATION = Server.MapPath("~/fonts/arial.ttf");
            BaseFont baseFont = BaseFont.CreateFont(FONT_LOCATION, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            iTextSharp.text.Font font = new iTextSharp.text.Font(baseFont, iTextSharp.text.Font.DEFAULTSIZE, iTextSharp.text.Font.NORMAL);
            //connected

PdfPCell cell1 = new PdfPCell(new Phrase(lblN, font)) { HorizontalAlignment = 1, VerticalAlignment= 1 };
krakoss
  • 36
  • 3