【发布时间】:2012-11-29 08:45:33
【问题描述】:
所以我认为 Chrome 和 Firefox 对 DOM 的解释让我很困惑。我正在尝试从浏览器(动态创建)打印 pdf,因为我无法正常打印 HTML 页面的页眉和页脚。现在我只是使用 fpdf 从 php 页面发送 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 # has no method 'print'”
所以我尝试使用 Thinking embed 导致 chrome 中的对象解释不正确:
<object data="print_pdf.php" type="application/pdf" width="100%" height="100%" id="pdfD2">
alt : test.pdf
并调用了相同的 onClick,其中 documentID = "pdfD2"... "Uncaught TypeError: Object # has no method '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')">
【问题讨论】: