问题:
我正在通过 ABC pdf 传递 HTML 并创建 pdf。
但是 CSS 没有应用到内容上,创建的 pdf 不是预期的。
这是我的代码,你能告诉我问题是什么或者我们如何应用 CSS...
public static String CreateHtmlFile(String strHtmlCode)
{
String Modifiedhtml = @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd""><html class="" _Telerik_IE9"" xmlns=""http://www.w3.org/1999/xhtml"">" + strHtmlCode;
Modifiedhtml = Modifiedhtml.Remove(Modifiedhtml.IndexOf(@"//<![CDATA["), (Modifiedhtml.IndexOf("//]]>") - Modifiedhtml.IndexOf(@"//<![CDATA[")));
string[] stringSeparators = new string[] { "PdfCreator" };
var baseUrl = HttpContext.Current.Request.Url.AbsoluteUri.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries).First();
Modifiedhtml = Modifiedhtml.Replace(@"href=""../", (@"href=""" + baseUrl));
Modifiedhtml = Modifiedhtml.Replace(@"href=""/", (@"href=""" + baseUrl));
Doc theDoc = new Doc();
theDoc.HtmlOptions.UseScript = false;
//theDoc.Width = 1125;
String s = string.Empty;
//s = File.ReadAllText(@"D:\test.html");
theDoc.Page = theDoc.AddPage();
int theID;
theID = theDoc.AddHtml(strHtmlCode);
//theID = theDoc.AddHtml(s);
while (true)
{
theDoc.FrameRect(); // add a black border
if (!theDoc.Chainable(theID))
break;
theDoc.Page = theDoc.AddPage();
theID = theDoc.AddImageToChain(theID);
}
for (int i = 1; i <= theDoc.PageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
theDoc.Save(@"D:\two\pagedhtml4.pdf");
theDoc.Clear();
return String.Empty;
}
strHtmlCode 是我们必须将其转换为 PDF 的页面的 HTML。
提前致谢
最佳答案
来自WebSupergoo doc page在 AddHtml
函数上:
Adds a block of HTML styled text to the current page.
HTML 样式的文本不 支持 CSS。对于功能齐全的标准 CSS,您需要 AddImageHtml
。
关于c# - CSS不适用于从ABC pdf创建pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20040600/