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:
-
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.
# With Yarn
yarn add file-converter-nodejs
# With NPM
npm install file-converter-nodejs
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:
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.
You will need to install the following dependencies manually:
-
LibreOffice
Install LibreOffice on your system.
Download LibreOffice -
Python 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.
import FileProcessor from "file-converter-nodejs";
const processor = new FileProcessor();
Convert PDF 📄
await processor.convertFile({
filePath: "/path/to/input.pdf",
from: "pdf",
to: "docx",
outdir: "/path/to/output",
});
await processor.convertFile({
filePath: "/path/to/input.pdf",
from: "pdf",
to: "pptx",
outdir: "/path/to/output",
});
await processor.convertFile({
filePath: "/path/to/input.pdf",
from: "pdf",
to: "png",
outdir: "/path/to/output",
});
await processor.convertFile({
filePath: "/path/to/input.pdf",
from: "pdf",
to: "jpg",
outdir: "/path/to/output",
});
await processor.convertFile({
filePath: "/path/to/input.pdf",
from: "pdf",
to: "html",
outdir: "/path/to/output",
});
await processor.convertFile({
filePath: "/path/to/input.pdf",
from: "pdf",
to: "docx",
outdir: "/path/to/output",
});
Convert PPTX 📊
await processor.convertFile({
filePath: "/path/to/input.pptx",
from: "pptx",
to: "pdf",
outdir: "/path/to/output",
});
await processor.convertFile({
filePath: "/path/to/input.pptx",
from: "pptx",
to: "html",
outdir: "/path/to/output",
});
await processor.convertFile({
filePath: "/path/to/input.pptx",
from: "pptx",
to: "png",
outdir: "/path/to/output",
});
await processor.convertFile({
filePath: "/path/to/input.pptx",
from: "pptx",
to: "jpg",
outdir: "/path/to/output",
});
Convert PNG 🖼️
await processor.convertFile({
filePath: "/path/to/input.png",
from: "png",
to: "pdf",
outdir: "/path/to/output",
});
await processor.convertFile({
filePath: "/path/to/input.png",
from: "png",
to: "jpg",
outdir: "/path/to/output",
});
await processor.convertFile({
filePath: "/path/to/input.png",
from: "png",
to: "svg",
outdir: "/path/to/output",
});
Convert JPG 🖼️
await processor.convertFile({
filePath: "/path/to/input.jpg",
from: "jpg",
to: "pdf",
outdir: "/path/to/output",
});
await processor.convertFile({
filePath: "/path/to/input.jpg",
from: "jpg",
to: "png",
outdir: "/path/to/output",
});
await processor.convertFile({
filePath: "/path/to/input.jpg",
from: "jpg",
to: "svg",
outdir: "/path/to/output",
});
Convert SVG 🖼️
await processor.convertFile({
filePath: "/path/to/input.svg",
from: "svg",
to: "pdf",
outdir: "/path/to/output",
});
await processor.convertFile({
filePath: "/path/to/input.svg",
from: "svg",
to: "png",
outdir: "/path/to/output",
});
await processor.convertFile({
filePath: "/path/to/input.svg",
from: "svg",
to: "jpg",
outdir: "/path/to/output",
});
Convert XLSX 📊
await processor.convertFile({
filePath: '/path/to/input.xlsx',
from: 'xlsx',
to: 'pdf',
outdir: '/path/to/output',
});
await processor.convertFile({
filePath: "/path/to/input.xlsx",
from: "xlsx",
to: "csv",
outdir: "/path/to/output",
});
await processor.convertFile({
filePath: "/path/to/input.xlsx",
from: "xlsx",
to: "html",
outdir: "/path/to/output",
});
Convert CSV 📊
await processor.convertFile({
filePath: "/path/to/input.csv",
from: "csv",
to: "xlsx",
outdir: "/path/to/output",
});
await processor.convertFile({
filePath: "/path/to/input.csv",
from: "csv",
to: "pdf",
outdir: "/path/to/output",
});
await processor.convertFile({
filePath: "/path/to/input.csv",
from: "csv",
to: "html",
outdir: "/path/to/output",
});
Splitting File 📄 → 📄📄📄
const splitFiles = processor.splitFile({
filePath: "/path/to/input.pdf",
fileType: "pdf",
outputDir: "/path/to/output",
});
console.log("Generated Files:", splitFiles);
const splitSlides = processor.splitFile({
filePath: "/path/to/input.pptx",
fileType: "pptx",
outputDir: "/path/to/output",
});
console.log("Generated Files:", splitSlides);
Merging Files 📄📄📄 → 📄
processor.mergeFiles({
filePaths: ["/path/to/file1.pdf", "/path/to/file2.pdf"],
fileType: "pdf",
outputFilePath: "/path/to/merged.pdf",
});
processor.mergeFiles({
filePaths: ["/path/to/file1.pptx", "/path/to/file2.pptx"],
fileType: "pptx",
outputFilePath: "/path/to/merged.pptx",
});
processor.mergeFiles({
filePaths: ["/path/to/file1.docx", "/path/to/file2.docx"],
fileType: "docx",
outputFilePath: "/path/to/merged.docx",
});
-
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.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or feature requests.
This project is licensed under the MIT License. See the LICENSE file for more information.