2008-11-13 66 views
6

我目前使用abcPDF 7將HTML轉換爲PDF。這是通過一個ASPX頁面來完成的,我重寫了Render方法。abcPDF 7將HTML轉換爲PDF,但只獲得第一頁轉換

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

這適用於第一頁完美,但然後截斷頁面,並不會繼續呈現其餘頁面。

有沒有人知道它爲什麼停止一頁後?

回答

10

「只繪製文檔的第一頁,後面的頁面可以使用AddImageToChain方法繪製。」

here

一個例子如何使用AddImageToChain可以發現here

11

我有此相同的問題。答案是使用鏈接,但前面的答案中提供的頁面並不完全顯示如何執行此操作。下面是我的網站中的一個示例: 請注意,變量htmlOutput是我的對象中的一個變量,它接受我要呈現的htmlOutput。我通過將HTML直接推入變量或從當前頁面收集這些內容,從頁面中收集這些信息,我爲Page運行受保護的覆蓋無效渲染(HtmlTextWriter輸出),將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(); 
+1

schnaader提供的答案中的第二個包含peices中的代碼。感謝您發佈您的代碼。我肯定這會幫助很多人。 – 2009-11-13 02:10:42