简体   繁体   English

如何使用 node.js 打印一组 PDF 文件

[英]How to print a set of PDF Files in using node.js

Hi I want to print(using printer) list of PDF files using nodejs.嗨,我想使用 nodejs 打印(使用打印机)PDF 文件列表。 But not able to find any proper way.但无法找到任何适当的方法。 I found one JavaScript library called print.js( http://printjs.crabbly.com ) But with that also I m not able to call it in loop.我找到了一个名为 print.js( http://printjs.crabbly.com ) 的 JavaScript 库,但是我也无法在循环中调用它。

Is there anything I can do for this.有什么我可以做的。

var pdflist = [a.pdf,b.pdf] //(this is my PDF list)

Thanks for help.感谢帮助。

You can use ghostscript command line tools from your node app by forking a child process to execute the commands and loop thru your pdfs.您可以通过派生子进程来执行命令并循环浏览您的 pdf 文件,从而使用您的节点应用程序中的ghostscript命令行工具。

// OS : windows 64bits (for other OSs : linux, macosx ...etc; it's almost the same thing)
//assuming here that pdf is the path string to your pdf file
//printer name : Apple LaserWriter II NT 
pdflist.foreach( function (pdf,index){
   require("child_process").exec('gswin64c.exe ... -sOutputFile="%printer%Apple LaserWriter II NT" ' + pdf,
      (error, stdout, stderr) => {
            if (error) {
                  console.error(`exec error: ${error}`);
                  return;
            }
            console.log(`stdout: ${stdout}`);
            console.log(`stderr: ${stderr}`);
      }
   );
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM