C# abcPDF 7将HTML转换为PDF,但仅转换第一页

C# abcPDF 7将HTML转换为PDF,但仅转换第一页,c#,asp.net,html,abcpdf,C#,Asp.net,Html,Abcpdf,我目前正在使用abcPDF 7将HTML转换为PDF。这是通过一个ASPX页面完成的,在该页面中我覆盖了Render方法 Doc theDoc = new Doc(); theDoc.SetInfo(0, "License", m_License ); theDoc.HtmlOptions.Paged = true; theDoc.HtmlOptions.Timeout = 1000000; string callUrl = "http:// my app page"; theDoc.AddI

我目前正在使用abcPDF 7将HTML转换为PDF。这是通过一个ASPX页面完成的,在该页面中我覆盖了Render方法

Doc theDoc = new Doc();
theDoc.SetInfo(0, "License", m_License );
theDoc.HtmlOptions.Paged = true;
theDoc.HtmlOptions.Timeout = 1000000;

string callUrl = "http:// my app page";
theDoc.AddImageUrl(callUrl);
Response.Clear();

Response.Cache.SetCacheability(HttpCacheability.Private);
Response.AddHeader("Content-Disposition", "attachment; filename=" + sFile + ".pdf");
Response.ContentType = "application/octet-stream";

theDoc.Save(Response.OutputStream);

Response.Flush();
这对第一个页面非常有效,但会截断该页面,而不会继续呈现其余页面

有人知道它为什么在一页之后停止吗?

“只绘制文档的第一页。可以使用AddImageToChain方法绘制后续页面。”


有关如何使用AddImageToChain的示例,请参见

我也有同样的问题。答案是使用链接,但上一个答案中提供的页面并没有确切地告诉您如何做到这一点。以下是我的网站上的一个示例: 注意,变量htmlOutput是我的对象中的一个变量,它接受我要渲染的htmlOutput。我从页面收集这些信息,或者直接将html推送到变量中,或者如果是当前页面,则对页面运行受保护的覆盖无效呈现(HtmlTextWriter输出),将呈现内容推送到这个htmlOutput变量中

Doc theDoc = new Doc();
int theID;
theDoc.Page = theDoc.AddPage();

theID = theDoc.AddImageHtml(htmlOutput);

 while (true)
 {
     theDoc.FrameRect(); // add a black border
     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();
  }
  //reset back to page 1 so the pdf starts displaying there
  if(theDoc.PageCount > 0)
       theDoc.PageNumber = 1;

  //now get your pdf content from the document
  byte[] theData = theDoc.GetData();
Doc theDoc=new Doc();
int theID;
theDoc.Page=theDoc.AddPage();
theID=doc.AddImageHtml(htmlOutput);
while(true)
{
theDoc.FrameRect();//添加黑色边框
如果(!theDoc.Chaineable(theID))
打破
theDoc.Page=theDoc.AddPage();
theID=DOC.AddImageToChain(theID);
}
对于(int i=1;i 0)
doc.PageNumber=1;
//现在从文档中获取您的pdf内容
字节[]theData=doc.GetData();

schnaader提供的答案中的第二个包含peices中的代码。谢谢你发布你的代码。我我相信这会帮助很多人。