PPTX to HTML with PHP

PPTX to HTML

Introduction

phppptx Advanced and Premium licenses include the functionality of transforming PPTX presentation to HTML with native PHP classes.

The main features of this functionality are the following:

  • Conversion of contents, styles and properties
  • Native PHP classes
  • Easily customizable
  • Transform PPTX created from scratch and templates
How to use it

The transformation can be done using just three lines of code:

where presentation.pptx can be a PPTX created with phppptx or from other source (MS PowerPoint, LibreOffice, etc). Premium licenses can also transform in-memory documents.

Supported OOXML tags and attributes

phppptx parses contents, styles, properties and other XML contents.

The list of currently parsed contents and styles include (OOXML content/style and HTML/CSS transformation):

  • presentation : <div class="presentation">

    • height (p:sldSz) => cy (height)
    • width (p:sldSz) => cx (width)
    • theme => color, font (major, minor)
  • slides : <div>

    • background color (a:solidFill) => w:color (background-color)
    • background image (a:blipFill) => id (background-image)
  • title and metas (cp:coreProperties) : <title>, <meta>

    • title (dc:title) => <title>
    • author (dc:creator) => <meta> (author)
    • description (dc:description) => <meta> (description)
    • keywords (cp:keywords) => <meta> (keywords)
  • text strings (a:t) and text styles (a:rPr) : <span>

    • text (a:t) => <span>
    • background color (a:highlight) => val (background-color: #HEX)
    • bold => b (font-weight: bold)
    • color (a:solidFill) => a:schemeClr (color), a:srgbClr (color)
    • font family => typeface (font-family)
    • font size => sz (font-size)
    • italic => i (font-style: italic)
    • strikethrough => strike (sngStrike) (text-decoration: line-through)
    • underline => u (text-decoration: underline)
  • paragraphs (a:p) : <p>

    • slide master styles, slide layout styles, shape styles
    • align (algn) => ctr (align-self: center;text-align: center;), l (align-self: start;text-align: left;), r (align-self: end;text-align: right;)
    • margin left (marL) => margin-left
    • font size (a:defRPr) => font-size
    • margin top (a:spcBef) => margin-top
    • margin bottom (a:spcAft) => margin-bottom
  • shapes (text boxes)

    • background color (a:solidFill) => a:schemeClr (background-color), a:srgbClr (background-color)
    • border (a:ln) => w (width), a:schemeClr (color), a:srgbClr (color)
    • position (a:off) => x (left), y (top)
    • rotation => rot (rotate)
    • size (a:ext) => cx (width), cy (height)
  • tables (w:tbl) : <table>

    • shape styles
    • row height (a:tr) => h (height)
    • cell background color (a:tcStyle) => w:solidFill (background-color)
    • cell width (a:gridCol) => w (width)
    • wholeTbl (a:tblStyle)
    • band1H (a:tblStyle)
    • band2H (a:tblStyle)
    • band1V (a:tblStyle)
    • band2V (a:tblStyle)
    • lastCol (a:tblStyle)
    • firstCol (a:tblStyle)
    • lastRow (a:tblStyle)
    • firstRow (a:tblStyle)
  • other elements

    • audio (a:audioFile) => r:link (<audio>)
    • break (a:br) => (<br>)
    • image (a:blip) => r:embed (<img>). Supported image formats: png, jpg and other formats supported by web browsers.
    • link (a:hlinkClick) => HYPERLINK (<a>) image and text
    • video (a:videoFile) => r:link (<video>)

    WARNING:

  • The fact that a tag is not parsed does not mean its content disappears from the HTML output. It only implies that their associated OOXML properties are not taken directly into account. Their children and text content will be parsed and rendered with their corresponding styles into the HTML output.
How to customize transformations

Nearly all the functionalities available for performing PPTX to HTML transformations can be customized.

The two main classes for transformations are: TransformNativeHtml and TransformNativeHtmlPlugin.

TransformNativeHtml is the class for parsing PPTX structures and performs the transformation to HTML. Its constructor receives an object of the TransformNativeHtmlPlugin type that sets the export options. This class can be extended to customize the transformation of each element.

TransformNativeHtmlPlugin allows to generate transformation plugins according to the project requirements. E.g.: inserting files as base64, customizing conversion factors, setting the method to set export sizes and set CSS, JavaScript and custom HTML. phppptx includes the TransformNativeHtmlDefaultPlugin, the default plugin to perform transformations.

All the available options are thoroughly explained in the API documentation page of the transformNativeHtml method.