npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

libreoffice-file-converter

v3.1.1

Published

Simple NodeJS wrapper for libreoffice CLI for converting office documents to different formats

Downloads

1,629

Readme

libreoffice-file-converter

Simple NodeJS wrapper for libreoffice CLI for converting office documents to different formats.

Dependency

Please install libreoffice in /Applications (Mac), with your favorite package manager (Linux), or with the msi (Windows).

How to use

Constructor

LibreOfficeFileConverter constructor accepts optional configuration object.

options.binaryPaths

Array of paths to LibreOffice binary executables.

options.childProcessOptions

child_process.ExecFileOptions object. Can be used to configure such things as timeout, etc.

options.debug

Enables debug output for LibreOffice command execution.

options.tmpOptions

tmp.DirOptions object. Can be used to configure behavior of tmp package, which is used to create temporary folders for LibreOffice data.

LibreOfficeFileConverter.convert

Converts provided file, Buffer or Readable stream to the request format.

input

Input type: buffer | file | stream.

Defines corresponding field for input: buffer | inputPath | stream.

output

Output type: buffer | file | stream.

Requires outputPath field to be present when set to file.

Defines return type: Promise<Buffer> | Promise<void> | Promise<Readable>.

format

Conversion format.

inputFilter

LibreOffice input filter, see docs.

outputFilter

LibreOffice output filter, see docs.

filter

LibreOffice output filter, see docs.

Deprecated, use outputFilter instead.

options

Overrides for LibreOfficeFileConverter instance options.

Examples

From Buffer to Buffer.

import { readFile } from 'fs/promises';
import { join } from 'path';
import { LibreOfficeFileConverter } from 'libreoffice-file-converter';

const inputPath = join(__dirname, './resources/example.doc');

const run = async () => {
  const libreOfficeFileConverter = new LibreOfficeFileConverter({
    childProcessOptions: {
      timeout: 60 * 1000,
    },
  });

  const inputBuffer = await readFile(inputPath);

  const outputBuffer = await libreOfficeFileConverter.convert({
    buffer: inputBuffer,
    format: 'pdf',
    input: 'buffer',
    output: 'buffer'
  })
};

run();

From Buffer to file.

import { readFile } from 'fs/promises';
import { join } from 'path';
import { LibreOfficeFileConverter } from 'libreoffice-file-converter';

const inputPath = join(__dirname, './resources/example.doc');
const outputPath = join(__dirname, './resources/output/result.pdf');

const run = async () => {
  const libreOfficeFileConverter = new LibreOfficeFileConverter({
    childProcessOptions: {
      timeout: 60 * 1000,
    },
  });

  const inputBuffer = await readFile(inputPath);

  await libreOfficeFileConverter.convert({
    buffer: inputBuffer,
    format: 'pdf',
    input: 'buffer',
    output: 'fille',
    outputPath,
  })
};

run();

From Buffer to Readable stream.

import { readFile } from 'fs/promises';
import { join } from 'path';
import { LibreOfficeFileConverter } from 'libreoffice-file-converter';

const inputPath = join(__dirname, './resources/example.doc');

const run = async () => {
  const libreOfficeFileConverter = new LibreOfficeFileConverter({
    childProcessOptions: {
      timeout: 60 * 1000,
    },
  });

  const inputBuffer = await readFile(inputPath);

  const outputStream = await libreOfficeFileConverter.convert({
    buffer: inputBuffer,
    format: 'pdf',
    input: 'buffer',
    output: 'stream',
  })
};

run();

From file to Buffer.

import { readFile } from 'fs/promises';
import { join } from 'path';
import { LibreOfficeFileConverter } from 'libreoffice-file-converter';

const inputPath = join(__dirname, './resources/example.doc');

const run = async () => {
  const libreOfficeFileConverter = new LibreOfficeFileConverter({
    childProcessOptions: {
      timeout: 60 * 1000,
    },
  });

  const outputBuffer = await libreOfficeFileConverter.convert({
    format: 'pdf',
    input: 'file',
    inputPath,
    output: 'buffer',
  })
};

run();

From file to file.

import { readFile } from 'fs/promises';
import { join } from 'path';
import { LibreOfficeFileConverter } from 'libreoffice-file-converter';

const inputPath = join(__dirname, './resources/example.doc');
const outputPath = join(__dirname, './resources/output/result.pdf');

const run = async () => {
  const libreOfficeFileConverter = new LibreOfficeFileConverter({
    childProcessOptions: {
      timeout: 60 * 1000,
    },
  });

  await libreOfficeFileConverter.convert({
    format: 'pdf',
    input: 'file',
    inputPath,
    output: 'file',
    outputPath,
  })
};

run();

From file to Readable stream.

import { readFile } from 'fs/promises';
import { join } from 'path';
import { LibreOfficeFileConverter } from 'libreoffice-file-converter';

const inputPath = join(__dirname, './resources/example.doc');

const run = async () => {
  const libreOfficeFileConverter = new LibreOfficeFileConverter({
    childProcessOptions: {
      timeout: 60 * 1000,
    },
  });

  const outputStream = await libreOfficeFileConverter.convert({
    format: 'pdf',
    input: 'file',
    inputPath,
    output: 'stream',
  })
};

run();

From Readable stream to Buffer.

import { createReadStream } from 'fs';
import { join } from 'path';
import { LibreOfficeFileConverter } from 'libreoffice-file-converter';

const inputPath = join(__dirname, './resources/example.doc');

const run = async () => {
  const libreOfficeFileConverter = new LibreOfficeFileConverter({
    childProcessOptions: {
      timeout: 60 * 1000,
    },
  });

  const inputStream = createReadStream(inputPath);

  const outputBuffer = await libreOfficeFileConverter.convert({
    format: 'pdf',
    input: 'stream',
    output: 'buffer',
    stream: inputStream,
  })
};

run();

From Readable stream to file.

import { createReadStream } from 'fs';
import { join } from 'path';
import { LibreOfficeFileConverter } from 'libreoffice-file-converter';

const inputPath = join(__dirname, './resources/example.doc');
const outputPath = join(__dirname, './resources/output/result.pdf');

const run = async () => {
  const libreOfficeFileConverter = new LibreOfficeFileConverter({
    childProcessOptions: {
      timeout: 60 * 1000,
    },
  });

  const inputStream = createReadStream(inputPath);

  await libreOfficeFileConverter.convert({
    format: 'pdf',
    input: 'stream',
    output: 'file',
    outputPath,
    stream: inputStream,
  })
};

run();

From Readable stream to Readable stream.

import { createReadStream } from 'fs';
import { join } from 'path';
import { LibreOfficeFileConverter } from 'libreoffice-file-converter';

const inputPath = join(__dirname, './resources/example.doc');

const run = async () => {
  const libreOfficeFileConverter = new LibreOfficeFileConverter({
    childProcessOptions: {
      timeout: 60 * 1000,
    },
  });

  const inputStream = createReadStream(inputPath);

  const outputStream = await libreOfficeFileConverter.convert({
    format: 'pdf',
    input: 'stream',
    output: 'stream',
    stream: inputStream,
  })
};

run();