簡體   English   中英

類型為EngineType.Gecko的HtmlOption.Engine僅生成第一頁

[英]HtmlOption.Engine with type EngineType.Gecko generate only first page

我想將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樣式看起來不太好

要使用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);
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM