2012-06-19 30 views
0

我有一個ASP.NET應用程序(它使用DevExpress v 10.2)。在頁面上有一個名爲PRINT的按鈕。當點擊該按鈕時,應用程序應該: 1.從其數據庫提取文件。該文件爲PDF或JPEG(應用程序僅在運行時才知道它的類型) 2.打印輸出文件。一些'預覽'應該顯示給用戶在這期間如何從頁面打印PDF或圖像

問題是 - 如何實現這個(項目'2')?有一個衆所周知的方法來打印使用JavaScript像下面的圖片:

function DisplayPrintPopup(html) { 
    var win = window.open('', 'popup', 'toolbar=no,menubar=no,width=500,height=500,scrollbars=yes'); 
      self.focus(); 
      win.document.open(); 
      win.document.write('<head><style></style></head><body>' + html + '<style></style></head><body>'); 
      win.document.close(); 
      win.print(); 
      win.close(); 
} 

這可能是好的我。但是當一個文件是PDF時該怎麼辦?

回答

2

這只是從你頁面打印件,其中strid =要打印的元素的ID,

之前打印可以查看預覽:

function CallPrint(strid) { 

    var prtContent = document.getElementById(strid); 
    var WinPrint = window.open('', '', 'letf=0,top=0,width=800,height=600,toolbar=0,scrollbars=0,status=0'); 
    WinPrint.document.write(prtContent.innerHTML); 
    WinPrint.document.close(); 
    WinPrint.focus(); 
    WinPrint.print(); 
    WinPrint.close(); 
} 

http://forums.asp.net/t/1034884.aspx/1