c# - abcPDF 7 将 HTML 转换为 PDF 但仅转换第一页

标签 c# asp.net html abcpdf

我目前正在使用 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();

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

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

最佳答案

我遇到了完全相同的问题。答案是使用链接,但上一个答案中提供的页面并没有准确地告诉您如何做到这一点。这是我网站上的一个例子: 请注意,变量 htmlOutput 是我的对象中的一个变量,它接收我要呈现的 htmlOutput。我通过将 html 直接插入变量从页面收集这个,或者如果它用于当前页面,我为页面运行 protected 覆盖 void Render(HtmlTextWriter 输出),将 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();

关于c# - abcPDF 7 将 HTML 转换为 PDF 但仅转换第一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/286748/

相关文章:

c# - 如何在本地运行 Azure WebJob?

c# - 将参数发送到另一个 ASP.Net 页面

c# - 仅使用 Azure AD 进行身份验证而不是授权

html - CSS 文本大纲在 IE10 兼容性 View 中不起作用

c# - Xamarin.iOS 本地化

c# - Entity Framework 无效的对象名称 "dbo.EA_EmployeePerformance"

javascript - 检测单击元素的内部文本而不将文本包装在第二个元素中

html - 网页打印

c# - .NET 中计算数组平均值的算法的性能问题

asp.net - 由不同 ContentPlaceHolder 中的控件触发 UpdatePanel 的更新