1. 程式人生 > >在web伺服器上,有些pdf, 怎麼讓使用者在頁面上點選一個按鈕,就直接列印?

在web伺服器上,有些pdf, 怎麼讓使用者在頁面上點選一個按鈕,就直接列印?

<a target=_blank href="http://bbs.jatools.com/redirect.php?tid=1732&goto=lastpost#lastpost" style="word-wrap: break-word; color: rgb(0, 0, 0); text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 13.3333339691162px; line-height: 21.3333339691162px;"><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script>
function printReport() {
	var printer = document.getElementById('printer_list').value;
	var url = getPDFUrl();
	document.getElementById("jatoolsPrinter").printDocument(url, {
				printer : printer
			});
}
function getPDFUrl() {
	return "a.pdf" // 給出pdf地址,可以是一個靜態pdf檔案,也可以動態生成的一個pdf
}
function getAvailablePrinters() {
	var printer_list = document.getElementById('printer_list');
	var printers = document.getElementById("jatoolsPrinter").getPrinters(); // 印表機列表是一個字串陣列
	if (printers) {
		for (i = 0; i < printers.length; i++)
			printer_list.options[i + 1] = new Option(printers[i], printers[i]);
		printer_list.options[0].selected = true;
	}
}
</script>
</head>
<body onload='getAvailablePrinters()' style='padding:30px;'>
<select id="printer_list">
    <option>--預設--</option>
</select>
<input type="button" value="列印pdf報表" onClick="printReport()">
<object id="jatoolsPrinter" codebase="jatoolsPrinter.cab#version=5,4,0,0"
        classid="clsid:B43D3361-D075-4BE2-87FE-057188254255" width="0" height="0">
</object>
</body>
</html>
</a>
完成後的效果: