从html页面渲染pdf

Render a pdf from a html page

本文关键字:pdf html      更新时间:2023-09-26

你好,我有以下代码,我正在尝试将html页面转换为pdf。我正在使用abcpdf。

我的代码如下:

Doc theDoc = new Doc();
    theDoc.Rect.Inset(72, 144);
    theDoc.Page = theDoc.AddPage();
    int theID;
    **theID = theDoc.AddImageUrl("http://www.templateworld.com/free_templates.html/");**
    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(Server.MapPath("pagedhtml.pdf"));
    theDoc.Clear();

在以下行:

ID=文档添加图像URL("http://www.templateworld.com/free_templates.html/");

它抛出一个错误,说"HTML呈现为空白"。我在Firefox和chrome上也试过同样的操作。我试着用其他url也是如此。我也犯了同样的错误。

有人知道这个问题的解决方案吗?

查看另一篇Stack Overflow文章。也许它会帮助你。

ABCPDF6问题:;HTML呈现为空白";但是网页输出很好

trueamerican420和McAden的回答都很有帮助。

我在InternetExplorer10上使用ABCPDF版本7。我删除了更新并降级为互联网浏览器9。现在一切都很完美