c# - CSS不适用于从ABC pdf创建pdf

标签 c# asp.net .net abcpdf

问题:

我正在通过 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 pageAddHtml 函数上:

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/

相关文章:

c# - 如何从 aspx 文件调用方法?

c# - 具有 "Group By"和/或 "Order by"的 Entity Framework

javascript - updatepanel 部分回发后运行 javascript

javascript - 为 Javascript 显示文本启用多语言支持的推荐方法是什么

c# - 如何在 UWP 中检查有线互联网连接?

c# - 使用 Moq 模拟不安全的接口(interface)

c# - WPF:如何实现通用窗口?

c# Dynamic.Linq - groupby,然后按条件选择

jquery - 如何使用Tab键进入下一个标签

java - 字节码和目标代码有什么区别?