doc to pdf

Perform DOC to PDF conversion with Node.js API.

Microsoft Word (DOC, DOCX) is a popular format for document creation and editing, but when it comes to secure sharing, archiving, or printing, PDF (Portable Document Format) is the preferred choice. Converting Word to PDF ensures consistent formatting, universal compatibility, and document integrity across platforms.

In this tutorial, you’ll learn how to convert Word files to PDF using the GroupDocs.Conversion Cloud SDK for Node.js, a powerful and scalable REST API built for developers.

Node.js SDK for Word to PDF Conversion

GroupDocs.Conversion Cloud SDK for Node.js makes document transformation easy, efficient, and scalable. With just a few lines of code, you can integrate high-quality Word to PDF conversion into your Node.js application.

Key Features:

  • Supports DOC, DOCX, DOT, and other Word formats.
  • Convert to PDF, HTML, JPG, XLSX, and more.
  • Upload, convert, and download via cloud storage.
  • OAuth 2.0 secure authentication.
  • No need for Microsoft Word or third-party tools.

Installation Install the SDK using npm:

npm install groupdocs-conversion-cloud --save

Then, get your API credentials (Client ID and Client Secret) from GroupDocs Cloud Dashboard.

Convert Word to PDF Using Node.js

Follow these steps to convert a DOC/DOCX file to PDF using Node.js and GroupDocs SDK:

  1. Initialize API Configuration:
const {
  Configuration,
  ConvertApi,
  FileApi,
  UploadFileRequest,
  ConvertDocumentRequest,
  ConvertSettings
} = require("groupdocs-conversion-cloud");

const config = new Configuration("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");
const convertApi = new ConvertApi(config);
const fileApi = new FileApi(config);
  1. Upload Word Document to Cloud Storage:
const fs = require("fs");
const uploadRequest = new UploadFileRequest("input-sample.doc", fs.createReadStream("input-sample.doc"));
await fileApi.uploadFile(uploadRequest);
  1. Define Conversion Settings:
const settings = new ConvertSettings();
settings.filePath = "input-sample.doc";
settings.format = "pdf";
settings.outputPath = "resultant/output.pdf";
  1. Execute the Conversion:
const request = new ConvertDocumentRequest(settings);
const result = await convertApi.convertDocument(request);
console.log("Word successfully converted to PDF.");
docx to pdf

Image:- A preview of DOCX to PDF conversion.

Convert DOC to PDF using cURL

If you prefer using REST directly or integrating into scripts, here’s how to do it using cURL:

Step 1 – Generate Access Token:

curl -v "https://api.groupdocs.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Step 2 – Trigger the DOCX to PDF Conversion:

curl -v "https://api.groupdocs.cloud/v2.0/conversion" \
-X POST \
-H "Authorization: Bearer <JWT_TOKEN>" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-d '{
  "FilePath": "<inputFile>",
  "Format": "pdf",
  "OutputPath": "converted/<resultantPDF>",
  "LoadOptions": {
    "Format": "docx"
  }
}'

Please replace inputFile with the name of input Word document, resultantPDF with the name of resultant PDF file and JWT_TOKEN with personalized JWT access token.

DOC to PDF Conversion - Save output on local drive: If you prefer saving the resultant PDF file on local drive, please try executing following cURL command:

curl -v "https://api.groupdocs.cloud/v2.0/conversion" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {JWT_TOKEN}" \
-H "Content-Type: application/json" \
-d "{  \"StorageName\": \"internal\",  \"FilePath\": \"{inputFile}\",  \"Format\": \"pdf\",  \"LoadOptions\": {    \"Format\": \"doc\"  }}" \
-o "localResultant.pdf"

🌐 Try the Free DOC to PDF Online Converter

Want to preview the conversion capabilities? Use the Free DOCX to PDF Conversion App powered by GroupDocs.Conversion Cloud.

DOCX to PDF converter

Additional Resources

Conclusion

With GroupDocs.Conversion Cloud SDK for Node.js, converting Word documents to PDF is secure, accurate, and simple to implement. Whether you’re integrating conversion into your SaaS platform, automating document workflows, or building cloud-based apps, this SDK provides the reliability and scalability needed for production environments.

We also recommend visiting the following links to learn more about: