简体   繁体   English

window.print()打印空白页面

[英]window.print() prints blank page

I get blank page while printing. 打印时我得到空白页。 The border(it may be the frame) is printed. 打印边框(可能是框架)。 But not the content inside the frame. 但不是框架内的内容。 if we manually print the new page it is getting printed correctly. 如果我们手动打印新页面,它将被正确打印。 Why this happen? 为什么会这样?

var printwindow = window.open('', '', 'fullScreen=no');
printwindow.document.write('<iframe id="docPrint" onLoad="window.print()" width="100%" height="100%" src="http://localhost:8080/hiring/docs/Keneth _1340800082258/Keneth _resume_1340800082258.pdf"></iframe>');

Since you are injecting it dynamically, try escaping / in </iframe> : 由于您是动态注入它,请尝试转义/ in </iframe>

'.....<\/iframe>'

Also apply onload to window not iframe: 同时将onload应用于窗口而不是iframe:

printwindow.onload = printwindow.print;

So try this instead: 所以试试这个:

var printwindow = window.open('', '', 'fullScreen=no');
printwindow.document.write('<iframe id="docPrint" width="100%" height="100%" src="http://localhost:8080/hiring/docs/Keneth _1340800082258/Keneth _resume_1340800082258.pdf"></iframe>');
printwindow.onload = printwindow.print;

I am not sure if browser will take your pdf file and print it, if pdf open directly in browser then there is a print option in browser pdf plugin separately. 我不确定浏览器是否会将您的pdf文件打印出来,如果pdf直接在浏览器中打开,那么浏览器pdf插件中会有一个打印选项。

That is not possible with JavaScript. 使用JavaScript是不可能的。

I don't know which language your server is written in, but it may be possible to make your PDF auto print . 我不知道您的服务器是用哪种语言编写的,但也可以自动打印 PDF。

这里的问题是来自iframe的window.print()指的是包含iFrame的窗口,而不是其中的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM