Last active
August 4, 2022 02:51
-
-
Save kzykhys/4603902 to your computer and use it in GitHub Desktop.
Print MS Word in Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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