问题
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?
回答1:
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
回答2:
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 };
来源:https://stackoverflow.com/questions/11536942/itextsharp-parse-html-with-cyrillic-international-words