### Install pptx-in-html-out Package
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/README.md
Install the package using npm. This command downloads and installs the library into your project.
```bash
npm install pptx-in-html-out
```
--------------------------------
### Initialize Converter with PPTX Buffer
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/api-reference/PPTXInHTMLOut.md
Example demonstrating how to read a PPTX file into a buffer and then initialize the PPTXInHTMLOut converter. This is a common setup for conversion tasks.
```javascript
import fs from 'fs/promises';
import { PPTXInHTMLOut } from 'pptx-in-html-out';
const pptxBuffer = await fs.readFile('presentation.pptx');
const converter = new PPTXInHTMLOut(pptxBuffer);
```
--------------------------------
### CLI Tool Integration Example
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt
Illustrates how the PPTXInHTMLOut library can be used within a command-line interface (CLI) tool. This example outlines the basic structure for accepting file paths as arguments and outputting HTML.
```javascript
import fs from 'fs';
import PPTXInHTMLOut from './src/index.js';
import process from 'process';
async function runCli() {
const args = process.argv.slice(2);
if (args.length < 2) {
console.error('Usage: node cli.js ');
process.exit(1);
}
const inputFile = args[0];
const outputFile = args[1];
try {
const pptxBuffer = fs.readFileSync(inputFile);
const converter = new PPTXInHTMLOut(pptxBuffer);
const html = await converter.toHTML();
fs.writeFileSync(outputFile, html);
console.log(`Successfully converted ${inputFile} to ${outputFile}`);
} catch (error) {
console.error(`Error processing ${inputFile}:`, error);
process.exit(1);
}
}
runCli();
```
--------------------------------
### Batch Conversion Example
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt
Shows how to perform batch conversion of multiple PPTX files to HTML. This is useful for processing a large number of presentations efficiently.
```javascript
import fs from 'fs';
import PPTXInHTMLOut from './src/index.js';
async function batchConvert(pptxFiles) {
for (const file of pptxFiles) {
try {
const pptxBuffer = fs.readFileSync(file);
const converter = new PPTXInHTMLOut(pptxBuffer);
const html = await converter.toHTML();
fs.writeFileSync(file.replace('.pptx', '.html'), html);
console.log(`Converted ${file} successfully.`);
} catch (error) {
console.error(`Failed to convert ${file}:`, error);
}
}
}
const filesToConvert = ['presentation1.pptx', 'presentation2.pptx'];
batchConvert(filesToConvert);
```
--------------------------------
### Example Usage of ToHTMLOptions
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/types.md
Demonstrates how to control style inclusion when converting PPTX to HTML.
```javascript
// Include default styles
const html1 = await converter.toHTML({ includeStyles: true });
// Use custom styles
const html2 = await converter.toHTML({ includeStyles: false });
```
--------------------------------
### Express.js Integration Example
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt
Demonstrates integrating the PPTXInHTMLOut library into an Express.js application to serve converted HTML content. This example shows handling file uploads and sending HTML responses.
```javascript
import express from 'express';
import multer from 'multer';
import PPTXInHTMLOut from './src/index.js';
const app = express();
const upload = multer({ storage: multer.memoryStorage() });
app.post('/convert', upload.single('pptxFile'), async (req, res) => {
if (!req.file) {
return res.status(400).send('No PPTX file uploaded.');
}
try {
const converter = new PPTXInHTMLOut(req.file.buffer);
const html = await converter.toHTML();
res.send(html);
} catch (error) {
res.status(500).send('Error converting PPTX: ' + error.message);
}
});
app.listen(3000, () => console.log('Server listening on port 3000'));
```
--------------------------------
### Example Output HTML Structure
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/quick-reference.md
Illustrates the basic structure of the generated HTML, including slide containers and content wrappers.
```html
Text content from shapes
Text extracted from images via OCR
```
--------------------------------
### Full Example with Debug Enabled
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/configuration.md
Demonstrates enabling debug logging before initiating the HTML conversion. When debug is enabled, the converter logs buffer size, files found, parsing progress, and more.
```javascript
import { PPTXInHTMLOut } from 'pptx-in-html-out';
const converter = new PPTXInHTMLOut(pptxBuffer);
converter.setDebug(true);
const html = await converter.toHTML();
// Console output will show detailed conversion logs
```
--------------------------------
### Debug Mode Example
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt
Demonstrates enabling and using the debug mode during PPTX to HTML conversion. Debug logs provide insights into the conversion process, which can be helpful for diagnosing issues.
```javascript
import PPTXInHTMLOut from "./src/index.js";
async function convertWithDebug() {
const pptxBuffer = Buffer.from("...");
const converter = new PPTXInHTMLOut(pptxBuffer);
converter.setDebug(true); // Enable debug output
const html = await converter.toHTML();
console.log("HTML generated with debug info.");
// Debug logs will be printed to the console during execution
}
convertWithDebug();
```
--------------------------------
### Custom Styling Example
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt
Shows how to apply custom CSS classes to HTML elements generated from the PPTX. This allows for detailed control over the presentation's appearance in HTML.
```javascript
import PPTXInHTMLOut from "./src/index.js";
async function convertWithCustomStyles() {
const pptxBuffer = Buffer.from("...");
const converter = new PPTXInHTMLOut(pptxBuffer);
const html = await converter.toHTML({
cssClasses: {
slide: "custom-slide",
title: "custom-title",
text: "custom-text"
}
});
console.log(html);
}
convertWithCustomStyles();
```
--------------------------------
### Usage Example: Convert PPTX to HTML
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/overview.md
Demonstrates how to read a PPTX file, create an instance of the PPTXInHTMLOut converter, convert it to HTML, and save the output. Ensure you have the 'fs/promises' and 'pptx-in-html-out' modules imported.
```javascript
import fs from 'fs/promises';
import { PPTXInHTMLOut } from 'pptx-in-html-out';
// Read PPTX file
const pptxBuffer = await fs.readFile('presentation.pptx');
// Create converter
const converter = new PPTXInHTMLOut(pptxBuffer);
// Convert to HTML
const html = await converter.toHTML();
// Save output
await fs.writeFile('output.html', html);
```
--------------------------------
### Extending the Class Example
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt
Demonstrates how to extend the PPTXInHTMLOut class to add custom functionality or override existing methods. This allows for creating specialized converters tailored to specific needs.
```javascript
import PPTXInHTMLOut from './src/index.js';
class CustomPPTXConverter extends PPTXInHTMLOut {
constructor(pptxBuffer) {
super(pptxBuffer);
}
async customMethod() {
console.log('Performing custom operation...');
// Access internal methods or properties if needed
// await this.parse();
return 'Custom result';
}
async toHTML(options) {
// Override toHTML to add custom logic before or after conversion
console.log('Calling custom toHTML...');
const html = await super.toHTML(options);
// Add custom post-processing to HTML
return html.replace('', '
Processed
');
}
}
// Usage:
// const pptxBuffer = Buffer.from('...');
// const customConverter = new CustomPPTXConverter(pptxBuffer);
// const customHtml = await customConverter.toHTML();
// console.log(customHtml);
// const customResult = await customConverter.customMethod();
```
--------------------------------
### Puppeteer Integration Example
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt
Shows how to integrate PPTXInHTMLOut with Puppeteer, a Node.js library for controlling headless Chrome or Chromium. This can be used for generating PDFs from the converted HTML or for advanced browser-based processing.
```javascript
import puppeteer from 'puppeteer';
import PPTXInHTMLOut from './src/index.js';
async function convertAndGeneratePdf(pptxBuffer) {
const converter = new PPTXInHTMLOut(pptxBuffer);
const html = await converter.toHTML();
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setContent(html);
const pdfBuffer = await page.pdf({ format: 'A4' });
await browser.close();
return pdfBuffer;
}
// Usage:
// const pptxBuffer = Buffer.from('...');
// convertAndGeneratePdf(pptxBuffer).then(pdf => {
// fs.writeFileSync('output.pdf', pdf);
// });
```
--------------------------------
### Method Chaining Example
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt
Illustrates the possibility of method chaining, although the current implementation of PPTXInHTMLOut does not explicitly support chaining for its primary methods like `toHTML` or `setDebug` due to their asynchronous nature or return values.
```javascript
// Note: The current API might not directly support chaining for async methods.
// This is a conceptual example.
// const converter = new PPTXInHTMLOut(pptxBuffer)
// .setDebug(true) // Hypothetical chaining
// .toHTML();
```
--------------------------------
### Error Recovery Example
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt
Illustrates strategies for error recovery during the conversion process. This might involve attempting to continue processing other parts of the presentation even if some slides or elements fail to convert.
```javascript
import PPTXInHTMLOut from './src/index.js';
async function convertWithRecovery() {
const pptxBuffer = Buffer.from('...');
const converter = new PPTXInHTMLOut(pptxBuffer);
// Assume toHTML has an option or internal logic for error recovery
// For example, if a slide fails, it might be skipped or replaced with an error placeholder.
const html = await converter.toHTML({
// hypothetical option for recovery
// skipOnSlideError: true
});
console.log('Conversion attempted with recovery mechanisms.');
}
convertWithRecovery();
```
--------------------------------
### Custom HTML Generation Example
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt
Demonstrates advanced customization of the HTML output by providing custom functions for generating specific HTML elements. This allows for fine-grained control over the structure and content of the output.
```javascript
import PPTXInHTMLOut from './src/index.js';
async function convertWithCustomHTML() {
const pptxBuffer = Buffer.from('...');
const converter = new PPTXInHTMLOut(pptxBuffer);
const customHtmlGenerator = {
slide: (slideData) => `
${slideData.content}
`,
// Add other custom generators for headings, text, images, etc.
};
const html = await converter.toHTML({
customHtmlGenerator: customHtmlGenerator
});
console.log(html);
}
convertWithCustomHTML();
```
--------------------------------
### Error Handling Example
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt
Illustrates how to handle potential errors during the PPTX to HTML conversion process using a try-catch block. Catches specific error messages related to input validation and file parsing.
```javascript
import PPTXInHTMLOut from "./src/index.js";
async function convertWithErrors() {
try {
const invalidBuffer = Buffer.from("not a pptx");
const converter = new PPTXInHTMLOut(invalidBuffer);
await converter.toHTML();
} catch (error) {
if (error.message.includes("Invalid PPTX file")) {
console.error("Caught an invalid PPTX file error:", error.message);
} else {
console.error("An unexpected error occurred:", error);
}
}
}
convertWithErrors();
```
--------------------------------
### Handling Thrown Errors During Conversion
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/errors.md
This example shows how to use a try-catch block to gracefully handle errors that are thrown by the toHTML() method. This is essential for preventing application crashes and providing user feedback.
```javascript
try {
const html = await converter.toHTML();
} catch (error) {
console.error('Conversion failed:', error.message);
// Handle error appropriately
}
```
--------------------------------
### Internal Property Access Example
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt
Shows how to access internal properties of the PPTXInHTMLOut class. This is generally discouraged as internal properties are not part of the public API and may change without notice.
```javascript
import PPTXInHTMLOut from './src/index.js';
// Accessing internal properties is generally not recommended.
// This is for demonstration purposes only.
const pptxBuffer = Buffer.from('...');
const converter = new PPTXInHTMLOut(pptxBuffer);
// Example: Accessing parsed slides (internal property)
// Note: The actual property name might differ and is subject to change.
// const parsedSlides = converter._parsedSlides;
// console.log(parsedSlides);
```
--------------------------------
### Create a Command-Line Interface (CLI) Tool
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/advanced-usage.md
Builds a simple CLI tool that takes input and output file paths as arguments, converts a PPTX file to HTML, and saves the result. Includes basic argument parsing and error handling.
```javascript
#!/usr/bin/env node
import fs from 'fs/promises';
import { PPTXInHTMLOut } from 'pptx-in-html-out';
const [inputFile, outputFile] = process.argv.slice(2);
if (!inputFile || !outputFile) {
console.error('Usage: pptx-convert ');
process.exit(1);
}
try {
const pptxBuffer = await fs.readFile(inputFile);
const converter = new PPTXInHTMLOut(pptxBuffer);
const html = await converter.toHTML();
await fs.writeFile(outputFile, html);
console.log(`✓ Converted: ${inputFile} → ${outputFile}`);
} catch (error) {
console.error('Error:', error.message);
process.exit(1);
}
```
--------------------------------
### Package Entry Point Configuration
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/configuration.md
Configuration snippet from package.json defining the main entry point for the library's exports.
```json
"main": "src/index.js"
```
--------------------------------
### PPTXInHTMLOut Class Constructor and Methods
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/INDEX.md
Demonstrates the basic usage of the PPTXInHTMLOut class, including instantiation with a PPTX buffer and converting it to HTML. Also shows how to enable debug logging.
```javascript
import { PPTXInHTMLOut } from 'pptx-in-html-out';
// Constructor
const converter = new PPTXInHTMLOut(pptxBuffer);
// Public methods
const html = await converter.toHTML(options);
converter.setDebug(enabled);
```
--------------------------------
### Constructor
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/quick-reference.md
Initializes the PPTXInHTMLOut converter with the PPTX file content. The constructor expects the PPTX file to be provided as a Buffer.
```APIDOC
## Constructor `PPTXInHTMLOut(pptxBuffer)`
### Description
Initializes the converter with the PPTX file content.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
* `pptxBuffer` (Buffer) - Required - The PPTX file content as a Buffer.
### Request Example
```javascript
import { PPTXInHTMLOut } from 'pptx-in-html-out';
import fs from 'fs/promises';
const pptxBuffer = await fs.readFile('presentation.pptx');
const converter = new PPTXInHTMLOut(pptxBuffer);
```
### Response
N/A (Constructor does not return a value directly, but initializes an object).
#### Success Response (N/A)
#### Response Example
N/A
```
--------------------------------
### Get Slide Relationships
Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/api-reference/PPTXInHTMLOut.md
Retrieves the relationships XML for a specific slide, mapping relationship IDs to their target files. This helps in understanding how different resources are linked within a slide.
```javascript
async getSlideRels(slideFile): Promise