我认为Chrome和Firefox对DOM的解释正在干扰我的工作。我正在尝试从浏览器(动态创建)打印PDF,因为我无法在打印HTML页面时正常打印页眉和页脚。现在,我只是从php页面使用fpdf发送PDF,并使用工具栏或右键单击打印,但现在客户想要一个按钮来启动打印对话框,但当然不会打印PDF之外的任何内容....所以我嵌入了它:
<embed
type="application/pdf"
src="print_pdf.php"
id="pdfDocument"
width="100%"
height="100%" />
同时一个按钮的 onClick 被称为
<script type="text/javascript">
function printDocument(documentId) {
((function(){return document.getElementById(documentId);})()).print();
//Wait until PDF is ready to print
if (typeof document.getElementById(documentId).print == 'undefined') {
setTimeout(function(){printDocument(documentId);}, 1000);
} else {
var x = document.getElementById(documentId);
x.print();
}
}
</script>
当documentID = "pdfDocument"时
这在IE9中很好用,但是Chrome和Mozilla都会出现“Uncaught TypeError:Object#没有print方法”的错误。
所以我尝试使用thinking嵌入,认为它导致了在Chrome中不正确的对象解释:
<object data="print_pdf.php" type="application/pdf" width="100%" height="100%" id="pdfD2">
alt: test.pdf
并在onClick中以相同方式调用,其中documentID =“pdfD2” … “未捕获的TypeError:对象#没有方法'print'”
然后我尝试了一个iframe: … “未捕获的TypeError:对象#没有方法'print'”
我感到非常沮丧,因为Chrome是我的首选…我甚至禁用了chrome的内置PDF查看器并使用了Adobe 10.xxx.. ARGH!!!
提醒一下,我的简单按钮标签如下:
<input type="button" value="Print Rx" onclick="printDocument('pdfDocument')">
<input type="button" value="Print Rx2" onclick="printDocument('pdfD2')">
<input type="button" value="Print Rx3" onclick="printDocument('pdfD3')">