abcPDF 7 converting HTML to PDF but only getting the first page converted
Asked Answered
V

2

6

I'm currently using abcPDF 7 to convert HTML to PDF. This is done via an ASPX page where I override the Render method.

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?

Vikkivikky answered 13/11, 2008 at 10:26 Comment(0)
R
10

"Only the first page of the document is drawn. Subsequent pages can be drawn using the AddImageToChain method."

From here

An example how to use AddImageToChain can be found here

Romain answered 13/11, 2008 at 10:29 Comment(0)
S
11

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.

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();
Spigot answered 13/11, 2009 at 1:5 Comment(1)
The second in the answer provided by schnaader contains the code in peices. Thanks for posting your code. I;m sure this will help many people.Vikkivikky
R
10

"Only the first page of the document is drawn. Subsequent pages can be drawn using the AddImageToChain method."

From here

An example how to use AddImageToChain can be found here

Romain answered 13/11, 2008 at 10:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.