1

我想将 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 样式看起来不太好

4

1 回答 1

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);
 }
于 2014-10-21T13:09:32.820 回答