OpenXmlSdkTs - v1.0.7
    Preparing search index...

    Class PmlPackage

    PowerPoint presentation package — opens, navigates, and saves .pptx files.

    Extends OpenXmlPackage with PowerPoint-specific convenience methods. All parts returned by this class are typed as PmlPart.

    import { PmlPackage, P } from "openxmlsdkts";
    import fs from "fs";

    const buffer = fs.readFileSync("deck.pptx");
    const doc = await PmlPackage.open(new Blob([buffer]));
    const presentation = await doc.presentationPart();
    const slides = await presentation!.slideParts();
    console.log(`${slides.length} slides`);

    Hierarchy (View Summary)

    Index

    Constructors

    Methods

    • Adds a new part to the package.

      Parameters

      • uri: string

        The part URI (e.g., "/word/comments.xml").

      • contentType: string

        The MIME content type. Use ContentType constants.

      • partType: PartType

        The part data type: "xml", "binary", or "base64".

      • data: unknown

        The part content (an XDocument for XML parts, or a string/Blob for binary).

      Returns OpenXmlPart

      The newly created OpenXmlPart.

      Error if a part with the given URI already exists.

      import { ContentType, XDocument, XElement, W } from "openxmlsdkts";

      const xDoc = new XDocument(new XElement(W.comments));
      pkg.addPart("/word/comments.xml", ContentType.wordprocessingComments, "xml", xDoc);
    • Returns the content type for a part identified by its URI.

      Parameters

      • uri: string

        The full part URI.

      Returns string

      The MIME content type string.

      Error if the content type cannot be determined.

    • Deletes a package-level relationship by ID.

      Parameters

      • id: string

        The relationship ID to delete.

      Returns Promise<boolean>

      true if the relationship was deleted.

      Error if the relationship is not found.

    • Saves the package as a Flat OPC XML string.

      Returns Promise<string>

      A promise resolving to the Flat OPC XML string.

      Flat OPC XML is the required format when working with Office JavaScript/TypeScript Add-ins. It is also useful for storing documents in XML databases, applying XSLT transformations, and debugging document structure.

      const flatOpc = await pkg.saveToFlatOpcAsync();
      fs.writeFileSync("document.xml", flatOpc);
    • Saves the package as a Base64-encoded string.

      Returns Promise<string>

      A promise resolving to the Base64 string.

      Useful for embedding documents in JSON payloads, data URIs, or text-based storage.

      const base64 = await pkg.saveToBase64Async();
      
    • Saves the package as a binary Blob (ZIP).

      Returns Promise<Blob>

      A promise resolving to a Blob containing the document bytes.

      const blob = await pkg.saveToBlobAsync();
      // In Node.js, convert to Buffer for file I/O:
      const buffer = Buffer.from(await blob.arrayBuffer());
      fs.writeFileSync("output.docx", buffer);