Node.js Library For Office Documents Conversion to PDF or HTML
A Leading Open Source Node.js Library Allows Software Developers to Read and Convert Office Documents to PDF, HTML, JPEG, PNG & Various Other Formats via free Node.js API.
What is Awesome-Unoconv?
The Awesome-Unoconv library is a powerful, open-source wrapper designed to enhance the capabilities of the popular unoconv tool, which facilita1tes seamless file format conversions leveraging the LibreOffice suite. Built to simplify interactions with unoconv, this library provides a programmatic interface to automate document conversion tasks with minimal effort. There are several important features part of the library, such as converting Office files to PDF, converting DOCX to HTML, customized document conversion to PDF or HTML, document conversion to buffer, web-based document conversion, and many more. It includes built-in support for asynchronous conversions, enabling you to perform multiple conversions simultaneously without blocking your application.
The Awesome-Unoconv library brings an intuitive and well-documented API for handling document conversions inside Node.js applications, allowing software developers to integrate robust format conversion into their projects effortlessly. It supports a wide range of document formats, including DOC, DOCX, ODT, XLSX, PPTX, PDF, HTML, PNG, JPEG, and so on. This versatility makes it an ideal choice for projects that require file format conversions. The library provides a range of conversion options, allowing you to customize the conversion process to suit your specific needs such as specifying the output format, font, and layout. The library includes robust error handling mechanisms, ensuring that your application remains stable and responsive even in the event of conversion errors. With support for diverse formats, it enables developers to build multifunctional applications, such as file converters, automated reporting tools, and more. Overall, it is an ideal choice for projects that require seamless file conversions.
Getting Started with Awesome-Unoconv
To install Awesome-Unoconv, you can use npm, the package manager for JavaScript. Please use the following commands for a successful installation.
Install Awesome-Unoconv library via npm
$ npm install awesome-unoconv
Convert Office Documents to PDF inside Node.js
The Awesome-Unoconv library has provided complete functionality for programmatically converting various documents like PDF, DOCX, ODT, XLSX, and popular image formats like JPEG, PNG and so on. The primary feature of the library is its simplicity in converting a wide range of document formats. The following example demonstrates how software developers can load and convert a Word DOCX document to PDF file format inside Node.js applications.
How to Convert a Word Document to PDF via Node.js Library?
const path = require('path');
const unoconv = require('awesome-unoconv');
const sourceFilePath = path.resolve('./myDoc.docx');
const outputFilePath = path.resolve('./myDoc.pdf'); // or 'myDoc.html'
unoconv
.convert(inputPath, { output: outputPath, format: 'pdf' }) // or format: 'html'
.then(result => {
console.log(result); // return outputFilePath
})
.catch(err => {
console.log(err);
});
Customizable Documents Conversion in Node.js
The open source Awesome-Unoconv library, makes it easy for software developers to load and convert various office documents inside Node.js applications. Software developers can specify advanced conversion options, such as page ranges, image quality, and output resolution, to tailor the output according to their requirements. The following example demonstrates, how software developers can export specific pages of a PDF to PNG with custom resolution.
How to Convert specific pages of a PDF to PNG inside Node.js Apps?
unoconv.convert('document.pdf', 'png', { startPage: 1, endPage: 5, resolution: 300 }, (error, result) => {
if (error) {
console.error('Failed to convert:', error);
} else {
console.log('High-resolution PNGs generated.');
}
});
Documents Batch Conversion in Node.js
With Awesome-Unoconv library, developers can easily perform documents batch conversions. This feature is useful when dealing with large collections of documents that need to be converted to different formats. It supports converting multiple files in one go, thus saving time and effort. With just a couple of lines of code software developers can easily convert multiple files at once. Here's an example that convert multiple files in a batch, simplifying large-scale document processing tasks.
How to Convert Multiple Files to PDF inside Node.js Apps?
const files = ['doc1.docx', 'doc2.odt', 'doc3.txt'];
files.forEach((file) => {
unoconv.convert(file, 'pdf', (error, result) => {
if (error) {
console.error(`Error converting ${file}:`, error);
} else {
const outputName = file.replace(/\.[^/.]+$/, '.pdf');
require('fs').writeFileSync(outputName, result);
console.log(`${file} converted to PDF.`);
}
});
});