-2

look ...

i have a server installed on a linux machine ( RHEL 7 + PHP ) . where i have a server called " Printer " acessible by : 192.168.0.48/Printer.

i have a page php at my server that create a file with some ZPL LANGUAGE inside on this location

' \Printer\documents\'

its possible to send the file that has been generated to the printers of side-client via " window.open() " ?

or for example , get the content of this file and insert of this function ?

   <script type="text/javascript">
   function printZpl(zpl) {
   var printWindow = window.open();
   printWindow.document.open('text/plain')
   printWindow.document.write(zpl);
   printWindow.document.close();
   printWindow.focus();
   printWindow.print();
   printWindow.close();
  }
</script>
Joe Doe
  • 57
  • 10

1 Answers1

0

You can pass string to encodeURIComponent() at function call and set string as .textContent of <pre> element at opened window to preserve new line characters for at print() call

<!DOCTYPE html>
<html>

<head>
</head>

<body>
  <button id="print">Print file</button>
  <script type="text/javascript">
    function printZpl(zpl) {
      var printWindow = window.open(`data:text/html,<!DOCTYPE html><html><body><pre>${zpl}</pre><script>print();<\/script></body></html>`);
      printWindow.focus();
    }

    var zpl = `^XA 
^FXTest ZPL
^FS 
^FO50,100 
^A0N,89
^FDHello ZPL
^FS 
^XZ`;
document.getElementById("print")
.onclick = function() {
  printZpl(encodeURIComponent(zpl))
};
</script>
</body>

</html>

plnkr http://plnkr.co/edit/TBx0tNP0WkDODAz71qzO?p=preview

guest271314
  • 1
  • 15
  • 104
  • 177
  • but , how could get content from a file ? without need write the zpl lan guage. example , the zpl must be from a file "sample.txt". – Joe Doe Aug 04 '17 at 14:14
  • @Kamikaz0r You can use `` to upload local file and `FileReader`, `FileReader.readAsText()` to read file, or `XMLHttpRequest()` or `fetch()` to request a remote file, see [How to print all the txt files inside a folder using java script](https://stackoverflow.com/questions/37634049/how-to-print-all-the-txt-files-inside-a-folder-using-java-script/) – guest271314 Aug 04 '17 at 14:24