我想将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样式看起来不太好
答案 0 :(得分: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);
}