6

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

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

这对于第一页非常有效,但随后会截断页面并且不会继续呈现剩余页面。

有谁知道为什么它在页面后停止?

4

2 回答 2

11

我有这个完全相同的问题。答案是使用链接,但上一个答案中提供的页面并没有准确地向您展示如何做到这一点。这是我网站上的一个示例:请注意,变量 htmlOutput 是我的对象中的一个变量,它接收我要呈现的 htmlOutput。我通过将 html 直接推送到变量中来从页面收集此信息,或者如果它针对当前页面,我为 Page 运行受保护的覆盖 void Render(HtmlTextWriter output),将 Render 的内容推送到此 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();
于 2009-11-13T01:05:31.163 回答
10

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

这里

可以在此处找到如何使用 AddImageToChain 的示例

于 2008-11-13T10:29:26.033 回答