【发布时间】:2020-12-15 10:25:28
【问题描述】:
我正在使用 Laravel 开发内部网。
我生成了一个 PDF,并希望在网络上的打印机上自动打印此 PDF。 生成 PDF 不是问题,但我找不到打印它的方法。 我们使用的是 IBM 的 Power Server,所以 laravel-printing 包无法工作。
有人有什么想法吗?
【问题讨论】:
我正在使用 Laravel 开发内部网。
我生成了一个 PDF,并希望在网络上的打印机上自动打印此 PDF。 生成 PDF 不是问题,但我找不到打印它的方法。 我们使用的是 IBM 的 Power Server,所以 laravel-printing 包无法工作。
有人有什么想法吗?
【问题讨论】:
使用 javascript 打印它。
<script>
function PrintElem(elem)
{
var mywindow = window.open('', 'PRINT', 'height=400,width=600');
mywindow.document.write('<html><head><title>' + document.title + '</title>');
mywindow.document.write('</head><body >');
mywindow.document.write('<h1>' + document.title + '</h1>');
mywindow.document.write(document.getElementById(elem).innerHTML);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10*/
mywindow.print();
mywindow.close();
return true;
}
</script>
通过单击按钮或其他方式调用该函数(因为您在生成 pdf 后调用该函数)
【讨论】: