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

Nodejs document printing #13915

Closed
lumenier1 opened this issue Jun 26, 2017 · 8 comments
Closed

Nodejs document printing #13915

lumenier1 opened this issue Jun 26, 2017 · 8 comments
Labels
child_process Issues and PRs related to the child_process subsystem. question Issues that look for answers. windows Issues and PRs related to the Windows platform.

Comments

@lumenier1
Copy link

Hello,
Recently I've installed node-printer module but it doesn't work and I don't know why :(
When I try to log Printer.list() command (Get available printers list) it returns an empty array despite of the fact that I have a working printer and drivers installed.

I really want to use nodejs for document printring.
I'm curious to know exactly how this module works? Does it send file to the printing queue or communicates directly to the printer?
Is there any way just to send files to the printing queue through a standard OS command? I know that it is pretty simple to do for win and linux using python. Unfortunately it is not feasible for node yet. But I don't want to use python script in conjunction with node!
Does anyone use node-printer module? Do you need any specific settings or installation for this?
I know that node has an os module but it only returns information about the system. Is it possible to create some function for node similar to python's that will start a file with associated application by os?
For e.g. this is code that works perfectly in python:
import os
os.startfile("printme.txt", "print")
Is it possible to do the same with just node child_process?

  • Version: 7.0.0
  • Platform: Win 7 64-bit
  • Printer: Brother HL-2130 series
@cjihrig
Copy link
Contributor

cjihrig commented Jun 26, 2017

You can view the code and issue tracker for that module at https://github.com/alepee/node-printer. However, it was last published 2 years ago, and according to the README, the module should not be used.

@mscdex mscdex added the question Issues that look for answers. label Jun 26, 2017
@TimothyGu
Copy link
Member

This issue seems to apply to the node-printer module, not Node.js itself. Please redirect your question to node-printer. Either way, it seems to me that the node-printer module depends on CUPS, which is Unix-only.

@lumenier1 lumenier1 changed the title Node-printer issue Nodejs document printing Jun 26, 2017
@lumenier1
Copy link
Author

I wanted to raise the issue of printing documents in general.
What about child_process?
Please do not say that I have to use python for this.

@TimothyGu
Copy link
Member

I'm not quite sure what

os.startfile("printme.txt", "print")

does in Python, but if it is equivalent to print printme.txt in cmd.exe then either

const stdout = child_process.execSync('print printme.txt');

// or

child_process.exec('print printme.txt', (err, stdout, stderr) => {
  // ...
});

should suffice.

I'll close this ticket for now, but for future questions like this you should find more help at, well, nodejs/help.

@lumenier1
Copy link
Author

Thank you so much, that is exactly what I want!
const stdout = child_process.execSync('print printme.txt');
is is equivalent to os.startfile("printme.txt", "print")

@lumenier1
Copy link
Author

lumenier1 commented Jun 28, 2017

Omg, could somebody explain this, now the same code doesn't work!
const stdout = child_process.execSync('start printme.txt'); is fine, but const stdout = child_process.execSync('print printme.txt'); doesn't work anymore. Before that I thought that this was my mistake, but now I realized that this print command does not always work.
What's wrong with node???

@refack
Copy link
Contributor

refack commented Jun 28, 2017

@lumenier1 I'm just guessing but the issue might be if your exec uses a shell or not https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options

Could you provide more information about how does the "not working" look like? Does the child process throw or return a non 0 ERRORLEVEL? Does print just not work (no new job in the spooler)?

Also from personal experience I know that print is highly dependant of the state of your system + the state of the printer.

@refack refack added child_process Issues and PRs related to the child_process subsystem. windows Issues and PRs related to the Windows platform. labels Jun 28, 2017
@lumenier1
Copy link
Author

Thank you for taking some time for the answer.
There is no error, but stdout log contains this string �� 㤠���� ���樠����஢��� ���ன�⢮ PRN
Code sample:
var child_process = require('child_process');
child_process.exec('print printme.txt', (err, stdout, stderr) => {
console.log(err, stdout, stderr);
});
At some point this code sample used to work, but now it doesn't.
I mean that earlier the file was sent to printing queue when this script was launched. Now nothing appears in the printing queue by script execution. It is very strange. Why the same thing works perfectly with python but fails unpredictably with nodejs on the same system?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem. question Issues that look for answers. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

No branches or pull requests

5 participants