简体   繁体   English

如何在没有打印对话框窗口的情况下自动打印数据内容(在Div,表格,表单等上)-(WebClientPrint-Neodynamic)

[英]How to print contents of data (on a Div, table, form etc) automatically without a print-dialog window- (WebClientPrint-Neodynamic)

I'm following through the PDF version on this URL: https://www.neodynamic.com/articles/Print-PDF-from-PHP-directly-to-default-printer-without-print-dialog/ 我正在此URL上浏览PDF版本: https : //www.neodynamic.com/articles/Print-PDF-from-PHP-direct-to-default-printer-without-print-dialog/

I have managed to have it running. 我设法使其运行。 However, I noticed that it can only print one PDF file that is saved, using the $filePath = 'files/LoremIpsum.pdf'; 但是,我注意到它只能使用$ filePath ='files / LoremIpsum.pdf'打印一个保存的PDF文件。 under the PrintPDFController.php file. 在PrintPDFController.php文件下。 Is there a way of dynamically getting contents from a database that is output on say a table as follows: 有没有一种方法可以动态地从数据库中获取内容,该数据库在表上输出如下:

        <table id="WebClientPrint">
        <tr><td>ONLY PRINT THIS PART AUTOMATICALLY</td></tr>
        </table>

        <input type="button"  onclick="How to call Table ID i.e. WebClientPrint and the default printer" value="Print" />

This means that at button click, only the contents of the table should be printed out. 这意味着单击按钮时,仅应打印表的内容。

Hello I once used this type of printing and it helped me, only the window for choosing a printer will pop up. 您好,我曾经使用过这种类型的打印,它对我有帮助,仅弹出选择打印机的窗口。

  function PrintDiv() { var contents = document.getElementById("dvContents").innerHTML; var frame1 = document.createElement('iframe'); frame1.name = "frame1"; frame1.style.position = "absolute"; frame1.style.top = "-1000000px"; document.body.appendChild(frame1); var frameDoc = frame1.contentWindow ? frame1.contentWindow : frame1.contentDocument.document ? frame1.contentDocument.document : frame1.contentDocument; frameDoc.document.open(); frameDoc.document.write('<html><head><title>DIV Contents</title>'); frameDoc.document.write('</head><body>'); frameDoc.document.write(contents); frameDoc.document.write('</body></html>'); frameDoc.document.close(); setTimeout(function () { window.frames["frame1"].focus(); window.frames["frame1"].print(); document.body.removeChild(frame1); }, 500); return false; } 

Use it like this 这样使用

 <body> <form id="form1"> <span style="font-size: 10pt; font-weight: bold; font-family: Arial">Sample code</span> <hr /> <div id="dvContents" style="border: 1px dotted black; padding: 5px; width: 300px"> <span style="font-size: 10pt; font-weight: bold; font-family: Arial">Hello, <br /> This is <span style="color: #18B5F0">Mateo</span>.<br /> Hoping that you are enjoying my articles!</span> </div> <br /> <input type="button" onclick="PrintDiv();" value="Print" /> </form> </body> 

I hope it helps you. 希望对您有帮助。

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

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