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

msoffice2pdf

v1.0.12

Published

Convert Microsoft Office documents (ppt, pptx, doc, docx, xls, xlsx) to PDF.

Downloads

59

Readme

msoffice2pdf

Convert Microsoft Office documents (ppt, pptx, doc, docx, xls, xlsx) to PDF.
Click here to see the change log.

Web Demo

Click here to learn how to use the web demo.

Evidence of PDF conversion results for office documents

Evidence can be referenced by clicking here.

Supported OS

  • Linux
  • MAC
  • Windows

Requirements

LibreOffice version 5.3 or higher is required.
See https://www.libreoffice.org/get-help/install-howto/ for installation instructions.

  • For example, on Amazon Linux, follow these steps to install LibreOffice
    1. Install LibreOffice.

      sudo amazon-linux-extras enable libreoffice
      sudo yum -y install libreoffice libreoffice-langpack-ja
    2. Check fonts.

      yum list | grep ipa- | grep fonts
      # ipa-gothic-fonts.noarch                003.03-5.amzn2                @amzn2-core
      # ipa-mincho-fonts.noarch                003.03-5.amzn2                amzn2-core
      # ipa-pgothic-fonts.noarch               003.03-5.amzn2                amzn2-core
      # ipa-pmincho-fonts.noarch               003.03-5.amzn2                amzn2-core
    3. Install fonts.
      Install the fonts found earlier.

      sudo yum -y install \
          ipa-gothic-fonts \
          ipa-mincho-fonts \
          ipa-pgothic-fonts \
          ipa-pmincho-fonts

      If you want to add more fonts, place font files such as ttf and ttc in the home directory of the user running msoffice2pdf (~/.local/share/fonts/).

  • How to install the latest stable LibreOffice.
    1. Uninstall the installed LibreOffice.

      sudo yum -y remove libreoffice-langpack-ja libreoffice
    2. Install LibreOffice.

      cd ~
      wget https://download.documentfoundation.org/libreoffice/stable/7.4.3/rpm/x86_64/LibreOffice_7.4.3_Linux_x86-64_rpm.tar.gz
      tar -zxvf LibreOffice_7.4.3_Linux_x86-64_rpm.tar.gz
      sudo yum -y install LibreOffice_7.4.3.2_Linux_x86-64_rpm//RPMS/*.rpm

      If an error occurs here that libcairo.so.2 is missing, install cairo.

      sudo yum -y install cairo

      Check the version of LibreOffice installed.

      libreoffice7.4 --version
      # LibreOffice 7.4.3.2 1048a8393ae2eeec98dff31b5c133c5f1d08b890
    3. Installed Japanese language pack.

      cd ~
      wget http://download.documentfoundation.org/libreoffice/stable/7.4.3/rpm/x86_64/LibreOffice_7.4.3_Linux_x86-64_rpm_langpack_ja.tar.gz
      tar -zxvf LibreOffice_7.4.3_Linux_x86-64_rpm_langpack_ja.tar.gz
      sudo yum -y install LibreOffice_7.4.3.2_Linux_x86-64_rpm_langpack_ja/RPMS/*.rpm
    4. Test. Convert Word to PDF.

      libreoffice7.4 --headless --convert-to pdf:writer_pdf_Export --outdir convert test.docx

Installation

npm install --save msoffice2pdf

Usage

  1. Load msoffice2pdf.

    const msoffice2pdf = require('msoffice2pdf');

    in Node >v7 you can do (very pretty):

    import msoffice2pdf from 'msoffice2pdf'
  2. Convert office documents to PDF.

    await msoffice2pdf('sample.pptx', 'sample.pdf');

    You can also specify the LibreOffice that msoffice2pdf invokes internally.
    If libreOffice is not specified, it will It will automatically look for the following.

    • For Linux:
      /usr/bin/libreoffice
      /usr/bin/soffice
      /snap/bin/libreoffice
    • For MAC:
      /Applications/LibreOffice.app/Contents/MacOS/soffice
    • For WIndows:
      C:\Program Files\LibreOffice*\program\soffice.exe
      C:\Program Files (x86)\LibreOffice*\program\soffice.exe
    await msoffice2pdf('sample.pptx', 'sample.pdf', {
      libreOfficeBinaryPath: '/opt/libreoffice/program/soffice'
    });

    Use the language option to specify the language of the input file.
    Click here for available language options.

    await msoffice2pdf('sample.pptx', 'sample.pdf', {
      language: 'ja'
    });

msoffice2pdf API

Syntax

msoffice2pdf(inputPath, outputPath);
msoffice2pdf(inputPath, outputPath, {
  libreOfficeBinaryPath: '/opt/libreoffice/program/soffice'
});
msoffice2pdf(inputPath, outputPath, {
  language: 'ja'
});
msoffice2pdf(inputPath, outputPath, {
  libreOfficeBinaryPath: '/opt/libreoffice/program/soffice',
  language: 'ja'
});

Parameters

  • inputPath: string
    Paths to office documents (ppt, pptx, doc, docx, xls, xlsx).
  • outputPath: string
    PDF Path.
  • options.libreOfficeBinaryPath?: string
    The path to the libreOffice executable (soffice) that you installed.
    The default is to use the file found by looking for the following file.
    • For Linux:
      /usr/bin/libreoffice
      /usr/bin/soffice
      /snap/bin/libreoffice
    • For MAC:
      /Applications/LibreOffice.app/Contents/MacOS/soffice
    • For WIndows:
      C:\Program Files\LibreOffice*\program\soffice.exe
      C:\Program Files (x86)\LibreOffice*\program\soffice.exe
  • options.language?: string
    Document Language. Default is undefined.
    Click here for available language options.

Return value

Promise<void>

Throws

  • UnsupportedOSError
    For unsupported operating systems. msoffice2pdf supports Linux, MAC, and Windows.
  • LibreOfficeNotFoundError
    LibreOffice executable not found, please install LibreOffice.
  • SpecifiedLibreOfficeNotFoundError
    The specified LibreOffice executable cannot be found.
  • InputFileNotFoundError
    The input file to be converted cannot be found.
  • UnsupportedFileError
    An unsupported file was specified as the conversion source.
    msoffice2pdf supports ppt, pptx, doc, docx, xls, xlsx as conversion sources.
  • UnsupportedLanguageError
    An unsupported language was specified.

Unit testing

npm run test
# > [email protected] test
# > jest
# 
#  PASS  tests/case-of-exception.test.js
#   Case of exception
#     √ Should throw an error for unsupported OS (159 ms)
#     √ Should throw an error for unsupported input file (2 ms)
#     √ Should throw an error for input file not found (2 ms)
#     √ Should throw an error for LibreOffice not found (2 ms)
#     √ Should throw an error for unsupported language option (3 ms)
# 
#  PASS  tests/convert-word97-2003-to-pdf.test.js (19.745 s)
#   Convert Word97-2003 to PDF
#     √ Should convert Word97-2003 to PDF (9283 ms)
#     √ Should convert Word97-2003 to PDF using the language option (8111 ms)
# 
#  PASS  tests/convert-word-to-pdf.test.js (19.993 s)
#   Convert Word to PDF
#     √ Should convert Word to PDF (9585 ms)
#     √ Should convert Word to PDF using the language option (8199 ms)
# 
#  PASS  tests/convert-powerpoint97-2003-to-pdf.test.js (20.683 s)
#   Convert PowerPoint97-2003 to PDF
#     √ Should convert PowerPoint97-2003 to PDF (9990 ms)
#     √ Should convert PowerPoint97-2003 to PDF using the language option (8349 ms)
# 
#  PASS  tests/convert-powerpoint-to-pdf.test.js (21.484 s)
#   Convert PowerPoint to PDF
#     √ Should convert PowerPoint to PDF (10715 ms)
#     √ Should convert PowerPoint to PDF using the language option (8599 ms)
# 
#  PASS  tests/convert-excel97-2003-to-pdf.test.js (21.665 s)
#   Convert Excel97-2003 to PDF
#     √ Should convert Excel97-2003 to PDF (10967 ms)
#     √ Should convert Excel97-2003 to PDF using the language option (8539 ms)
# 
#  PASS  tests/convert-excel-to-pdf.test.js (21.985 s)
#   Convert Excel to PDF
#     √ Should convert Excel to PDF (11462 ms)
#     √ Should convert Excel to PDF using the language option (8254 ms)
# 
# Test Suites: 7 passed, 7 total
# Tests:       17 passed, 17 total
# Snapshots:   0 total
# Time:        22.716 s, estimated 24 s
# Ran all test suites.

Author

Takuya Motoshima

License

MIT