1

htmlファイルを解析してpdfを生成しようとしています。コードを使用します

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();

キリル文字/国際語を使用したい場合、ベースフォントを定義するにはどうすればよいですか?

4

2 に答える 2

4

フォントを登録する必要があります

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

変更されたページの本文

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

ロシア語で読むことができる人にとって、この記事は役に立つかもしれません

于 2012-09-01T19:05:11.707 に答える
1

私は次の変種を提案します

//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 };
于 2012-08-02T08:38:28.597 に答える