Registry / serialization / node-pptx-parser

node-pptx-parser

JSON →
library1.0.1jsnpmunverified

node-pptx-parser is a Node.js library designed for parsing Microsoft PowerPoint (PPTX) files. It offers functionalities to extract text content while preserving its original formatting, including line breaks and paragraph structures, or to parse the entire PPTX document into manageable JavaScript objects. Currently at version 1.0.1, the library provides a Promise-based API for asynchronous operations and is written entirely in TypeScript, ensuring type safety for developers. Its key differentiators include the accurate preservation of text formatting, its modern Promise-based API, and its TypeScript foundation, making it robust for backend applications requiring reliable PPTX content extraction. While no explicit release cadence is stated, it adheres to standard semantic versioning practices.

npm install node-pptx-parser
INSTALL
IMPORT
SIG · NODE-PPTX-PARSER
N
node-pptx-parser
serializationjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PptxParser
import PptxParser from 'node-pptx-parser';
import { PptxParser } from 'node-pptx-parser';
The library exports PptxParser as a default export for ESM.
PptxParser (CJS)
const PptxParser = require('node-pptx-parser').default;
const PptxParser = require('node-pptx-parser');
When using CommonJS, you must explicitly access the '.default' property due to ESM interop.
ParsedPresentation
import type { ParsedPresentation } from 'node-pptx-parser';
Import types separately for type checking without bundling the implementation.

Demonstrates how to initialize PptxParser with a file path and extract text content from all slides, as well as initiating a full presentation parse.

import PptxParser from 'node-pptx-parser'; import * as path from 'path'; import * as fs from 'fs'; async function main() { const filePath = path.join(__dirname, 'example.pptx'); // Create a dummy pptx file for demonstration if it doesn't exist // In a real scenario, this file would already be present. if (!fs.existsSync(filePath)) { console.log(`Please create a dummy 'example.pptx' file at ${filePath} for the quickstart to work.`); console.log('Skipping text extraction example.'); return; } const parser = new PptxParser(filePath); try { // Extract text from all slides const textContent = await parser.extractText(); // Print text from each slide textContent.forEach((slide) => { console.log(`\nSlide ${slide.id}:`); console.log(slide.text.join('\n')); }); // Example of full parsing const parsedContent = await parser.parse(); console.log('\nFull presentation structure parsed. Example slide 1 content:', parsedContent.slides[0]?.parsed); } catch (error: any) { console.error('Error during PPTX parsing:', error.message); if (error.message.includes('Invalid PPTX file structure')) { console.error('Ensure example.pptx is a valid PowerPoint file.'); } } } main();
Debug
Known issues
gotchaWhen using CommonJS (require), you must access the `default` export property (e.g., `require('pkg').default`). Failing to do so will result in `TypeError: PptxParser is not a constructor`.
fix
For CommonJS, change `const PptxParser = require('node-pptx-parser');` to `const PptxParser = require('node-pptx-parser').default;`
affects: >=1.0.0
gotchaThe library expects a valid file path to a PPTX file. Providing an incorrect path or a non-existent file will result in an `ENOENT` error or a 'File reading error'.
fix
Ensure the `filePath` provided to the `PptxParser` constructor is a correct, absolute, or relative path to an existing .pptx file.
affects: >=1.0.0
gotchaThe library explicitly throws errors for invalid PPTX file structures. This means corrupted or malformed PowerPoint files will cause the parsing methods to reject, requiring robust error handling.
fix
Wrap `PptxParser` method calls in `try...catch` blocks and specifically handle `error.message.includes('Invalid PPTX file structure')` to inform users about file integrity issues.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: PptxParser is not a constructor
Attempting to instantiate PptxParser using CommonJS `require()` without accessing the `.default` export.
fix
Change `const PptxParser = require('node-pptx-parser');` to `const PptxParser = require('node-pptx-parser').default;`
Error: ENOENT: no such file or directory, open 'non_existent.pptx'
The file path provided to the PptxParser constructor does not point to an existing file.
fix
Verify that the `filePath` argument is correct and the PPTX file exists at that location. Use `path.resolve()` or `path.join()` for robust path handling.
Error: Invalid PPTX file structure
The provided PPTX file is corrupted, malformed, or not a valid PowerPoint presentation document.
fix
Ensure the input file is a legitimate and uncorrupted .pptx file. The library relies on the underlying ZIP structure and XML content being valid.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
unzip-thisrequiredUsed internally to decompress the PPTX file, which is a ZIP-based archive format.
Agent activity
4 hits · last 30 days
node
4
Resources
node-pptx-parser — npm install node-pptx-parser · libregistry