Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/415.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javascript或jquery打印pdf_Javascript_Pdf_Printing - Fatal编程技术网

使用javascript或jquery打印pdf

使用javascript或jquery打印pdf,javascript,pdf,printing,Javascript,Pdf,Printing,当我点击print.gif按钮时,我需要打印一个.pdf文件(我用jasperReport生成并保存在服务器上)。 现在我发现这个解决方案适用于Firefox,但不适用于IE function printPdf(){ var url= document.getElementById('_url').value; newwindow=window.open(); newdocument=newwindow.document; newdocument.wri

当我点击print.gif按钮时,我需要打印一个.pdf文件(我用jasperReport生成并保存在服务器上)。 现在我发现这个解决方案适用于Firefox,但不适用于IE

function printPdf(){    
  var url= document.getElementById('_url').value;    
  newwindow=window.open();  
  newdocument=newwindow.document;   
  newdocument.write('<embed   type="application/pdf"  src="'+url+'"
       id="pdfDocument"   height="100%" width="100%" ></embed> <SCR'+'IPT
       LANGUAGE="JavaScript">window.print();window.close();</SCR'+'IPT>'); 
}
函数printPdf(){
var url=document.getElementById(“U url”).value;
newwindow=window.open();
newdocument=newwindow.document;
newdocument.write('window.print();window.close();');
}
我还尝试了
document.close()
window.focus()
window.print()
window.close(),但它们不起作用


我读了很多主题,但我找不到解决这个问题的方法

我认为问题在于内容还没有加载?
我在IE8中也有同样的问题。我必须保存文档,重新打开,打印,然后再次关闭窗口。

我认为问题在于内容尚未加载?
我在IE8中也有同样的问题。我必须保存文档,重新打开,打印,然后再次关闭窗口。

在html中创建
iframe

<iframe id="pdf-iframe">

在html中创建
iframe

<iframe id="pdf-iframe">

如果您想使用真正的打印机在纸上打印.pdf,那么最好使用不同的插件和解决方案,了解如何通过jQuery打印pdf。此外,堆栈上溢出可能会有所帮助。祝你好运@Thara-这听起来是个不错的答案。我会投赞成票的。我尝试了你链接的教程。但我总是打印空白页!PrintJs非常好,如果您想使用真正的打印机在纸上打印.pdf,那么最好使用不同的插件和解决方案,了解如何通过jQuery打印pdf。此外,堆栈上溢出可能会有所帮助。祝你好运@Thara-这听起来是个不错的答案。我会投赞成票的。我尝试了你链接的教程。但我总是打印空白页!PrintJs非常好,这会触发以下错误:“阻止具有原点的帧访问交叉原点帧”这会触发以下错误:“阻止具有原点的帧访问交叉原点帧”