InfoProjectsPosts

How to Use Files2Pdf

Files2Pdf is a powerful Node.js package for converting PowerPoint (.ppt, .pptx) and Word (.doc, .docx) files to PDF format. Here's a step-by-step guide on how to use it effectively.

Installation

You can install Files2Pdf globally for command-line usage or locally within a project.

Global Installation

Install the package globally:

npm install -g files2pdf

Local Installation

Add Files2Pdf to your project:

npm install files2pdf

Using Files2Pdf

Command-Line Interface (CLI)

Once installed globally, Files2Pdf can be used directly from the terminal.

files2pdf <input-folder> <output-folder>

Parameters:

  • <input-folder>: Directory containing files you want to convert.
  • <output-folder>: Directory where the converted PDFs will be saved.

Example:

files2pdf ./input ./output

This will convert all supported files in the ./input folder and save the resulting PDFs in the ./output folder.

Programmatic Usage

If you prefer programmatic control, Files2Pdf offers an easy-to-use API:

const { processFolder } = require('files2pdf');
const path = require('path');

const inputFolder = path.resolve('./input');
const outputFolder = path.resolve('./output');

processFolder(inputFolder, outputFolder)
  .then(() => console.log('All files converted successfully!'))
  .catch(err => console.error('Error converting files:', err));

Features

  • Converts multiple files in a single operation.
  • Supports PowerPoint (.ppt, .pptx) and Word (.doc, .docx) formats.
  • Automatically skips unsupported file types.
  • Ensures the output folder exists before saving files.

Requirements

  1. Node.js: Version 14 or higher is recommended.
  2. LibreOffice: Ensure LibreOffice is installed on your system, as it's required for the conversion process.

Troubleshooting

Common Issues

  1. LibreOffice Not Found: Ensure LibreOffice is installed and accessible in your system's PATH.
  2. Unsupported File Types: Verify that your input files are supported formats.
  3. Permission Issues: Ensure the script has access to the input/output directories.

By following this guide, you can leverage Files2Pdf to streamline your file conversion workflows. Happy converting!