是否使用npm/node模块或通过代码将PDF转换为doc或docx?

2nc8po8w  于 2022-12-13  发布在  其他
关注(0)|答案(3)|浏览(327)

我还没有成功找到一个节点模块或一些代码,可以转换一个PDF到doc/docx使用 NodeJS 。有什么办法做到这一点?

jq6vz3qz

jq6vz3qz1#

您可以使用Aspose.Words Cloud SDK for Node.js将PDF从npm转换为DOCX

#Convert PDF to DOCX from Cloud Storage
const { WordsApi, SaveOptionsData } = require("asposewordscloud");
const { UploadFileRequest, SaveAsRequest }= require("asposewordscloud/dist/model/model");
var fs = require('fs');

# Please get your App Key and App SID from https://dashboard.aspose.cloud
wordsApi = new WordsApi("APP_KEY", "APP_SID");

const remotename = "02_pages.pdf";
const remoteTempFolder = "Temp";

const request = new SaveAsRequest({
                        saveOptionsData: new SaveOptionsData({
                            saveFormat: "docx",
                            fileName: "TestPostDocumentSavePdfAsDocx.docx",
                        }),

                    });
                    request.name = remotename;
                    request.folder = remoteTempFolder;

wordsApi.saveAs(request).then((result) => {    
    console.log(result.body);    
}).catch(function(err) {
    // Deal with an error
    console.log(err);
});

# Convert PDF to DOCX from request stream
const { WordsApi, ConvertDocumentRequest } = require("asposewordscloud");
var fs = require('fs');

 // Get Customer ID and Customer Key from https://dashboard.aspose.cloud/
wordsApi = new WordsApi("xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx");

 var request = new ConvertDocumentRequest({
                format: "docx",
                document: fs.createReadStream("C:/Temp/02_pages.pdf"),
            });
 var outputFile = "C:/Temp/ConvertPDFtotxt.docx";
 wordsApi.convertDocument(request).then((result) => {    
 console.log(result.response.statusCode);    
 console.log(result.body.byteLength);    
 fs.writeFileSync(outputFile, result.body);
 }).catch(function(err) {
 // Deal with an error
 console.log(err);
 });

我是Aspose的开发人员宣传员。

7fyelxc5

7fyelxc52#

节点-未转换

用于使用unoconv转换文档的node.js Package 器。
https://github.com/gfloyd/node-unoconv

hkmswyz6

hkmswyz63#

你可以试试这个服务https://docs.groupdocs.cloud/conversion/convert-document/。它允许转换很多不同的格式。

相关问题