Advertisement
Guest User

Untitled

a guest
Nov 7th, 2021
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fs = nw.require('fs');
  2.         let filename = "PA_Parrot.jpg";
  3.         let fileToPrintPath = global.__dirname + '/tmp/' + filename;
  4.         let stream = fs.createReadStream(filename).pipe(fs.createWriteStream(fileToPrintPath));
  5.         stream.on('finish', function () {
  6.             nw.Window.open('http://localhost:37339/' + filename, {
  7.                 show: true,
  8.                 new_instance: false
  9.             }, function (win) {
  10.                 win.maximize();
  11.                 win.on('loaded', function () {
  12.                     try {
  13.                         win.print({
  14.                             autoprint: false,
  15.                             landscape: true,
  16.                             headerFooterEnabled: true,
  17.                             headerString: 'Compass snapshot: ' + filename,
  18.                             footerString: ''
  19.                         });
  20.                         console.log('tried');
  21.                         fs.unlinkSync(fileToPrintPath);
  22.                         win.close();
  23.                     } catch (exception) {
  24.                         console.log('print exception', exception);
  25.                     }
  26.                 });
  27.             });
  28.         });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement