【问题标题】:HtmlOption.Engine with type EngineType.Gecko generate only first page类型为 EngineType.Gecko 的 HtmlOption.Engine 仅生成第一页
【发布时间】:2014-09-15 11:49:45
【问题描述】:

我想将 html 导出为 pdf,文档已生成但只有第一页

    Doc theDoc = new Doc();
    theDoc.HtmlOptions.UseScript = true;
    theDoc.HtmlOptions.Media = MediaType.Print;
    theDoc.HtmlOptions.InitialWidth = 1048;
    theDoc.HtmlOptions.ImageQuality = 101;
    theDoc.HtmlOptions.UseScript = true;
    theDoc.HtmlOptions.OnLoadScript = "(function(){ window.ABCpdf_go = false; setTimeout(function(){ window.ABCpdf_go = true; }, 55000); })();";
    theDoc.HtmlOptions.Engine = EngineType.Gecko;
    theDoc.HtmlOptions.PageLoadMethod =  PageLoadMethodType.WebBrowserNavigate;
    theDoc.HtmlOptions.ForMSHtml.UseScript = true;

     int theID = theDoc.AddImageHtml(htmlContent);

     while (true)
    {
        theDoc.FrameRect();
        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(HttpContext.Current.Server.MapPath("htmlimport.pdf"));
    theDoc.Clear();

如何使用 Gecko 添加所有页面?如果我从页面中使用 MSHtml 样式就不好看了

【问题讨论】:

  • 你有没有让这个工作?我有同样的问题,下面接受的答案似乎没有添加任何内容。谢谢

标签: c# html abcpdf abcpdf9


【解决方案1】:

要使用 Gekoengine,请添加

  theDoc.HtmlOptions.Engine = EngineType.Gecko;

到顶部的文档设置。

您需要在添加 HTML 时对文档进行分页,只需将您拥有的内容包装在一个循环中,我已将上限设置为 50 页,但如果文档很大,则只需循环即可。

 int theID = theDoc.AddImageUrl(htmlContent);
 //Add up to 50 pages
 for (int i = 1; i <= 50; i++)
 {
   if (!theDoc.Chainable(theID))
   break;
   theDoc.Page = theDoc.AddPage();
   theID = theDoc.AddImageToChain(theID);
 }

【讨论】:

    猜你喜欢
    • 2015-07-31
    • 2011-02-08
    • 1970-01-01
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-26
    相关资源
    最近更新 更多