镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Nodejs document printing #13915

Description

@lumenier1

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

Activity

  1. cjihrig commented on Jun 26, 2017

    @cjihrig
    Contributor

    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.

  2. added
    questionIssues asking questions about Node.js.
    on Jun 26, 2017
  3. TimothyGu commented on Jun 26, 2017

    @TimothyGu
    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.

  4. changed the title [-]Node-printer issue[/-] [+]Nodejs document printing[/+] on Jun 26, 2017
  5. lumenier1 commented on Jun 26, 2017

    @lumenier1
    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.

  6. TimothyGu commented on Jun 26, 2017

    @TimothyGu
    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.

  7. lumenier1 commented on Jun 26, 2017

    @lumenier1
    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")

  8. lumenier1 commented on Jun 28, 2017

    @lumenier1
    Author

    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???

  9. refack commented on Jun 28, 2017

    @refack
    Contributor

    @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.

  10. added
    child_processIssues and PRs related to the child_process subsystem.
    windowsIssues and PRs related to the Windows platform.
    on Jun 28, 2017
  11. lumenier1 commented on Jun 30, 2017

    @lumenier1
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    child_processIssues and PRs related to the child_process subsystem.questionIssues asking questions about Node.js.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions