Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 330
Alexandre Brisebois Avatar asked Nov 13 '08 10:11

Alexandre Brisebois


2 Answers

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();
like image 118
Chris Smith Avatar answered Nov 09 '22 23:11

Chris Smith


"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

like image 38
schnaader Avatar answered Nov 09 '22 22:11

schnaader