[英]How to convert PDF to DOCX or URL to DOCX with NodeJS?
I'm trying to research on URL to DOCx
or PDF to DOCx
conversation in NodeJS but didn't get any proper solution.我正在尝试在
URL to DOCx
研究URL to DOCx
或PDF to DOCx
对话,但没有得到任何适当的解决方案。
I reached out PhantomJS
but It convert URL to PDF
Is that any idea, Phantom can convert into DOCX?我联系了
PhantomJS
但它会将URL to PDF
转换URL to PDF
有什么想法吗,Phantom 可以转换为 DOCX?
Please give your suggestion regarding docx
conversation.请就
docx
对话提出您的建议。
NOTE: HTML content to Docx does not require Because I've MAP and other charts available on HTML page so URL needed.注意: Docx 的 HTML 内容不需要,因为我在 HTML 页面上提供了 MAP 和其他图表,因此需要 URL。
There are very few free, open source utilities that can convert HTML to DOCX and even fewer that can do it well, so asking specifically about Node.js is quite specific.很少有免费的开源实用程序可以将 HTML 转换为 DOCX,而能够将 HTML 转换为 DOCX 的实用程序更少,因此专门询问 Node.js 是非常具体的。 If you're comfortable shelling out a simple command, you can convert a URL to DOCX using
pandoc
.如果您愿意执行简单的命令,则可以使用
pandoc
将 URL 转换为 DOCX。 I recommend testing this utility locally without Node first.我建议先在没有 Node 的情况下在本地测试此实用程序。
pandoc -f html https://stackoverflow.com/questions/48656219 -o 48656219.docx
Disclaimer: Pandoc is a markup converter, not a full blown HTML renderer.免责声明: Pandoc 是一个标记转换器,而不是一个完整的 HTML 渲染器。 This means you will not have a full browser... eg You will lose formatting and there will generally be rendering problems for many common HTML and CSS techniques.
这意味着您将没有完整的浏览器……例如,您将丢失格式,并且通常会出现许多常见 HTML 和 CSS 技术的渲染问题。 Here's a rendering of this page using
pandoc
: https://i.stack.imgur.com/LfUhw.png这是使用
pandoc
渲染此页面: https : pandoc
If it works, you're in luck because there's an npm
package for pandoc available.如果它有效,那么你很幸运,因为有一个用于 pandoc 的
npm
包可用。 https://www.npmjs.com/package/node-pandoc https://www.npmjs.com/package/node-pandoc
var pandoc = require('node-pandoc');
var src, args, callback;
src = 'https://stackoverflow.com/questions/48656219';
args = ['-f','html', '-o','48656219.docx'];
// Set your callback function
callback = function (err, result) {
if (err) {
console.error('Oh Nos: ',err);
}
// For output to files, the 'result' will be a boolean 'true'.
// Otherwise, the converted value will be returned.
console.log(result);
return result;
};
// Call pandoc
pandoc(src, args, callback);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.