views:

2727

answers:

2

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?

+6  A: 

"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

schnaader
+3  A: 

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();
Chris Smith
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.
Alexandre Brisebois