ABCPDF6 问题:“HTML 渲染为空”但网页输出没问题

发布于 2024-12-08 07:48:01 字数 311 浏览 0 评论 0原文

正如标题所示,我们使用 ABCPdf6 从 XSLT 渲染 PDF。一切工作正常,但现在我们收到一条错误,指出“HTML 渲染为空白”。使用浏览器(在 IE/Firefox/Chrome 上测试),我可以浏览到生成的 HTML(格式为 XSL),并且它在浏览器中显示得非常好。 ABCPDF6 无法转换该文件。我已尝试将控制权交给输出 XSL 的页面,但仍然收到此错误。

有没有人有使用 ABCPdf 的经验并且以前遇到过这种情况?该代码之前工作正常,没有任何问题,而另一个使用完全相同的生成代码的页面(甚至指向输出 HTML 的相同占位符页面!)工作正常。

Like the title says, we are using ABCPdf6 to render PDFs from XSLT. Everything was working fine, but now we are getting an error that states "HTML render is blank". Using a browser (tested on IE/Firefox/Chrome) I am able to browse to the generated HTML (formatted XSL) and it displays perfectly fine in the browser. ABCPDF6 is not able to convert the file. I have tried giving control to the page that outputs the XSL, but I am still getting this error.

Does anyone have experience with ABCPdf and have encountered this before? The code was working fine before without a problem, and another page that uses the exact same generating code (even pointing to the same placeholder page that spits out the HTML!) is working fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

迷你仙 2024-12-15 07:48:01

我现在知道我的情况出了什么问题。
当我在 2008 年服务器上运行 Windows 更新时,安装了 Internet Explorer 9。
IE 9 有一种不同的 HTML 渲染方式,这会阻碍 abcPDF。
更新到最新版本(8)解决了我的所有问题。在此版本中,您还可以尝试另一个名为 Gecko 的 HTML 引擎。

即使您已经解决了问题,但如果其他人遇到此错误,我建议您安装试用版并使用最新版本进行尝试。

I know what the problem was in my case now.
When i ran Windows update on my 2008 server, Internet Explorer 9 was installed.
IE 9 has a different way of rendering HTML which brakes abcPDF.
Updating to the latest version (8) solved all my problems. In this version you can also try another HTML engine called Gecko.

Even though you have resolved your problem, if anyone else gets this error, I would suggest that you install the trial version and try this out with the latest version.

痴者 2024-12-15 07:48:01

我在使用 AbcPdf4.0 的 Windows 7 机器上遇到了同样的错误。在 MS 更新期间,IE8 升级到了 IE10。通过卸载 IE10 解决了问题。

注意:Abcpdf4.0 不适用于 IE9 及以上版本。升级 Abcpdf 或卸载最新的 IE。

I had same error on windows 7 machine with AbcPdf4.0. During MS updates IE8 was upgraded to IE10. Issue got fixed by uninstalling IE10.

Note: Abcpdf4.0 does not work with IE9 onwards. Either upgrade Abcpdf or uninstall latest IE.

箜明 2024-12-15 07:48:01

今天早上我在 AbcPdf9 上遇到了类似的问题。我添加了代码来测试引擎类型,GECKO 工作了,然后我将其换回 MSHTML,它仍然工作。所以这是一个暂时的问题。

这是指定引擎类型的方式:

using (var document = new Doc())
{
    document.HtmlOptions.Engine = EngineType.Gecko;
    ...
    ...
}

此代码调用将 html 转换为 PDF 的方法,但如果需要,则调用它两次,因为它只会失败一次:

try
{
    return GeneratePdfFromHtml(html, width, EngineType.MSHtml);
}
catch (Exception ex)
{
    /* detect this known issue, swapping the rendering engine once seems to fix it */
    if (ex.Message.ToUpper().Contains("BLANK"))
    {
        return GeneratePdfFromHtml(html, width, EngineType.Gecko);
    }
    throw;                            
}

然后您可以向执行转换的方法添加一个参数:

    public byte[] GeneratePdfFromHtml(string html, int width, EngineType engineType)
    {
        if (string.IsNullOrWhiteSpace(html)) throw new ArgumentNullException("html");
        if (width < 100) throw new ArgumentOutOfRangeException("width");

        try
        {
            using (var document = new Doc())
            {
                document.HtmlOptions.Engine = engineType;
                ...
                ...

如果您有建议或不同的解决方案,请发表评论。

I had a similar issue this morning with AbcPdf9. I added code to test the engine types and GECKO worked, then I swapped it back to MSHTML, and it still worked. So it was a temporary issue.

This is how you specify the engine type:

using (var document = new Doc())
{
    document.HtmlOptions.Engine = EngineType.Gecko;
    ...
    ...
}

This code calls the method that converts the html to PDF, but calls it twice if necessary, since it will only fail once:

try
{
    return GeneratePdfFromHtml(html, width, EngineType.MSHtml);
}
catch (Exception ex)
{
    /* detect this known issue, swapping the rendering engine once seems to fix it */
    if (ex.Message.ToUpper().Contains("BLANK"))
    {
        return GeneratePdfFromHtml(html, width, EngineType.Gecko);
    }
    throw;                            
}

Then you can add a parameter to the method that does the conversion:

    public byte[] GeneratePdfFromHtml(string html, int width, EngineType engineType)
    {
        if (string.IsNullOrWhiteSpace(html)) throw new ArgumentNullException("html");
        if (width < 100) throw new ArgumentOutOfRangeException("width");

        try
        {
            using (var document = new Doc())
            {
                document.HtmlOptions.Engine = engineType;
                ...
                ...

If you have a suggestion or different solution, please leave a comment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文