2

在与这个不太友好的 API 苦苦挣扎后,我终于取得了进展,但现在我遇到了一个非常讨厌的问题。我在我的 html 中的各个位置放置了“dir”属性的值是“rtl”..但 XMLWorker 似乎根本不尊重这一点。有谁知道解决方法?这是我的方法:

public static void Generate<TModel>(string templateFile, TModel model, string outputFile, IEnumerable<string> fonts)
        {
            string template = System.IO.File.ReadAllText(templateFile);
            string result = Razor.Parse(template, model);

            using (var fsOut = new FileStream(outputFile, FileMode.Create, FileAccess.Write))
            using (var stringReader = new StringReader(result))
            {
                var document = new Document();
                var pdfWriter = PdfWriter.GetInstance(document, fsOut);
                pdfWriter.InitialLeading = 12.5f;
                document.Open();

                var xmlWorkerHelper = XMLWorkerHelper.GetInstance();

                var cssResolver = new StyleAttrCSSResolver();
                //cssResolver.AddCss(cssFile);

                var xmlWorkerFontProvider = new XMLWorkerFontProvider();

                foreach (string font in fonts)
                {
                    xmlWorkerFontProvider.Register(font);
                }

                var cssAppliers = new CssAppliersImpl(xmlWorkerFontProvider);
                var htmlContext = new HtmlPipelineContext(cssAppliers);
                htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());

                PdfWriterPipeline pdfWriterPipeline = new PdfWriterPipeline(document, pdfWriter);
                HtmlPipeline htmlPipeline = new HtmlPipeline(htmlContext, pdfWriterPipeline);
                CssResolverPipeline cssResolverPipeline = new CssResolverPipeline(cssResolver, htmlPipeline);
                XMLWorker xmlWorker = new XMLWorker(cssResolverPipeline, true);
                XMLParser xmlParser = new XMLParser(xmlWorker);
                xmlParser.Parse(stringReader);

                document.Close();
            }
        }
4

1 回答 1

1

我创建了一个示例来展示如何使用 XMLWorker 解析和显示 RTL 数据。从这里下载

于 2013-08-15T10:47:59.207 回答