Skip to content

Instantly share code, notes, and snippets.

@blog-aspose-cloud
Last active October 6, 2024 16:46
Show Gist options
  • Select an option

  • Save blog-aspose-cloud/0b9b424974f335d0694d176a894764a7 to your computer and use it in GitHub Desktop.

Select an option

Save blog-aspose-cloud/0b9b424974f335d0694d176a894764a7 to your computer and use it in GitHub Desktop.
PDF to Word Conversion in Node.js

Convert PDF to Word in Node.js


PDF file is multiplatform and can be viewed on any platform and you can edit files to some extent. However, we cannot easily edit the PDF file but on the other end, if we have a word document, its easy to edit and manipulate the content inside it. This gist explains the steps on how to develop PDF to Word converter online using Aspose.PDF Cloud SDK for Node.js. For complete information, please visit PDF To Word in Node.js.

pdf to word

Important Links

Product Page | Docs | Live Demo | Swagger UI | Code Samples | Source Code | New Releases | Blog | Free Support | Free Trial

Convert PDF to Word using Node.js SDK
import { Controller, Post } from '@nestjs/common';
import { AppService } from './app.service';
import { PdfApi } from 'asposepdfcloud';
import \* as fs from 'fs';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Post('/pdf-to-doc')
async pdfToDoc() {
const name = 'm.pdf';
const SrcFile = '/' + name;
const resultName = 'result.doc';
const resultPath = 'myfolder/' + resultName;
const storageName = 'testing';
const fileToWrite = process.cwd() + '/' + resultName;
const pdfApi = new PdfApi(
'YOUR-APPSID',
'YOUR-APPKEY',
);
try {
const data = fs.readFileSync(name);
await pdfApi.uploadFile(SrcFile, new Buffer(data), storageName);
await pdfApi.putPdfInStorageToDoc(
name,
resultPath,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
'',
'',
'',
'',
'',
'',
'',
'',
'',
storageName,
);
// Download pdf from cloud storage
const fileData = await pdfApi.downloadFile(resultPath, storageName, '');
const writeStream = fs.createWriteStream(fileToWrite);
writeStream.write(fileData.body);
return 'PDF converted to DOC successfully';
} catch (e) {
throw e;
}
}
}
@Abhishek11n
Copy link
Copy Markdown

hi

@Abhishek11n
Copy link
Copy Markdown

hi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment