C# abcPDF 7 将 HTML 转换为 PDF 但只转换了第一页
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/286748/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
abcPDF 7 converting HTML to PDF but only getting the first page converted
提问by Alexandre Brisebois
I'm currently using abcPDF 7 to convert HTML to PDF. This is done via an ASPX page where I override the Render method.
我目前正在使用 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();
This works perfectly for the first page but then truncates the page and does not continue rendering the remaining pages.
这对于第一页非常有效,但随后会截断页面并且不会继续呈现剩余的页面。
Does anyone know why it stops after a page?
有谁知道为什么它在一页后停止?
采纳答案by schnaader
回答by Chris Smith
I had this exact same issue. The answer is using chaining, but the page provided in the previous answer doesn't exactly show you how to do this. Here's an example from my site: Note that the variable htmlOutput is a variable in my object which takes in the htmlOutput I want to render. I gather this from the page either by just pushing html directly into the variable, or if its for the current page, I run the protected override void Render(HtmlTextWriter output) for Page, pushing the content of the Render into this htmlOutput variable.
我有这个完全相同的问题。答案是使用链接,但上一个答案中提供的页面并没有完全向您展示如何执行此操作。这是我网站上的一个示例:请注意,变量 htmlOutput 是我的对象中的一个变量,它接收我想要呈现的 htmlOutput。我通过将 html 直接推送到变量中来从页面收集它,或者如果它用于当前页面,我运行受保护的覆盖 void Render(HtmlTextWriter output) for Page,将 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();