1

I want to export html to pdf, document is generated but only first page

    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();

how I can to add all pages with Gecko? if I use MSHtml style from the page is not look good

Alex
  • 8,908
  • 28
  • 103
  • 157
  • Did you ever get this to work? I have the same problem, the accepted answer below doesn't seem to add anything. Thanks – user1259167 Apr 12 '17 at 02:25

1 Answers1

1

To use the Gekoengine, add

  theDoc.HtmlOptions.Engine = EngineType.Gecko;

to the document settings at the top.

You need to page the document as you add the HTML, just wrap what you have in a loop, I have set a upper limit to 50 pages, but if the document is large just up the loop.

 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);
 }
TheAlbear
  • 5,507
  • 8
  • 51
  • 84