Document conversion API for Node.js (powered by Java) to convert back and forth between the most popular document and image formats, including PDF, Word, Excel, PowerPoint, OpenDocument documents, e-mail messages, images and many more in one package.
npm install @groupdocs/groupdocs.conversionDocument conversion API for Node.js (powered by Java) to convert back and forth between the most popular document and image formats, including PDF, Word, Excel, PowerPoint, OpenDocument documents, e-mail messages, images and many more in one package.
bash
npm i @groupdocs/groupdocs.conversion
`
For detailed setup instructions, see the System Requirements and Installation documentation topics.
$3
Below are simple Node.js snippets that demonstrate typical use cases: converting a DOCX to PDF, converting PDF to PDF/A, and converting only specific pages of a document.
#### Convert DOCX to PDF
This code example shows how to convert a Word document (DOCX) to a PDF file with default conversion options.
`js
'use strict';
// Require dependencies
const groupdocs = require('@groupdocs/groupdocs.conversion');
const path = require('path');
// Apply license if you have one (optional for evaluation).
const licensePath = path.resolve(__dirname, 'GroupDocs.Conversion.lic');
const license = new groupdocs.License();
license.setLicense(licensePath);
// Create a converter for the source document.
const converter = new groupdocs.Converter('source.docx');
// Set up PDF conversion options and run the conversion.
const convertOptions = new groupdocs.PdfConvertOptions();
converter.convert('converted.pdf', convertOptions);
// Exit the process
process.exit(0);
`
#### Convert PDF to PDF/A
This code example shows how to convert a regular PDF document to a PDF/A-compliant PDF.
`js
'use strict';
// Require dependencies
const groupdocs = require('@groupdocs/groupdocs.conversion');
const path = require('path');
// Apply license if you have one (optional for evaluation).
const licensePath = path.resolve(__dirname, 'GroupDocs.Conversion.lic');
const license = new groupdocs.License();
license.setLicense(licensePath);
// Create a converter for the source document.
const converter = new groupdocs.Converter('source.pdf');
// Set the format to PDF/A-compliant PDF
const pdfOptions = new groupdocs.PdfOptions();
pdfOptions.setPdfFormat(groupdocs.PdfFormats.PdfA_1A);
// Set the convert options
const convertOptions = new groupdocs.PdfConvertOptions();
convertOptions.setPdfOptions(pdfOptions);
// Convert the document
converter.convert('converted_pdfa.pdf', convertOptions);
// Exit the process
process.exit(0);
`
#### Convert Specific Pages
This code example shows how to convert only selected pages of a Word document (DOCX) to a PDF document.
`js
'use strict';
// Require dependencies
const groupdocs = require('@groupdocs/groupdocs.conversion');
const path = require('path');
// Import java array list
const java = require('java');
const ArrayList = java.import('java.util.ArrayList');
// Apply license if you have one (optional for evaluation)
const licensePath = path.resolve(__dirname, 'GroupDocs.Conversion.lic');
const license = new groupdocs.License();
license.setLicense(licensePath);
// Create a converter for the source document
const converter = new groupdocs.Converter('source.docx');
// Set pages to convert
const pages = new ArrayList();
pages.add(1);
pages.add(2);
pages.add(3);
// Set the convert options
const convertOptions = new groupdocs.PdfConvertOptions();
convertOptions.setPages(pages);
// Convert pages 1, 2, and 3 to PDF
converter.convert('converted_pages_1_2_3.pdf', convertOptions);
// Exit the process
process.exit(0);
`
Troubleshooting
- Download during installation fails (corporate proxy/firewall): Ensure your environment allows downloading the required JAR during postinstall. If needed, download the file manually to the lib/ directory as described in the Installation Guide.
- Java not found: Make sure Java (JRE 8+) is installed and available on your system PATH.
- Permission issues when writing output files: Verify your process has write access to the target directory.
Licensing
For testing without trial limitations, you can request a 30-day Temporary License:
- Visit the Get a Temporary License page
- Login with your company email address
- Request a temporary license and get it in your mailbox
After you receive the license file, save it locally and use it in your application as follows:
`js
'use strict';
const groupdocs = require('@groupdocs/groupdocs.conversion');
// Apply license
const license = new groupdocs.License();
license.setLicense('GroupDocs.Conversion.lic');
``