Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom printing API #4911

Closed
rogerwang opened this issue May 30, 2016 · 61 comments
Closed

Custom printing API #4911

rogerwang opened this issue May 30, 2016 · 61 comments

Comments

@rogerwang
Copy link
Member

As proposed in #1263 (comment)

@Andrew-Gee
Copy link

Andrew-Gee commented May 30, 2016

How about something 'simple', like a print function on the nw Window:

nw.Window.get().print({
   printerName: 'Laser100',
   preview: false,
   headers: false
});

Would also need a function to return a list of all available printers.

@kailniris
Copy link

We are working on a project where printing is pretty important and it would be awesome to use an API like this. Here is a list of feature requests:

  • Get available printers and send job one of this printer
  • Show preview or don't (there is already an option for kiosk print but to turn on and off kiosk print requires restart the app which can be problematic on some cases where some reports or invoices requires print preview and some don't).
  • Save to pdf (or the simple solution for this is to use an installed pdf printer as a regular printer)
  • Basic printing options: page size, page orientation, margin, pages to print, number of copies, turn of header and footer
  • A solution for non blocking print preview like open a new window on a new render process and show data in that new window then print it.

Thanks You!

@AndryBray
Copy link

@rogerwang Just saw electron supports win.printToPDF(options, callback).
Any chance to build something like that?

@rogerwang
Copy link
Member Author

@AndryBray it will be included.

Thanks to all the suggestions.

rogerwang added a commit that referenced this issue Jun 1, 2016
Support nw.Window.print(options), where options could have:
'pdf_path' - output filename if printing to pdf
'printer' - name of the printer
'headerFooterEnabled' - whether to turn on header and footer

nw.Window.getPrinters(GetPrintersCallback callback)
where callback is a function to receive an array of printer information.
rogerwang added a commit that referenced this issue Jun 1, 2016
Support nw.Window.print(options), where options could have:
'pdf_path' - output filename if printing to pdf
'printer' - name of the printer
'headerFooterEnabled' - whether to turn on header and footer

nw.Window.getPrinters(GetPrintersCallback callback)
where callback is a function to receive an array of printer information.
@rogerwang
Copy link
Member Author

NW v0.14.6 LTS released with custom printing API http://nwjs.io/blog/v0.14.6/

@kailniris
Copy link

This was fast! Thanks You very much!

I tested it and there is two things i can't get to work:
Clould not get the printer and pdf_path options to work. Landscape and headerFooterEnabled works fine.
var win = nw.Window.get();
win.print({'printer': 'SHARP AR-5620N', 'landscape': false, 'headerFooterEnabled': false });
win.print({'pdf_path': 'c:\asd.pdf', 'landscape': false, 'headerFooterEnabled': false })

win.getPrinters returned this printer in one of its array->objects:
deviceName: "SHARP AR-5620N"

It prints without print dialog but to the printer I last set in the print dialog before not to the printer option value path.

Windows 10, v0.14.6, the printer is a network printer, can print to it in chrome print dialog

@rogerwang
Copy link
Member Author

@kailniris I made a fix and verify it working: http://dl.nwjs.io/live-build/06-02-2016/nw14-d775bb5-1a287bf-2a9e6e1-5a26102/v0.14.7/

Would you try it again and see if there are other issues? Thanks.

@kailniris
Copy link

Hello,
I tried out the new build here are the test results:
'SHARP AR-5620N' is a network printer
'\OFFICE-5\HP LaserJet P2035' is a windows shared printer

win.print({'printer': 'SHARP AR-5620N'}); works fine as intended

win.print({'printer': 'SHARP AR-5620N2'}); uses default printer set in chrome print dialog cuz this printer does not exists, works as intended

win.print({'printer': '\OFFICE-5\HP LaserJet P2035'}); does NOT work but i can use it in print dialog

win.print({'pdf_path': 'C:\asd.pdf'}) does NOT work, does not print to default printer and does not create the pdf in this location, nor any
Additional info:
I tried the following paths:
win.print({'pdf_path': 'C:\Dev'})
win.print({'pdf_path': 'C:\Dev\test.pdf'})
Also If I open the app and i use print to pdf in print dialog, it wokrs fine, but after i use the win.print({'pdf_path': 'C:\asd.pdf'}) the print to pdf function in the print dialog no longer works.

headerFooterEnabled: works fine

landscape: works fine

shouldPrintBackgrounds: works fine

mediaSize: works fine

Windows 10, v0.14.7

@rogerwang
Copy link
Member Author

I tried it with something like E:/1.pdf and it works. Could you please
check again with forward slash?

On Thu, Jun 2, 2016, 3:08 PM kailniris notifications@github.com wrote:

Hello,
I tried out the new build here are the test results:
'SHARP AR-5620N' is a network printer
'\OFFICE-5\HP LaserJet P2035' is a windows shared printer

win.print({'printer': 'SHARP AR-5620N'}); works fine as intended

win.print({'printer': 'SHARP AR-5620N2'}); uses default printer set in
chrome print dialog cuz this printer does not exists, works as intended

win.print({'printer': '\OFFICE-5\HP LaserJet P2035'}); does NOT work but i
can use it in print dialog

win.print({'pdf_path': 'C:\asd.pdf'}) does NOT work, does not print to
default printer and does not create the pdf in this location, nor any
Additional info:
I tried the following paths:
win.print({'pdf_path': 'C:\Dev'})
win.print({'pdf_path': 'C:\Dev\test.pdf'})
Also If I open the app and i use print to pdf in print dialog, it wokrs
fine, but after i use the win.print({'pdf_path': 'C:\asd.pdf'}) the print
to pdf function in the print dialog no longer works.

headerFooterEnabled: works fine

landscape: works fine

shouldPrintBackgrounds: works fine

mediaSize: works fine

Windows 10, v0.14.7


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#4911 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AAKGGXRFFBdu-iw_2eUlcri5wCpMV3fTks5qHoGCgaJpZM4Ipfyu
.

@kailniris
Copy link

kailniris commented Jun 2, 2016

Confirmed it works with win.print({'pdf_path': 'C:/Dev/test.pdf'})

Could the \ slashes the problem with the "\OFFICE-5\HP LaserJet P2035" printer name?

Another thing i found out if i use the win.print() function the regular print (dialoged one) print to pdf will not work till nw restart.

@jasminmif
Copy link

jasminmif commented Jun 2, 2016

Im trying to print PDF directly to a printer:
i run the app in kiosk printing:
nw.exe --kiosk-printing ..\

And the only option thats printing is the win.print({}) ( function printDialog() ), others just show the printing Layout just like in chrome, and it gets hidden automaticly and no job to the printer gets sent.

Im running: nwjs-sdk-v0.14.7-win-x64.zip

// Not Working
function printerNamePrint() {
    console.log('printerNamePrint');
    var printerName = "HP LaserJet Professional P 1102w_1";
    win.print({
        printer: printerName, 
        pdf_path: filePath
    });
}
//Not Working
function pritnerDoc() {
    console.log('printerDoc');
    win.print({
        pdf_path: filePath
    });
}
//Working
function printDialog(){
    win.print({});
}
//Working
function printName() {
    win.print({
        printer: "HP LaserJet Professional P 1102w_1", 
    });
}

@Andrew-Gee
Copy link

It seems to remember the last printer passed in, and disregards future printer values.

@notsospecial1
Copy link

@rogerwang, @Gimmeaphatbeat, @jasminmif, @kailniris

Custom "Silent" printing -- win.print({options}) seems to be developing nicely. But "normal" (HTML5 print dialog window) printing has been lost..... at least on Windows-32.... hasn't it?
Neither win.print() nor win.print({}) allow interaction with the print dialog at this point (in latest nightlys of nw-14x, 15x and 16x).

@kailniris
Copy link

@notsospecial1
Try Window.print() for default print dialog.

@notsospecial1
Copy link

@kailniris

" Window.print() is not a function "

@kailniris
Copy link

@notsospecial1
Sorry typo. I ment window.print()

@notsospecial1
Copy link

@kailniris

Great !! It works and I can go back and forth between dialoged- and silent- printing. Now I need to figure out exactly why it works (I've never been a fan of naming everything the same in requires, function definitions, etc -- for just this reason).

I assume this has also solved your issue posed above, "Another thing i found out if i use the win.print() function the regular print (dialoged one) print to pdf will not work till nw restart".

Thanks again

@kailniris
Copy link

@notsospecial1
I am no expert but the window object is the chrome basic window object. The win object is what you get from var win = nw.Window.get(); so basicly is possible to do monkey.print(obj) too.
My problem is a bug. If you use the nw.js save to pdf function you can't save to pdf from the regular print dialog. Try it out.

@notsospecial1
Copy link

@kailniris

Works fine for me ( Win 10 on old 32-bit Win XP => Win 7 => Win 10 Sony Vaio).
Incidently, the win.getPrinters(callback) does not find the "save to pdf" choice -- it lists 10 "printers" but the window.print() dialog shows 11 -- including "save to pdf" and allows modification (orientation, etc) before saving to a pdf file. As I mentioned, I can go back and forth between silent- and dialogued- printing with no problems, so far. I will dig further into possible conflicts/glitches as time allows. I am currently testing on the most recent "win-ia32 nw;js 16.0 beta candidate 1" before checking out the most recent 14.x and 15.x builds which are all supposed to include the "Custom" print API.

@notsospecial1
Copy link

@kailniris

Here is my quick-and-dirty index.html file....

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test Custom Printer extension</title>
<script>
var win = nw.Window.get();
function pCallBack(printJob) {
console.log(JSON.stringify(printJob));
};
var options = {'printer': 'Canon MP970 series Prnter', 'landscape': true,
'headerFooterEnabled': true } ;
</script>
</head>
<body>
<input type="button" value="Get Prntrs" onClick="win.getPrinters(pCallBack)"/>
<input type="button" value="Silent Print" onClick="win.print(options)"/>
<input type="button" value="Normal Print" onClick="window.print()"/>
</body>
</html>

Actually, dirty it may be, but hardly quick --- it took me 15 minutes to get the code showing....

@kailniris
Copy link

@notsospecial1
The getprinters function won't return the savs to pdf 'printer'. If you want to use the savetopdf dialog print option in in win.print you have to use win.print({'pdf_path': 'C:/Dev/test.pdf'}).
Use this function to print to pdf to a location on your disk then the regular print to pdf in the print dialog will no longer work.

@gerdus
Copy link

gerdus commented Jun 4, 2016

The Save To PDF using normal print not working til app restart can be "solved" by running:
win.print({'pdf_path': ''})
Which will prompt for a PDF location so isn't a true workaround. Subsequent print to pdf using default dialog works then.
Storing the printer settings before the custom printing api call and restoring them after would probably solve this.

@notsospecial1
Copy link

@gerdus

"Storing the printer settings before the custom printing api call and restoring them after would probably solve this."

I have been trying to figure this out.... I presume the "printer" whose "settings" would be stored and restored would be the one utilized for silent printing. But I have no clue as to the storing/restoring code (win 10 -ia32). Are we talking the "preferences" or "properties" as shown in the devices and printers settings? And how is it done programmatically? (i.e. in javascript)? Any clues would be welcome, and thank you for the "pseudo-workaround" solution.

@rogerwang
Copy link
Member Author

To all: I just fixed the "print to pdf" issue in normal print dialog. It will be available in the next nightly build.

@fanchou using 'pdf_path' is supposed to specify the output pdf path when you print the current page...

@kailniris
Copy link

@gerdus This is a bit misleading, the only reason why win.print({'pdf_path': ''}) prompts a dialog cuz the last used option in print dialog was savetopdf. If you set a printer in the chrome print dialog then you call win.print({'pdf_path': ''}) then the doc will be printed to the printer you lastly set.

@rdtsc
Copy link

rdtsc commented Jun 6, 2016

@rogerwang: When printing silently (e.g., to PDF or directly to some printer), the Chromium print dialog pops up for a short while and then disappears once the job is spooled. This is the case for Windows, at least.

Silent mode should really be silent without any additional modals spawning. Would it be possible to implement an additional boolean flag like show_print_dialog in win.print that when set to false would forcefully prevent the Chromium print modal from spawning when user interaction is not required?

Currently, a workaround is to spawn another hidden NW.js window and print from there, but that's a little ugly.


Behavior:

Source:
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Print Test</title>
    <style>@media print {button {display: none}}</style>
    <script>
    function printToPdf()
    {
      nw.Window.get().print({pdf_path:'c:/foo.pdf', headerFooterEnabled:false});
    }
    </script>
  </head>
  <body>
    <pre>Lorem ipsum dolor sit amet, consectetur adipisicing.</pre>
    <button onclick="printToPdf()">Print to PDF</button>
  </body>
</html>

@jasminmif
Copy link

@rdtsc Does it prints, cause when i use the same code, it does not. Correct me if im wrong but

pdf_path is the path of the PDF File you want to print ?

@petermeester
Copy link

petermeester commented Sep 12, 2016

Hi, the new printing feature is very nice . We are using it in our application. We developed an application for our delivery partners so they can receive orders from our website which will be automatically printed. Works fine. We can't push multiple printjobs at once because we first create a local PDF file received from our API but we have settle this using a custom function which check every five seconds for new printjobs and execute one printjob at a time (some kind of print queue).

In our application the client can choose a normal A4 printer and a POS printer. We noticed that when a printjob is executed, the default printer on Windows has been changed. Is this a bug in Chromium? When we execute the print function, we defined the printer name. Is there a way to get the default printer and set the default printer again after the printjob has been executed?

See my issue #5300

@conceptualspace
Copy link

conceptualspace commented Dec 9, 2016

we're trying to use the print API to hide chrome's headers/footers, but now the print preview pops up briefly and disappears

anybody else seeing this? to be clear, we're trying to customize the print settings but are not looking for silent printing (my understanding is that is provided independently by kiosk-printing flag)

nw 0.19.1; also tried 0.16.4

@conceptualspace
Copy link

maybe result of _option["autoprint"] = true;.. can this be exposed as option?

@maschinenzeitmaschine
Copy link

maschinenzeitmaschine commented Feb 4, 2017

after running in circles for quite a while (there are so many threads about printing that all reference each other, it's almost kafkaesque), two questions:

  • how does this new printing api work? i did find a lot of details about it but no basic example on how it's actually used... how would i silently print the contents of a string variable?
  • does it run stable? i'm asking since i'm currently using the code below and at least that does make my whole program hang up after some time (using nwjs-sdk-v0.20.0-osx-x64).

thanks a lot for any help!!!
k

in html file:
<iframe name="printframe" id="printframe" style="display: none;"></iframe>

in javascript:
document.getElementById('printframe').contentWindow.document.write(myString)); window.frames['printframe'].print();

@rdtsc
Copy link

rdtsc commented Feb 5, 2017

@KarlKrach: AFAIK, the scriptable printing API only works with NWWindow instances.

You can see some basic sample code in my earlier comment.

As mentioned in my comment, I use a hidden window to work around the brief print dialog popup issue. I've got a Windows app in production that uses something similar to this technique without user complaints:

nwjs-4911-ss

package.json:

{
  "name": "nwjs-print-demo", 
  "main": "index.html"
}

index.html:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>NW.js Silent Printing Demo</title>
  </head>
  <body>
    <textarea id="payload" placeholder="HTML"></textarea>
    <button id="print">Print</button>
    <script>
      document.addEventListener('DOMContentLoaded', () => {
        const $ = document.querySelector.bind(document);
        const textarea = $('#payload');

        $('#print').onclick = () => {
          const data = textarea.value.trim() || 
            '<img src="https://nwjs.io/img/logo.png">';

          const payload = `data:text/html,${encodeURI(data)}`;

          nw.Window.open(payload, {show: false}, (win) => {
            win.on('loaded', () => {
              const filename = 'result.pdf';

              win.print({
                pdf_path: filename, 
                headerFooterEnabled: false
              });

              win.close();
              nw.Shell.openItem(filename);
            });
          });
        };
      });
    </script>
  </body>
</html>

IIRC, I use Window.postMessage paired with an inject_js_start script (see nw.Window.open) since I have to support like 30 report types based on different templates located on the fs.

For what it's worth, if you need more advanced control over your PDFs, I'd recommend taking a look at wkhtmltopdf provided that it fits your redistributable size allowance, if any.

@maschinenzeitmaschine
Copy link

maschinenzeitmaschine commented Feb 5, 2017

... it did take me some time to understand the magic happening in your code - but since i did, it works really well. again: thank you so much!!

one question left: when printing, the screen briefly freezes for like a second or so - which will not be much of an issue in most of the cases but since i have a continous animation going on, it does look quite irritating. i tried circumventing this by introducing a setTimeout which, according to this link https://javascriptweblog.wordpress.com/2010/06/28/understanding-javascript-timers/ should defer execution to a low priority queue - but that did not do the trick.
is there anything i could do about this?

apart, just in case someone else should have the same questions as me:

@TheJaredWilcurt
Copy link
Member

May 31, 2016

AndryBray: Just saw electron supports win.printToPDF(options, callback). Any chance to build something like that?
rogerwang: it will be included.

Is there a way to run a callback for when a print finishes. If so it isn't documented:

Would it be possible to add this feature, or, if it already exists, have the documentation updated to reflect that.

@kailniris
Copy link

@TheJaredWilcurt
Is not printing api synchronous?

@rogerwang
Copy link
Member Author

Yeah, it is synchronous so there is no callback...

@alexandreprado
Copy link

Hi guys,

Even if I set 'show' to false in the open window options, when I call 'print' to a specific or default printer, the window shows up for a few seconds. I couldn't find a way to keep this window hidden, is there a fix for it or something?

Behavior:

silent printing

Source:

package.json
{ "name": "JustRestaurante", "main": "index.html" }

index.html

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>NW.js Silent Printing Demo</title>
</head>
<body>
<textarea id="payload" placeholder="HTML"></textarea>
<button id="print">Print</button>
<script>
    document.addEventListener('DOMContentLoaded', function () {
        var $ = document.querySelector.bind(document);
        const textarea = $('#payload');
        $('#print').onclick = function() {
            var data = textarea.value.trim();
            var payload = `data:text/html,${encodeURI(data)}`;
            nw.Window.open(payload, {show: false}, function (win) {
                win.on('loaded', function () {
                    win.print({
                        printer: 'Photosmart_D110_series'
                    });
                    win.close();
                });
            });
        }
    });
</script>
</body>
</html>

I'm using NW.js v0.20.3 SDK on macOS 10.12.3, btw.

Thanks!

@maschinenzeitmaschine
Copy link

hi,
sorry to ask again but this is becoming quite a problem for me: thanks to rdtsc and his post #4911 (comment) i now do manage to print silently BUT everytime i do so, my whole app freezes for about 4 seconds.
is there anything i can do about this? is this because the printing api is synchronous? i did try to run printing from another window but to no avail, it always puts the whole app on hold...
thanks for any help with this!!
karl

@acicali
Copy link

acicali commented Jun 14, 2017

@KarlKrach - since printing is synchronous, it will lock the main UI thread. Moving your print routine to a web worker may resolve your issue.

@kailniris
Copy link

@KarlKrach Open a new window in a new render process (new_instance). You can safely print from there it wont freeze other windows in different threads.

@maschinenzeitmaschine
Copy link

maschinenzeitmaschine commented Jun 14, 2017

hi! this was quick, thank you so much for helping me!!!
new_instance does indeed solve the lag and i'm almost there but i'm afraid i do not fully understand the concept... what i did get to work:

from my main script i just open up the new window with nw.Window.open(toprinter, {show: true, new_instance: true});

the "toprinter"-string is a complete html-site including:
<script>window.print( { printer: "EPSON_TM_T20II", headerFooterEnabled: false }); window.close();</script></body></html>

now, that does work and fixes the lag but:

  • i can use window.print but that gives me the printing dialogue. if i try to use win.print however, it says "win is not defined". it seems this newly opened window doesn't use nwjs?
  • also it stops working as soon as i open the window with show: false.

or do i get the whole concept wrong?
again, thank you so much for your help!
karl

@rdtsc
Copy link

rdtsc commented Jun 15, 2017

@KarlKrach: it's been a while, but it might be that the Node context is not made available to the standalone data URI instance because of the lack of the node-remote pattern in the manifest. Regardless, I can't seem to get it to work either way with nw.Window.open.

Since #4418 is still open, you may want to try spawning an HTML file with new_instance:true and using it as a print container for a workaround. Alternatively, just save your print job files to a temp directory along with a bit of JS to invoke NW's print API. Below is a very crude example which should demonstrate the basic idea.

capture

package.json

{
  "name": "nwjs-print-test",
  "main": "index.html"
}

index.html

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>NW.js Print Test</title>
    <script>
      function getRandomString() {
        return Math.random().toString(32).slice(2);
      }

      function printAsync(html, printOpts, callback) {
        this.id = ++this.id || 1;

        const channel =
          new BroadcastChannel(`${nw.App.manifest.name}-print-job-${this.id}`);

        channel.onmessage = (event) => {
          switch(event.data) {
            case 'ready': {
              channel.postMessage(html);
            } break;

            case 'done': {
              channel.close();
              callback();
            } break;
          }
        };

        printOpts = encodeURIComponent(JSON.stringify(printOpts));

        nw.Window.open(`print.html?id=${this.id}&opt=${printOpts}`, {
          show: true,
          new_instance: true
        });
      }

      document.addEventListener('DOMContentLoaded', () => {
        const printBtn = document.querySelector('#print');

        printBtn.onclick = () => {
          printBtn.disabled  = true;
          printBtn.innerText = 'Printing in progress...';

          printAsync(getRandomString().repeat(10000), {
            pdf_path: `./tmp/${getRandomString()}.pdf`,
            headerFooterEnabled: false
          }, () => {
            printBtn.disabled  = false;
            printBtn.innerText = 'Print';
          });
        };

        const counter = document.querySelector('#counter');
        setInterval(() => counter.innerText = (+counter.innerText + 1), 50);
      });
    </script>
  </head>
  <body>
    <p>App UI is responsive: <span id="counter">0</span></p>
    <button id="print">Print</button>
  </body>
</html>

print.html

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Printing...</title>
    <script>
      document.addEventListener('DOMContentLoaded', () => {
        const url = require('url'),
              qs  = require('querystring'),
              win = nw.Window.get();

        const {id, opt} = qs.parse(url.parse(window.location.href).query);

        const channel =
          new BroadcastChannel(`${nw.App.manifest.name}-print-job-${id}`);

        channel.onmessage = (event) => {
          document.body.innerHTML = event.data;

          setTimeout(() => {
            win.print(JSON.parse(opt));
            setTimeout(() => {
              channel.postMessage('done');
              channel.close();
              win.close();
            }, 1000);
          }, 1000);
        };

        channel.postMessage('ready');
      });
    </script>
  </head>
  <body style="word-wrap: break-word">
  </body>
</html>

@maschinenzeitmaschine
Copy link

hi rdtsc,
... wow!
to be honest, it will take me some time to understand what you are doing there - i was hoping for this new_instance approach since i almost got that to work already and it did not seem that complicated but ok... if this is a known bug i guess there won't be much i can do about it.
so, for the time being, thank you so much for helping me! i'll get back once i understand your code!
all the best
karl

@maschinenzeitmaschine
Copy link

again, hi rdtsc.
i still do not fully understand your magic there but let me just say again: THANK YOU!!!
this works perfectly well. silent, lag-free printing, yay! and actually you really saved my whole program with this since in the meantime i found out, that this printing lag would not only freeze my screen but also mess with some data coming from an arduino - which would have been a serious dealbreaker for my project.
so, again! THANK YOU SO MUCH!!!
all the best!
karl

ps.: if i can get you a crate of beer for this, let me know!!!

@Christywl
Copy link
Contributor

So this issue is resolved now?

@elouf
Copy link

elouf commented Nov 15, 2017

Hi,

I'm trying to print a jpg file and i get some troubles...
The preview is well generated but the printed page (as the pdf preview) stay blank...

capture d ecran 2017-11-15 a 10 31 20

capture d ecran 2017-11-15 a 10 35 31

                        let filename = 47_abeille.jpg;
                        let filePath = global.__dirname + '/_content/ressources/reperes/' + filename;
                        nw.Window.open('file://' + filePath, {
                            show: true,
                            new_instance: false,
                            width: 800,
                            height: 600
                        }, function (win) {
                            win.on('loaded', function () {
                                try {
                                    win.print({
                                        autoprint: false,
                                        landscape: true,
                                        headerFooterEnabled: true,
                                        headerString: filename,
                                        footerString: ''
                                    });
                                    win.close();
                                } catch (exception) {
                                    console.log('print exception', exception);
                                }
                            });
                        });

Have you any advice about this issue?
Thanks

@Christywl
Copy link
Contributor

It works fine for me on Mac with nwjs-sdk-v0.26.6.

<html>
<script>
 let filename = 'myw3schoolsimage.jpg';
                        let filePath = global.__dirname + '/' + filename;
                        nw.Window.open('file://' + filePath, {
                            show: true,
                            new_instance: false,
                            width: 800,
                            height: 600
                        }, function (win) {
                            win.on('loaded', function () {
                                try {
                                    win.print({
                                        autoprint: false,
                                        landscape: true,
                                        headerFooterEnabled: true,
                                        headerString: filename,
                                        footerString: ''
                                    });
                                    win.close();
                                } catch (exception) {
                                    console.log('print exception', exception);
                                }
                            });
                        });
</script>
</html>

screen shot 2017-11-16 at 10 44 23 am

@elouf
Copy link

elouf commented Nov 16, 2017

I just tried with nwjs-sdk-v0.26.6 and get the same issue...
It's so frustrating! I really don't understand what is happening...

@stale
Copy link

stale bot commented Nov 11, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 11, 2018
@stale stale bot closed this as completed Nov 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests