### 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 ``` -------------------------------- ### PPTXInHTMLOut Constructor Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt Initializes a new instance of the PPTXInHTMLOut class. It takes the PowerPoint presentation as a Buffer. ```APIDOC ## PPTXInHTMLOut Constructor ### Description Initializes a new instance of the PPTXInHTMLOut class with the provided presentation data. ### Method Constructor ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **pptxBuffer** (Buffer) - Required - The PowerPoint presentation file content as a Buffer. ### Request Example ```javascript const fs = require('fs'); const pptxBuffer = fs.readFileSync('presentation.pptx'); const converter = new PPTXInHTMLOut(pptxBuffer); ``` ### Response #### Success Response (200) An instance of the PPTXInHTMLOut class. #### Response Example ```javascript // Instance of PPTXInHTMLOut ``` ### Throws * "Input must be a Buffer" - If the provided input is not a Buffer. * "Invalid PPTX file: missing {file}" - If the PPTX file is corrupted or missing essential components. * "Invalid PPTX file: no slides found" - If the presentation contains no slides. ``` -------------------------------- ### File Organization Structure Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/README.md Illustrates the directory structure of the project, showing the location of markdown files and the API reference subdirectory. ```bash # /workspace/home/output/ # ├── README.md (this file) # ├── INDEX.md (master index) # ├── overview.md # ├── types.md # ├── configuration.md # ├── errors.md # ├── quick-reference.md # ├── advanced-usage.md # └── api-reference/ # └── PPTXInHTMLOut.md ``` -------------------------------- ### Instantiate PPTXInHTMLOut Converter Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/README.md Create an instance of the PPTXInHTMLOut class. The constructor requires the PPTX file content as a Buffer. ```javascript const converter = new PPTXInHTMLOut(pptxBuffer); ``` -------------------------------- ### Get Image Data from Slide Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/api-reference/PPTXInHTMLOut.md Retrieves image buffer data for a specific relationship ID within a slide file. Use this when you need to access individual image assets referenced in a slide. ```javascript async getImageData(slideFile, rId): Promise ``` -------------------------------- ### PPTXInHTMLOut Constructor Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/README.md Initializes the PPTXInHTMLOut converter with the PPTX file data. ```APIDOC ## Constructor `PPTXInHTMLOut` ### Description Initializes the converter with the PPTX file data. ### Parameters #### Path Parameters - **pptxBuffer** (Buffer) - Required - Buffer containing the PPTX file data. ``` -------------------------------- ### Preview PPTX Conversion with Headless Browser Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/advanced-usage.md Uses Puppeteer to launch a headless browser, load the converted HTML, and generate a screenshot and PDF preview of the presentation. Requires 'puppeteer'. ```javascript import puppeteer from 'puppeteer'; import { PPTXInHTMLOut } from 'pptx-in-html-out'; async function previewPPTX(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, { waitUntil: 'networkidle0' }); // Take screenshot await page.screenshot({ path: 'preview.png' }); // Generate PDF await page.pdf({ path: 'preview.pdf' }); await browser.close(); } ``` -------------------------------- ### Import Syntax for PPTXInHTMLOut Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/overview.md Shows the correct way to import the main PPTXInHTMLOut class from the library using ESM syntax. This is the only exported component from the library. ```javascript import { PPTXInHTMLOut } from 'pptx-in-html-out'; ``` -------------------------------- ### Convert to HTML with Options Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/quick-reference.md Convert PPTX to HTML. Use includeStyles: true for default CSS, or false for custom styling. ```javascript const html = await converter.toHTML(); // With default styles const html = await converter.toHTML({ includeStyles: true }); // Explicit const html = await converter.toHTML({ includeStyles: false }); // Custom styling ``` -------------------------------- ### Compare PPTX Conversions Using Hashes Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/advanced-usage.md This function compares two PPTX files by converting them to HTML and then comparing the SHA-256 hashes of the generated HTML. It requires the 'crypto' and 'fs' modules. Ensure files are read correctly before hashing. ```javascript import crypto from 'crypto'; async function compareConversions(file1, file2) { const buf1 = await fs.readFile(file1); const buf2 = await fs.readFile(file2); const converter1 = new PPTXInHTMLOut(buf1); const converter2 = new PPTXInHTMLOut(buf2); const html1 = await converter1.toHTML(); const html2 = await converter2.toHTML(); const hash1 = crypto.createHash('sha256').update(html1).digest('hex'); const hash2 = crypto.createHash('sha256').update(html2).digest('hex'); console.log('File 1 hash:', hash1); console.log('File 2 hash:', hash2); console.log('Match:', hash1 === hash2); } ``` -------------------------------- ### Batch Convert PPTX Files in a Directory Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/advanced-usage.md Converts all PPTX files within a specified input directory to HTML and saves them to an output directory. Requires 'fs/promises' and 'path' modules. ```javascript import fs from 'fs/promises'; import path from 'path'; import { PPTXInHTMLOut } from 'pptx-in-html-out'; async function convertDirectory(inputDir, outputDir) { const files = await fs.readdir(inputDir); const pptxFiles = files.filter(f => f.endsWith('.pptx')); console.log(`Found ${pptxFiles.length} PPTX files`); for (const file of pptxFiles) { const inputPath = path.join(inputDir, file); const outputPath = path.join(outputDir, file.replace('.pptx', '.html')); try { console.log(`Converting: ${file}`); const pptxBuffer = await fs.readFile(inputPath); const converter = new PPTXInHTMLOut(pptxBuffer); const html = await converter.toHTML(); await fs.writeFile(outputPath, html); console.log(`✓ Saved to: ${outputPath}`); } catch (error) { console.error(`✗ Failed to convert ${file}:`, error.message); } } } // Usage await convertDirectory('./presentations', './html-output'); ``` -------------------------------- ### Custom Styling for HTML Output Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/configuration.md Demonstrates how to obtain HTML content without default styles and then embed it within a custom HTML structure, including a link to external CSS. ```javascript import { PPTXInHTMLOut } from 'pptx-in-html-out'; const converter = new PPTXInHTMLOut(pptxBuffer); // Get HTML without default styles const html = await converter.toHTML({ includeStyles: false }); // Add custom styles const customHTML = ` ${html.match(/([\s\S]*)<\/body>/)[1]} `; ``` -------------------------------- ### Enable Debug Logging for Troubleshooting Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/errors.md Activate detailed parsing logs by calling `setDebug(true)` on the converter instance. This is useful for diagnosing issues during conversion. ```javascript const converter = new PPTXInHTMLOut(pptxBuffer); converter.setDebug(true); const html = await converter.toHTML(); // Check console for detailed parsing logs ``` -------------------------------- ### Convert with Custom Stylesheet Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/quick-reference.md Generate HTML without default styles and manually inject a custom CSS file link. ```javascript const html = await converter.toHTML({ includeStyles: false }); const customHTML = ` ${html.match(/([\s\S]*)<\/body>/)[1]} `; ``` -------------------------------- ### Basic PPTX to HTML Conversion Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/configuration.md This is the recommended way to convert a PPTX file to HTML. It reads the PPTX file, performs the conversion, and writes the resulting HTML to a file. ```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); const html = await converter.toHTML(); await fs.writeFile('output.html', html); ``` -------------------------------- ### Convert PPTX to HTML via Express.js Server Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/advanced-usage.md Sets up an Express.js server endpoint to receive PPTX file uploads, convert them to HTML using the library, and return the HTML. Uses Multer for file handling. ```javascript import express from 'express'; import multer from 'multer'; import { PPTXInHTMLOut } from 'pptx-in-html-out'; const app = express(); const upload = multer({ storage: multer.memoryStorage() }); app.post('/convert', upload.single('pptx'), async (req, res) => { try { if (!req.file) { return res.status(400).json({ error: 'No file uploaded' }); } const converter = new PPTXInHTMLOut(req.file.buffer); const html = await converter.toHTML(); res.header('Content-Type', 'text/html'); res.send(html); } catch (error) { res.status(400).json({ error: error.message, details: error.message }); } }); app.listen(3000); ``` -------------------------------- ### toHTML Method Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/README.md Converts the presentation to HTML. Optionally, styles can be excluded from the output. ```APIDOC ## `toHTML(options)` ### Description Converts the presentation to HTML. ### Parameters #### Query Parameters - **options** (object) - Optional - Configuration object - **includeStyles** (boolean) - Optional - Default: `true` - Whether to include default styles in the output HTML ### Returns - `Promise` - The generated HTML content ### Request Example ```javascript // With default styles const html = await converter.toHTML(); // Without default styles (for custom styling) const html = await converter.toHTML({ includeStyles: false }); ``` ``` -------------------------------- ### Basic PPTX to HTML Conversion Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/README.md Convert a PPTX file to HTML using the PPTXInHTMLOut class. Ensure the PPTX file is read into a buffer before instantiation. ```javascript import fs from 'fs/promises'; import { PPTXInHTMLOut } from 'pptx-in-html-out'; // Read your PPTX file into a buffer const pptxBuffer = await fs.readFile('presentation.pptx'); // Create converter instance with buffer const converter = new PPTXInHTMLOut(pptxBuffer); // Convert to HTML const html = await converter.toHTML(); console.log(html); // Or write to a file await fs.writeFile('output.html', html); ``` -------------------------------- ### toHTML Method Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/quick-reference.md Converts the PPTX content to an HTML string. This is the primary method for generating the HTML output. It accepts an options object to control style inclusion. ```APIDOC ## Method `toHTML(options)` ### Description Converts the PPTX presentation to a complete HTML document string. Optionally includes default CSS styles. ### Method `toHTML` ### Endpoint N/A (This is a method of the `PPTXInHTMLOut` class) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * `options` (object) - Optional - Configuration for the conversion. * `includeStyles` (boolean, default: true) - If true, includes default CSS styles in the output HTML. If false, no default styles are included. ``` ```APIDOC ### Request Example ```javascript // With default styles const html = await converter.toHTML(); // With explicit styles (default behavior) const html = await converter.toHTML({ includeStyles: true }); // Without default styles const html = await converter.toHTML({ includeStyles: false }); ``` ### Response #### Success Response (200) - Returns a `Promise` which resolves to the complete HTML document as a string. ``` ```APIDOC #### Response Example ```html
...
``` ``` -------------------------------- ### PPTXInHTMLOut Class Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/overview.md The main class for converting PPTX files to HTML. It provides methods to initialize the converter, perform the conversion, and control debug logging. ```APIDOC ## Class: PPTXInHTMLOut ### Description The primary class for converting PPTX files to HTML. Instantiate this class with the PPTX file content as a Buffer. ### Methods - **`constructor(pptxBuffer: Buffer)`** - **Description:** Creates an instance of the PPTXInHTMLOut converter. - **Parameters:** - `pptxBuffer` (Buffer) - Required - The content of the PPTX file as a Buffer. - **`toHTML(options?: ToHTMLOptions): Promise`** - **Description:** Initiates the conversion of the PPTX file to an HTML string. Accepts optional configuration for styling. - **Parameters:** - `options` (ToHTMLOptions) - Optional - Configuration options for the HTML output. - `includeStyles` (boolean) - Optional - Whether to include default CSS styles. Defaults to `true`. - **Returns:** `Promise` - A promise that resolves with the generated HTML string. - **`setDebug(enabled: boolean): this`** - **Description:** Enables or disables debug logging for the conversion process. - **Parameters:** - `enabled` (boolean) - Required - `true` to enable debug logging, `false` to disable. - **Returns:** `this` - Returns the instance for method chaining. ``` -------------------------------- ### XML Parsing Options Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/configuration.md Displays the internal xml2js options used for parsing PPTX XML files. These options are fixed and cannot be modified externally. ```json { "explicitArray": false, // Don't wrap single elements "explicitRoot": true, // Keep root element "normalizeTags": true, // Normalize to lowercase "tagNameProcessors": [stripNS], // Strip namespace prefixes "attrNameProcessors": [stripNS], // Strip namespace prefixes "attrValueProcessors": [identity],// Preserve values "xmlns": true // Include namespace info } ``` -------------------------------- ### PPTXInHTMLOut Class Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/INDEX.md The main class for converting PPTX files to HTML. It takes the PPTX file content as a Buffer and provides methods to perform the conversion and control debugging. ```APIDOC ## Class: PPTXInHTMLOut ### Description Provides functionality to convert PowerPoint (PPTX) files into HTML. ### Constructor #### Parameters - **pptxBuffer** (Buffer) - Required - The PowerPoint file content as a Buffer. ### Methods #### `toHTML(options?)` ##### Description Converts the loaded PPTX content to an HTML string. ##### Parameters - **options** (object) - Optional. Configuration for the HTML output. - **includeStyles** (boolean) - Optional. Whether to include default CSS styles. Defaults to `true`. ##### Returns - `Promise` - A promise that resolves with the generated HTML string. #### `setDebug(enabled)` ##### Description Enables or disables debug logging for the conversion process. ##### Parameters - **enabled** (boolean) - Required. `true` to enable debug logging, `false` to disable. ##### Returns - `this` - Returns the converter instance for chaining. ``` -------------------------------- ### HTML Output Structure Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/overview.md Illustrates the basic structure of the generated HTML5 document. It includes head elements for character set and viewport, and a body containing slide divs. Styles are optionally included. ```html
``` -------------------------------- ### Validate PPTX Buffer Before Conversion Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/errors.md Ensure the file is read correctly as a buffer before initializing the converter. This prevents errors during the conversion process. ```javascript import fs from 'fs/promises'; import { PPTXInHTMLOut } from 'pptx-in-html-out'; async function convertPPTX(filePath) { try { const pptxBuffer = await fs.readFile(filePath); if (!Buffer.isBuffer(pptxBuffer)) { throw new Error('Failed to read file as buffer'); } const converter = new PPTXInHTMLOut(pptxBuffer); return await converter.toHTML(); } catch (error) { console.error('Conversion error:', error.message); throw error; // Re-throw or handle as needed } } ``` -------------------------------- ### Enable Debug Mode for Troubleshooting Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/configuration.md Enables debug logging within the converter to provide detailed output during conversion, which is useful for diagnosing issues. Errors during conversion are caught and logged. ```javascript import { PPTXInHTMLOut } from 'pptx-in-html-out'; const converter = new PPTXInHTMLOut(pptxBuffer); // Enable debug logging for detailed output converter.setDebug(true); try { const html = await converter.toHTML(); } catch (error) { console.error('Conversion failed:', error.message); // Debug output will show where the failure occurred } ``` -------------------------------- ### Monitor Memory Usage During Conversion Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/advanced-usage.md Demonstrates how to track memory consumption before and after converting a PPTX file to HTML. Useful for identifying memory leaks or high usage with large presentations. ```javascript const converter = new PPTXInHTMLOut(pptxBuffer); console.log('Initial memory:', process.memoryUsage().heapUsed); const html = await converter.toHTML(); console.log('After conversion:', process.memoryUsage().heapUsed); ``` -------------------------------- ### PPTXInHTMLOut Class API Reference Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt This section details the main class of the PPTXInHTMLOut library, including its constructor, public methods, parameters, return types, and associated error conditions. ```APIDOC ## Class: PPTXInHTMLOut ### Description Provides functionality to convert PowerPoint presentations (.pptx) into HTML. ### Constructor `new PPTXInHTMLOut(options)` Initializes a new instance of the PPTXInHTMLOut class. #### Parameters - **options** (object) - Optional - Configuration options for the converter. See `configuration.md` for details. ### Methods #### `render(pptxFilePath, outputDir)` Renders a PowerPoint presentation to HTML. ##### Parameters - **pptxFilePath** (string) - Required - The path to the input .pptx file. - **outputDir** (string) - Required - The directory where the HTML output will be saved. ##### Returns - `Promise` - A promise that resolves when the rendering is complete. ##### Throws - `PPTXParseError` - If the .pptx file cannot be parsed. - `HTMLGenerationError` - If there is an error during HTML generation. #### `destroy()` Cleans up resources used by the converter instance. ##### Returns - `void` ### Configuration Options See `configuration.md` for a detailed list of constructor and method options, including default values. ### Error Handling See `errors.md` for a comprehensive list of error types, their triggers, and how to handle them. ### Examples ```javascript import PPTXInHTMLOut from 'pptx-in-html-out'; async function convertPresentation() { const converter = new PPTXInHTMLOut({ // Optional configuration options }); try { await converter.render('/path/to/your/presentation.pptx', './output'); console.log('Presentation rendered successfully!'); } catch (error) { console.error('Error rendering presentation:', error); } finally { converter.destroy(); } } convertPresentation(); ``` ``` -------------------------------- ### Package Type Configuration Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/configuration.md Configuration snippet showing the 'type': 'module' setting in package.json, indicating the library is published as an ESM package. ```json "type": "module" ``` -------------------------------- ### Unsupported CommonJS Require Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/configuration.md Illustrates the unsupported method of importing the PPTXInHTMLOut class using CommonJS require(). This syntax will not work with the library. ```javascript // CommonJS require() is not supported const { PPTXInHTMLOut } = require('pptx-in-html-out'); ``` -------------------------------- ### Convert PPTX to HTML with Default Styles Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/README.md Convert the loaded PPTX presentation to HTML. By default, this method includes necessary styles for rendering. ```javascript // With default styles const html = await converter.toHTML(); ``` -------------------------------- ### generateHTML(slides, options) Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/api-reference/PPTXInHTMLOut.md Generates the complete HTML document from an array of parsed slide objects. Optional configuration can be provided to customize the output. ```APIDOC ## generateHTML(slides, options) ### Description Generates the complete HTML document from parsed slides. ### Method `async generateHTML(slides, options = { includeStyles: true }): Promise` ### Parameters #### Path Parameters - **slides** (Array) - Yes - Array of parsed slide objects - **options** (object) - No - Configuration options (see `toHTML()` for details) ### Response #### Success Response - **string** - Complete HTML document string ``` -------------------------------- ### toHTML Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt Converts the loaded PowerPoint presentation into an HTML representation. ```APIDOC ## toHTML ### Description Converts the PowerPoint presentation to an HTML string. This method can be configured with various options to customize the output. ### Method `toHTML(options)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **options** (object) - Optional - Configuration options for the HTML conversion. - **debug** (boolean) - Optional - Enables debug logging. Defaults to false. - **cssClassPrefix** (string) - Optional - Prefix for generated CSS classes. Defaults to 'pptx-'. - **embedImages** (boolean) - Optional - Whether to embed images as base64 data URIs. Defaults to false. - **customStyle** (string) - Optional - Custom CSS to inject into the HTML. ### Request Example ```javascript const html = await converter.toHTML({ debug: true, cssClassPrefix: 'my-pptx-', embedImages: true }); ``` ### Response #### Success Response (200) * **html** (string) - The generated HTML string representing the presentation. #### Response Example ```html
...
...
``` ### Throws * XML parsing errors * Image processing warnings * Slide parsing errors * Relationship errors * OCR processing errors ``` -------------------------------- ### Handle Potential Partial HTML Output Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/errors.md Be aware that the `toHTML()` method might return partial output if non-critical errors occur during conversion. Always check the generated HTML for completeness, especially for missing images. ```javascript try { const html = await converter.toHTML(); // html may contain some slides and missing images // Check the output for completeness } catch (error) { // Critical errors that stop conversion entirely } ``` -------------------------------- ### Parse Presentation Relationships Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/api-reference/PPTXInHTMLOut.md Parses the main relationship files (.rels) of the presentation to map resource IDs to their locations. This is a foundational step for understanding the PPTX structure. ```javascript async parseRelationships(): Promise ``` -------------------------------- ### Method Chaining for Conversion Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/quick-reference.md Chain multiple method calls, including instantiation, debug setting, and conversion, in a single statement. ```javascript const html = await new PPTXInHTMLOut(pptxBuffer) .setDebug(true) .toHTML({ includeStyles: true }); ``` -------------------------------- ### Troubleshoot with Debug Mode Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/quick-reference.md Enable debug logging to view detailed parsing information in the console for troubleshooting. ```javascript converter.setDebug(true); const html = await converter.toHTML(); // Check console for detailed parsing information ``` -------------------------------- ### Faster Conversion by Disabling OCR Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/advanced-usage.md Subclasses PPTXInHTMLOut to override image processing and skip OCR, significantly speeding up conversion at the cost of extracted text. Useful when OCR is not needed. ```javascript import { PPTXInHTMLOut } from 'pptx-in-html-out'; class FastConverter extends PPTXInHTMLOut { async processImage(imageBuffer) { // Return minimal data without OCR processing return { text: '' }; } } const converter = new FastConverter(pptxBuffer); const html = await converter.toHTML(); // Much faster, but no OCR text ``` -------------------------------- ### Enable Debug Logging for Missing Images Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/quick-reference.md If images are missing in the output, enable debug logging to diagnose extraction or OCR issues. ```javascript converter.setDebug(true); ``` -------------------------------- ### Generate Custom Single-Page HTML Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/advanced-usage.md Parse a PPTX and generate a custom HTML structure, embedding the raw XML content of each slide. Requires manual initialization and parsing steps. ```javascript import { PPTXInHTMLOut } from 'pptx-in-html-out'; const converter = new PPTXInHTMLOut(pptxBuffer); converter.setDebug(true); // Initialize and parse (internal methods) await converter.initialize(); await converter.validatePPTX(); await converter.parse(); // Access slides and generate custom HTML const customHTML = ` Custom Presentation

Extracted Presentation Content

${converter.slides.map((slide, index) => `

Slide ${index + 1}

${JSON.stringify(slide.content, null, 2)}
`).join(' ')} `; ``` -------------------------------- ### Error Recovery with Partial Output Source: https://github.com/jparkerweb/pptx-in-html-out/blob/main/_autodocs/advanced-usage.md Implement a fallback mechanism to attempt generating partial HTML output when the primary conversion to HTML fails. Handles individual slide rendering errors during recovery. ```javascript import { PPTXInHTMLOut } from 'pptx-in-html-out'; async function convertWithFallback(pptxBuffer) { const converter = new PPTXInHTMLOut(pptxBuffer); try { return await converter.toHTML(); } catch (error) { console.error('Conversion error:', error.message); // Attempt to get partial output by using internal methods try { await converter.initialize(); await converter.validatePPTX(); const slides = await converter.parseSlides(); if (slides.length > 0) { console.log(`Parsed ${slides.length} slides before error`); // Generate partial HTML let html = ''; for (let i = 0; i < Math.min(slides.length, 5); i++) { try { const slideHtml = await converter.convertSlideToHTML(slides[i]); html += slideHtml; } catch (slideError) { console.log(`Slide ${i + 1} failed, continuing...`); html += `

Failed to render slide ${i + 1}

`; } } html += ''; return html; } } catch (internalError) { console.error('Could not recover partial output:', internalError); } throw error; // Re-throw if no recovery possible } } const html = await convertWithFallback(pptxBuffer); ```