我使用itextsharp从html创建pdf文件。它工作得很好,但我在HTML中的样式属性有问题。使用此代码解析html i。#。
cssResolver.AddCssFile(AppDomain.CurrentDomain.BaseDirectory+"/Content/css/style.css",true);
IPipeline pipeline =
new CssResolverPipeline(cssResolver,
new HtmlPipeline(htmlContext,
new PdfWriterPipeline(doc, writer)));
var worker = new XMLWorker(pipeline, true);
var p = new XMLParser(true, worker, Encoding.Unicode);
using (var sr = new StringReader(html))
{
p.Parse(sr);
}
所以它应用了我的CSS样式并且它们有效,但我的html文件中有一些样式,我无法将其移动到css文件,因为它们是动态形成的。
<div id="VC" class="vc-scene-canvas-div" style="left: 15px; bottom: 15px; height: 517px; width: 244px;">
<img src="">
<img src="" style="left: 32px; bottom: 0px; height: 459px; width: 181px; z-index: 10;">
<img src="" style="left: 14px; bottom: 0px; height: 477px; width: 217px; z-index: 20;">
</div>
当我形成我的pdf时,我看到除了图像以外的所有内容。但是当我删除样式标签时,一切正常。 是否可以同时使用css和html中的样式?也许我做错了什么?