Repository navigation
Nodejs document printing #13915
Description
Activity
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.
- addedquestionIssues asking questions about Node.js.Issues asking questions about Node.js.
on Jun 26, 2017 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.
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.I'm not quite sure what
os.startfile("printme.txt", "print")
does in Python, but if it is equivalent to
print printme.txtin cmd.exe then eitherconst 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.
Thank you so much, that is exactly what I want!
const stdout = child_process.execSync('print printme.txt');
is is equivalent toos.startfile("printme.txt", "print")Omg, could somebody explain this, now the same code doesn't work!
const stdout = child_process.execSync('start printme.txt');is fine, butconst 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 thisprintcommand does not always work.
What's wrong with node???@lumenier1 I'm just guessing but the issue might be if your
execuses ashellor not https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_optionsCould you provide more information about how does the "not working" look like? Does the child process throw or return a non 0 ERRORLEVEL? Does
printjust not work (no new job in the spooler)?Also from personal experience I know that
printis highly dependant of the state of your system + the state of the printer.- addedchild_processIssues and PRs related to the child_process subsystem.Issues and PRs related to the child_process subsystem.windowsIssues and PRs related to the Windows platform.Issues and PRs related to the Windows platform.
on Jun 28, 2017 Thank you for taking some time for the answer.
There is no error, butstdoutlog 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?
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 osos.startfile("printme.txt", "print")Is it possible to do the same with just node child_process?