如何从页面打印PDF或图像

时间:2012-06-19 14:09:29

标签: asp.net

我有一个ASP.NET应用程序(它使用DevExpress v 10.2)。页面上有一个名为PRINT的按钮。单击按钮时,应用程序应: 1.从其数据库中提取文件。该文件是PDF或JPEG(应用程序仅在运行时知道其类型) 2.打印文件。在此

期间,应向用户显示一些“预览”

问题是 - 如何实现这个(项目'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时该怎么办?

1 个答案:

答案 0 :(得分: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

相关问题