2008-11-13 14 views
6

Actualmente estoy usando abcPDF 7 para convertir HTML a PDF. Esto se hace a través de una página ASPX donde anulo el método Render.abcPDF 7 convertir HTML a PDF pero solo obtener la primera página convertida

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(); 

Esto funciona perfectamente para la primera página, pero luego trunca la página y no continúa representando las páginas restantes.

¿Alguien sabe por qué se detiene después de una página?

Respuesta

10

"Solo se dibuja la primera página del documento. Las páginas siguientes se pueden dibujar utilizando el método AddImageToChain".

De here

Un ejemplo de cómo utilizar AddImageToChain se puede encontrar here

11

Tuve este mismo problema exacto. La respuesta es usar el encadenamiento, pero la página provista en la respuesta anterior no muestra exactamente cómo hacer esto. Aquí hay un ejemplo de mi sitio: Tenga en cuenta que la variable htmlOutput es una variable en mi objeto que toma el htmlOutput que quiero mostrar. Lo recojo de la página simplemente presionando html directamente en la variable, o si es para la página actual, ejecuto la invalidación protegida Render vacío (salida HtmlTextWriter) para la página, empujando el contenido de la Render en esta variable 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(); 
+1

El segundo en la respuesta proporcionada por schnaader contiene el código en términos. Gracias por publicar tu código. Estoy seguro de que esto ayudará a muchas personas. –

Cuestiones relacionadas