📄 file-converter-nodejs
A powerful Node.js package for converting files between various formats, splitting and merging files, and automating complex file operations. Backed by LibreOffice and Python, this tool makes file processing seamless for developers.
Useful link:
✨ Features
Format Conversions
Convert files between formats with ease:- PDF ➡️ PPTX, PNG, JPG, HTML, DOCX
- PPTX ➡️ PDF, HTML, PNG, JPG
- PNG ➡️ PDF, JPG, SVG
- JPG ➡️ PDF, PNG, SVG
- SVG ➡️ PDF, PNG, JPG
- XLSX ➡️ PDF, CSV, HTML
- CSV ➡️ XLSX, PDF, HTML
Advanced Pipelines
Multi-step processing like splitting PDFs into pages, converting them, and merging results into a single file.Splitting Files
Split large PDFs and PPTX files into smaller components.Merging Files
Merge multiple PDFs, DOCX, or PPTX files into one.🚀 Pre-built Docker Image
Use the provided Docker image with all dependencies pre-installed.
📦 Installation
1. Install Using Yarn or NPM
# With Yarn
yarn add file-converter-nodejs
# With NPM
npm install file-converter-nodejs
2. Install Dependencies
This package requires LibreOffice and Python to be installed on your system. You can install them via your package manager or use the provided Docker image:
Using Docker (Recommended)
docker pull azertyha77/nodejs-python-soffice:latest
Your Dockerfile could look like this:
FROM azertyha77/nodejs-python-soffice:latest
WORKDIR /app
COPY . .
RUN npm install
CMD ["node", "index.js"]
Or check example Dockerfile for a more accurate example.
Without Docker
You will need to install the following dependencies manually:
LibreOffice
Install LibreOffice on your system.
Download LibreOfficePython Install Python on your system.
Python dependencies
Install the required Python dependencies using pip (find them in requirements.txt):pip install -r requirements.txt
or if you already have the npm package installed:
pip install -r node_modules/file-converter-nodejs/requirements.txt
You can have a look at an example of how to install each dependency in this Dockerfile.
🛠️ Usage
Initialize the Processor
import FileProcessor from "file-converter-nodejs";
const processor = new FileProcessor();
🔄 File Conversion
📄 Convert PDF to DOCX:
await processor.convertFile({
filePath: "/path/to/input.pdf",
from: "pdf",
to: "docx",
outdir: "/path/to/output",
});
📄 Convert PDF to PPTX:
await processor.convertFile({
filePath: "/path/to/input.pdf",
from: "pdf",
to: "pptx",
outdir: "/path/to/output",
});
📄 Convert PDF to PNG:
await processor.convertFile({
filePath: "/path/to/input.pdf",
from: "pdf",
to: "png",
outdir: "/path/to/output",
});
📄 Convert PDF to JPG:
await processor.convertFile({
filePath: "/path/to/input.pdf",
from: "pdf",
to: "jpg",
outdir: "/path/to/output",
});
📄 Convert PDF to HTML:
await processor.convertFile({
filePath: "/path/to/input.pdf",
from: "pdf",
to: "html",
outdir: "/path/to/output",
});
📄 Convert PDF to DOCX:
await processor.convertFile({
filePath: "/path/to/input.pdf",
from: "pdf",
to: "docx",
outdir: "/path/to/output",
});
📊 Convert PPTX to PDF:
await processor.convertFile({
filePath: "/path/to/input.pptx",
from: "pptx",
to: "pdf",
outdir: "/path/to/output",
});
📊 Convert PPTX to HTML:
await processor.convertFile({
filePath: "/path/to/input.pptx",
from: "pptx",
to: "html",
outdir: "/path/to/output",
});
📊 Convert PPTX to PNG:
await processor.convertFile({
filePath: "/path/to/input.pptx",
from: "pptx",
to: "png",
outdir: "/path/to/output",
});
📊 Convert PPTX to JPG:
await processor.convertFile({
filePath: "/path/to/input.pptx",
from: "pptx",
to: "jpg",
outdir: "/path/to/output",
});
🖼️ Convert PNG to PDF:
await processor.convertFile({
filePath: "/path/to/input.png",
from: "png",
to: "pdf",
outdir: "/path/to/output",
});
🖼️ Convert PNG to JPG:
await processor.convertFile({
filePath: "/path/to/input.png",
from: "png",
to: "jpg",
outdir: "/path/to/output",
});
🖼️ Convert PNG to SVG:
await processor.convertFile({
filePath: "/path/to/input.png",
from: "png",
to: "svg",
outdir: "/path/to/output",
});
🖼️ Convert JPG to PDF:
await processor.convertFile({
filePath: "/path/to/input.jpg",
from: "jpg",
to: "pdf",
outdir: "/path/to/output",
});
🖼️ Convert JPG to PNG:
await processor.convertFile({
filePath: "/path/to/input.jpg",
from: "jpg",
to: "png",
outdir: "/path/to/output",
});
🖼️ Convert JPG to SVG:
await processor.convertFile({
filePath: "/path/to/input.jpg",
from: "jpg",
to: "svg",
outdir: "/path/to/output",
});
🖼️ Convert SVG to PDF:
await processor.convertFile({
filePath: "/path/to/input.svg",
from: "svg",
to: "pdf",
outdir: "/path/to/output",
});
🖼️ Convert SVG to PNG:
await processor.convertFile({
filePath: "/path/to/input.svg",
from: "svg",
to: "png",
outdir: "/path/to/output",
});
🖼️ Convert SVG to JPG:
await processor.convertFile({
filePath: "/path/to/input.svg",
from: "svg",
to: "jpg",
outdir: "/path/to/output",
});
📊 Convert XLSX to PDF:
await processor.convertFile({
filePath: '/path/to/input.xlsx',
from: 'xlsx',
to: 'pdf',
outdir: '/path/to/output',
});
📊 Convert XLSX to CSV:
await processor.convertFile({
filePath: "/path/to/input.xlsx",
from: "xlsx",
to: "csv",
outdir: "/path/to/output",
});
📊 Convert XLSX to HTML:
await processor.convertFile({
filePath: "/path/to/input.xlsx",
from: "xlsx",
to: "html",
outdir: "/path/to/output",
});
📝 Convert CSV to XLSX:
await processor.convertFile({
filePath: "/path/to/input.csv",
from: "csv",
to: "xlsx",
outdir: "/path/to/output",
});
📝 Convert CSV to PDF:
await processor.convertFile({
filePath: "/path/to/input.csv",
from: "csv",
to: "pdf",
outdir: "/path/to/output",
});
📝 Convert CSV to HTML:
await processor.convertFile({
filePath: "/path/to/input.csv",
from: "csv",
to: "html",
outdir: "/path/to/output",
});
🔄 Splitting and Merging Files
📄 Split PDF into Pages:
const splitFiles = processor.splitFile({
filePath: "/path/to/input.pdf",
fileType: "pdf",
outputDir: "/path/to/output",
});
console.log("Generated Files:", splitFiles);
📄 Split PPTX into Pages:
const splitSlides = processor.splitFile({
filePath: "/path/to/input.pptx",
fileType: "pptx",
outputDir: "/path/to/output",
});
console.log("Generated Files:", splitSlides);
📄 Merge PDF Files:
processor.mergeFiles({
filePaths: ["/path/to/file1.pdf", "/path/to/file2.pdf"],
fileType: "pdf",
outputFilePath: "/path/to/merged.pdf",
});
📄 Merge PPTX Files:
processor.mergeFiles({
filePaths: ["/path/to/file1.pptx", "/path/to/file2.pptx"],
fileType: "pptx",
outputFilePath: "/path/to/merged.pptx",
});
📄 Merge DOCX Files:
processor.mergeFiles({
filePaths: ["/path/to/file1.docx", "/path/to/file2.docx"],
fileType: "docx",
outputFilePath: "/path/to/merged.docx",
});
⚙️ Configuration
Default Settings
- LibreOffice Path
soffice
- Python Path
python3
You can customize the configuration by passing options to the FileProcessor
constructor:
const processor = new FileProcessor({
libreOfficePath: "/custom/path/to/soffice",
pythonPath: "/custom/path/to/python",
});
Note that if you're using the provided docker image, you don't need to pass these options.
🤝 Contribution
Contributions are welcome! Please open an issue or submit a pull request for any improvements or feature requests.
📝 License
This project is licensed under the MIT License. See the LICENSE file for more information.