通过 headless-wps 把 doc 转成 pdf,再通过上传 base64 解决了 word 转 pdf,字体和样式都没有问题。
但 pdf 文件是通过 onlyoffice 预览的,没有办法直接打印,只能先下载再打印。有没有办法通过浏览器直接打开呢?
我的做法是写一个 js 脚本监听
const http = require('http');
const { exec } = require('child_process');
var URL = require('url');
const hostname = '192.168.1.230';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
var arg = URL.parse(req.url).query; //方法一 arg => aa=001&bb=002
var arg = URL.parse(req.url, true).query; //方法二 arg => { aa: '001', bb: '002' }
console.log(arg.aaa);//返回 001
console.log('C:\Users\XCADEY\Downloads\Chrome\Chrome\chrome.exe --new-window ' + encodeURI('http://192.168.1.229:8080/#/shipping/') + encodeURI(arg.aaa));//返回 001
exec('C:\Users\XCADEY\Downloads\Chrome\Chrome\chrome.exe --new-window ' + encodeURI('http://192.168.1.229:8080/#/shipping/') + encodeURI(arg.aaa), (err, stdout, stderr) => {
if(err) {''
console.log(err);
return;
}
console.log(stdout: ${stdout}
);
console.log(stderr: ${stderr}
);
})
});
server.listen(port, hostname, () => {
console.log(Server running at http://${hostname}:${port}/
);
});