我正在尝试使用以下代码打印pdf:

$('#print').click(function() {

     var data = $(this).data('loc-subject');

     alert(data);
     var myWindow=window.open(data,'','width=500,height=500');

     var doc = myWindow.document;
     myWindow.document.writeln('<embed type="application/pdf" src="'+data+'" id="pdfDocument" width="100%" height="100%" />');
     myWindow.document.writeln('<script type="text/javascript">');
     myWindow.document.writeln('function load()');
     myWindow.document.writeln('{');
     myWindow.document.writeln('window.focus();');

     doc.writeln('setTimeout(function() {window.print();}, 3000);');

     myWindow.document.writeln('}');
     myWindow.document.writeln('</scr'+'ipt>');
     myWindow.document.writeln("<body onload=load()>");
     myWindow.document.writeln("</body>");

    myWindow.document.close();

});

但它有几个缺陷:

  • 在IE中无法正常工作 .

  • 在Firefox中它的工作正常,但只打印pdf的第一页 .

  • 使用Iframe也会给出相同的结果 .

PDF文件在crx上位于服务器端,我只想在链接点击时将pdf打印到客户端计算机 .

如果有人有这方面的工作代码或指导,那将对我有所帮助 .

谢谢 .