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

print - silent print [$100] #1263

Closed
ghost opened this issue Oct 30, 2013 · 49 comments
Closed

print - silent print [$100] #1263

ghost opened this issue Oct 30, 2013 · 49 comments
Assignees
Labels
Milestone

Comments

@ghost
Copy link

ghost commented Oct 30, 2013

Hi,
about the printing functionality is it stable now and mature, then i wan to ask how can i silent print the page some thing like chromes --kiosk --kiosk-printing. thanks

There is a $100 open bounty on this issue. Add to the bounty at Bountysource.

@jonathanrdelgado
Copy link

+1 - We have an external cpp file to do this right now, pretty hacky.

@rogerwang rogerwang self-assigned this Feb 20, 2014
@jardakotesovec
Copy link

+1 Where I can vote for this feature? :)

@acicali
Copy link

acicali commented Apr 17, 2014

@jonathandelgado... is your external cpp file available to others? I've been working on a node module for extended printing support, and have added some functionality, but failed at actual silent printing of the page (I can send raw text). Will you share?

@drekio
Copy link

drekio commented May 1, 2014

Any updates on this? Anyone found any usable workarounds?

@ragamo
Copy link

ragamo commented Jun 14, 2014

+1 please

@matths
Copy link

matths commented Aug 8, 2014

Any news on that? Did @jonathandelgado offer some insights about his cpp file?

@floralsystems
Copy link

No :(

I still don't have a solution for this. I've written a node module that can provide a list of installed printers and print to one. Unfortunately for me, this falls short in that I need to print the current page as webkit would render it for the selected printer. If anyone has any creative ideas of how this may be done, please let me know.

@jonathanrdelgado
Copy link

Oh, sorry, I unfollowed the issue and never got the notification, the mention pinged me.

My issue with this was regarding receipts, not really html, so I was able to get by with the windows spool API in cpp. I eventually ended up moving over to a fully OPOS module, which works much better - but wouldn't help with printing HTML. I can't release code samples for either, sorry.

In the end, this solution can only really be solved, in terms of html, my adding an additional JS API for both listing printers and initializing silent printing, which would call the functions from src/browser/printing/print_dialog_gtk.cc directly.

Good luck

@acicali
Copy link

acicali commented Aug 8, 2014

Thanks Jonathan, that's a great point in the right direction for me.

@matths
Copy link

matths commented Aug 11, 2014

I might take a look into https://github.com/tojocky/node-printer to overcome this. Sounds like a possible solution for silent printing.

@acicali
Copy link

acicali commented Aug 11, 2014

That project was the basis for my current module, and they've since added support for printing PDFs, but you'd need to know the paper size of the target printer to know what size PDF to generate, unless I'm missing something.

I simply want to be able to window.print({ printer: "Brother HL2700", silent: true}). The path of least resistance to this or something functionally equivalent is what I'm looking for.

@matths
Copy link

matths commented Aug 12, 2014

yeah +1, I would really need that feature like now. ;)

@AndryBray
Copy link

+1
any news?

@bestplay
Copy link

bestplay commented Apr 9, 2015

+1

3 similar comments
@RobinMalfait
Copy link

+1

@elbertcastaneda
Copy link

+1

@Andrew-Gee
Copy link

+1

@rogerwang
Copy link
Member

To all the people requesting silent printing -- I'd love to support this. Does --kiosk --kiosk-printing switches works for you? I'm looking to support those switches in nw13.

@RobinMalfait
Copy link

@rogerwang i would love this, for mr those switches would work :)

@RobinMalfait
Copy link

Or maybe a --printing so you don t need kiosk mode

@jonathanrdelgado
Copy link

@rogerwang That is an excellent first step. However, I think the majority of users requesting silent printing also need the ability to select a specific printer. There isn't a printer API in chromium, so that would have to be an external dependency.

@villanus
Copy link

That would be fantastic!

@Vandalko
Copy link

I work on Kiosk application and in deep need of good silent print support.
Currently. I have two solutions, both based on https://github.com/tojocky/node-printer :

  • Hack a bit this gist https://gist.github.com/zhchbin/4749217#gistcomment-1392153 and save captured image to file and print it - it utilise an interesting behavior of Window.capturePage(...) functions which allows to capture invisible window (with show:false)
  • Directly draw your content to a Canvas - it might be a bit hard, depending on what you desire to print but, anyway, there are tonns of helper libraries

@rogerwang rogerwang changed the title print - silent print print - silent print [$100] Jul 27, 2015
@rogerwang
Copy link
Member

It is supported now by command line switch '--kiosk-printing' in 0.13 version

@rogerwang
Copy link
Member

@ahmedkandel Currently no.. But in Chromium upstream the feature is working by automatically confirm in the print preview WebUI, which is written in JS/HTML and builtin in the resource file in the release.

If I enable a feature that the WebUI files can be override by you, so you can take the JS files for print preview from Chromium, modify it whatever you want, will that be good enough for you?

See the JS files for print view here: https://github.com/nwjs/chromium.src/tree/nw13/chrome/browser/resources/print_preview

@ghost
Copy link
Author

ghost commented Apr 4, 2016

would be a workaround but i prefer to wait for a more robust solution. please take your time thanks again.

@acicali
Copy link

acicali commented Apr 7, 2016

I hope this might help someone else. I needed silent printing in NWJS (Windows only) with the following requirements:

  1. Ability to pre-select one or more printers for later printing
  2. Ability to print HTML/CSS provided as a string to a given printer without user interaction

I was able to accomplish this via the following (general overview):

  1. A node addon (c++/win32api) that displays the Windows common printing dialog and returns a JavaScript object containing the selected printer's name and properties
  2. Including PhantomJS for rendering the provided HTML/CSS as a PDF (and writing that PDF to disk)
  3. Including SumatraPDF for PDF printing, providing it the PDF filename/path plus printer name

@Vandalko
Copy link

Vandalko commented Apr 7, 2016

@acicali I have recently done very similar thing, but because of 3D transformations, I was not able to render proper PDF file.
That's why I've ended up taking PNG snapshot of invisible page as described here https://gist.github.com/zhchbin/4749217#gistcomment-1392153 and printing it using IrfanView

@acicali
Copy link

acicali commented Apr 7, 2016

@Vandalko
What then do you use to send the PNG to a desired printer?

@Vandalko
Copy link

Vandalko commented Apr 7, 2016

@acicali I've configured Windows default printer and IrfanView printing, and then:

        win.capturePage(function(img) {
          var base64Data = img.replace(/^data:image\/(png|jpg|jpeg);base64,/, "");
          var fileName = printFolder + 'out-' + Date.now() + '.png';
          require("fs").writeFile(fileName, base64Data, 'base64', function(err) {
            if (err) {
              winston.error('Print error', {error: err});
            }
            var iPrint = spawn('C:\\Program Files (x86)\\IrfanView\\i_view32.exe', [fileName, '/print']);
            iPrint.on('close', function(code) {
              winston.info('IrfanView exit code: ' + code);
              var maxWaiting = global.konfig.printTime;
              var timeout = maxWaiting - (Date.now() - model.startTime);
              setTimeout(function() {
                global.printDone();
              }, Math.min(Math.max(timeout, 0), maxWaiting));
            });
          });
        }, 'png');

@AndryBray
Copy link

AndryBray commented May 11, 2016

@rogerwang do you have any idea about the possibility to customize/override the print_preview webUI and default preferences?
Is it possible to call the html-pdf process from chrome to build a pdf datauri from html string?

@rogerwang
Copy link
Member

@AndryBray my last proposal is to provide a way that developer can override the webUI by copying chrome/browser/resources/print_preview tree to somewhere under the application's directory and then modify it. Does that sound good to you?

Of course we would like to provide some API for this later, but the override way is straightforward in implementation.

@AndryBray
Copy link

AndryBray commented May 11, 2016

@rogerwang Yes it could be a perfect solution, the most important is to let us interact with default html & js files so we could be able to change behavior of chrome preview. How long does this task take? Is it possibile to have some preview on next nw15? thanks a lot!!!

@rogerwang
Copy link
Member

Yeah, will see this in 0.15.0 or 0.15.1 as Chromium 51 will be released soon in ~ 1 week.

@AndryBray
Copy link

Great! Please, could you do the same for nwjs 0.14 ? It's important because of XP and legacy MacOS versions support. Thank you

@rogerwang
Copy link
Member

@AndryBray yeah, as we announced 0.14 will be under development with new features in at least one year.

@rogerwang rogerwang added this to the 0.15.0 milestone May 11, 2016
@AndryBray
Copy link

@rogerwang You rock man!

@rogerwang
Copy link
Member

rogerwang commented May 12, 2016

@AndryBray I've done the overriding part but unfortunately the HTML file in that directory is not real HTML. It has tags like <include> and <if> which is used in chromium resources processing during building NW. I'll see how to deal with this. The original proposal may not be doable because of this.

@AndryBray
Copy link

AndryBray commented May 12, 2016

Oh no!
@rogerwang How about the possibility to build a bridge between app (nw) and print preview gui? something to let's setup default properties... the best would be a kind of API like:

window.customPrint({
  destination: 'pdf',
  margins: 0
  headings: false,
 printFrom: 1,
 printTo: 3,
 ... and so on
});

@AndryBray
Copy link

@rogerwang do you think is a kind of API doable in short time? Thank you

@rogerwang
Copy link
Member

@AndryBray currently I'm not sure how long it will take. At least it's longer than the previous proposal. If it's really urgent on your side, perhaps just change the preview UI files and rebuild NW would be the fastest way.

@jasminmif
Copy link

Any news about silent printing, im actually waiting for the release.
For the moment im using a node module to convert and compile html to pdf, than with a python script, print the result.

@rogerwang
Copy link
Member

@jasminmif see my previous comment #1263 (comment) for silent printing.

To all: I'm closing this issue and opened a new issue for custom printing API #4911

@jasminmif
Copy link

jasminmif commented May 30, 2016

@rogerwang Can you please provide a sample code of --kiosk printing, where should i add that option cause its very unclear ?

And is there a way to select a specific printer to print the document ?

window.print({
    options: { '-kiosk-printing': true}
})

@rogerwang
Copy link
Member

@jasminmif the argument is used in command line when you launch NW.js

@rogerwang
Copy link
Member

NW v0.14.6 LTS released with custom printing API http://nwjs.io/blog/v0.14.6/ . Please follow up in #4911

@spidermay
Copy link

I solved it in the package.json with the command: "chromium-args":"--kiosk-printing", and my file let as follows:
{
"version": "0.0.1",
"name": "my-project",
"main": "index.html",
"chromium-args":"--kiosk-printing",
"window":{
"printPreview":false,
"width":1440,
"height":960
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests