PPTX2HTML Documentation

repository·master·Indexed 20 days ago

https://github.com/g21589/pptx2html

A pure JavaScript library for converting Microsoft PowerPoint (.pptx) files into HTML. It supports the conversion of text, pictures (jpg, png, gif), graphs, tables, text blocks, drawings (SVG), and themes/layouts. The library is compatible with Chrome, Firefox, Edge, and Internet Explorer 10 or higher.

Tokens
1.9K
Snippets
8
Records
11
Agent score
71%

What's inside PPTX2HTML

  1. Overview of PPTX2HTML

    master
    PPTX2HTML is a pure JavaScript library designed to convert Microsoft PowerPoint (.pptx) files into HTML. It is compatible with modern web browsers including Chrome, Firefox, Edge, and Internet Explorer 10 or higher.
  2. Structure a custom theme SCSS file

    master

    A theme file must include components in this exact order to function correctly:

    1. Include mixins.scss: Import /css/theme/template/mixins.scss to access shared utility functions.
    2. Include settings.scss: Import /css/theme/template/settings.scss. This declares the custom variables required by the template. You should perform your variable overrides immediately after this step.
    3. Override: Specify your custom variables or add custom selectors and styles to override the default theme behavior.
    4. Include theme.scss: Finally, import /css/theme/template/theme.scss. This template file uses the variables defined in the previous steps to generate the final CSS output.
    // 1. Shared utilities
    @import "../template/mixins.scss";
    
    // 2. Variable declarations
    @import "../template/settings.scss";
    
    // 3. Overrides
    $theme-primary-color: #ff0000;
    .custom-selector {
      color: blue;
    }
    
    // 4. Final template generation
    @import "../template/theme.scss";
  3. Supported PPTX objects in PPTX2HTML

    master

    PPTX2HTML supports the conversion of various PowerPoint elements into web-compatible formats. The following object types are supported:

    • Text: Includes font size, font family, styles (bold, italic, underline), color, location, and hyperlinks.
    • Pictures: Supports jpg/jpeg, png, and gif formats with location preservation.
    • Graphs: Converts Bar charts, Line charts, Pie charts, and Scatter charts.
    • Tables: Preserves location and size.
    • Text Blocks: Converted to <div> elements, supporting horizontal/vertical alignment and single-color background colors, as well as borders (color, width, type, and strokeDasharray).
    • Drawings: Converted to SVG, including simple blocks like rect, ellipse, and roundRect. Supports alignment, background color, and border properties.
    • Groups/Multi-level Groups: Supports grouping with z-index (level) preservation.
    • Theme/Layout: Supports PowerPoint themes and layouts.
  4. Create a custom reveal.js theme

    master
    To create a new theme, duplicate an existing .scss file from /css/theme/source. The theme must follow a specific four-step structure to ensure variables and mixins are correctly applied. Once created, you can compile the Sass to CSS by running the Grunt command grunt css-themes.
    grunt css-themes
  5. How the Multiplex plugin handles state synchronization

    master

    The Multiplex plugin enables synchronized presentation states across multiple clients using Socket.io. It uses a secure handshake mechanism to prevent unauthorized state changes.

    1. Token Acquisition: A client requests a token from the /token endpoint. The server returns a secret and a socketId (which is a Blowfish hash of the secret).
    2. State Change: When a client wants to broadcast a state change (e.g., moving to a new slide), it emits a multiplex-statechanged event via Socket.io.
    3. Security Validation: The payload must include the secret. The server re-hashes the provided secret and compares it to the socketId. If they match, the server broadcasts the data to all other connected sockets using the socketId as the target event name.

    This ensures that only the client holding the valid secret for a specific session can trigger state updates for that session.

    // Conceptual flow of state synchronization
    
    // 1. Get token from server
    // GET /token -> { "secret": "...", "socketId": "..." }
    
    // 2. Emit state change with secret
    // socket.emit('multiplex-statechanged', { 
    //   secret: '...', 
    //   slideNumber: 5, 
    //   ... 
    // });
  6. Run the Reveal.js Speaker Notes server

    master

    The notes-server plugin provides a local HTTP and Socket.io server that allows a speaker to view notes on a separate device or window. When the server is running, it serves static assets (css, js, images, plugin, lib) and a specialized notes page.

    To use it:

    1. Start the server (it defaults to port 1947).
    2. Open the slides at http://localhost:1947.
    3. Access the notes page via the link provided in the browser's JavaScript console.
    4. As you advance through slides, the notes will update automatically via Socket.io events.
    # The server runs on port 1947 by default
    # Access slides at http://localhost:1947
  7. Notes-server configuration options

    master

    The server behavior is controlled by an opts object. While the current implementation uses hardcoded defaults, these are the keys used for configuration:

    • port: The port number the HTTP server listens on (default: 1947).
    • baseDir: The root directory from which static assets and templates are served.
    var opts = {
    	port :      1947,
    	baseDir :   __dirname + '/../../'
    };
  8. Notes-server Socket.io event API

    master

    The notes-server uses Socket.io to synchronize state between the slide presentation and the speaker notes view. The following events are broadcast to all connected clients:

    • new-subscriber: Emitted when a new client subscribes to the notes stream.
    • statechanged: Emitted when the presentation state (e.g., current slide) changes.
    • statechanged-speaker: Emitted when state changes specifically triggered by speaker actions.
    // Socket.io events handled by the server:
    // - 'new-subscriber'
    // - 'statechanged'
    // - 'statechanged-speaker'
  9. Use the Multiplex server endpoints

    master

    The Multiplex plugin runs an Express/Socket.io server that provides the following endpoints for client-side synchronization:

    • GET /: Serves the main index.html file.
    • GET /token: Returns a JSON object containing a secret and a socketId. The socketId is a Blowfish hash of the secret. This is used to authenticate state changes.
    • GET /css/*, GET /js/*, GET /plugin/*, GET /lib/*: Serves static assets from the plugin's directory structure.

    Configuration is handled via environment variables:

    • PORT: The port the server listens on (defaults to 1948).
    // Response from GET /token
    {
      "secret": "1672531200000123456",
      "socketId": "a1b2c3d4e5f6..."
    }