Skip to content

Instantly share code, notes, and snippets.

@kzykhys
Last active August 4, 2022 02:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kzykhys/4603902 to your computer and use it in GitHub Desktop.
Save kzykhys/4603902 to your computer and use it in GitHub Desktop.
Print MS Word in Node.js
/*
* Print Word document on Windows
*
* 1. Get the Word executable path
* > ftype Word.Document.8
* 2. Print silently
* > %WORD% /q /n /mfileprintdefault /mfileexit %FILE%
*/
var child_process = require('child_process');
var exec = child_process.exec;
(function(option) {
exec('ftype ' + option.ftype, function(error, stdout, stderr) {
var word = stdout.match(new RegExp('=(\".*\")'));
var cmd = [
stdout.match(new RegExp('=(\".*\")')),
option.args.join(' '),
option.file
].join(' ');
exec(cmd, function(error, stdout, stderr) {
console.log('printed!');
});
});
})({
'file': 'C:\\path\\to\\word.doc',
'ftype': 'Word.Document.8',
'args': ['/q', '/n', '/mfileprintdefault', '/mfileexit']
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment