docx
    Preparing search index...

    Class Packer

    Exports documents to various output formats.

    The Packer class provides static methods to convert a File object into different output formats such as Buffer, Blob, string, or stream. It handles the compilation of the document structure into OOXML format and compression into a .docx ZIP archive.

    // Export to buffer (Node.js)
    const buffer = await Packer.toBuffer(doc);

    // Export to blob (browser)
    const blob = await Packer.toBlob(doc);

    // Export with prettified XML
    const buffer = await Packer.toBuffer(doc, PrettifyType.WITH_2_BLANKS);
    Index

    Constructors

    Methods

    • Exports a document to the specified output format.

      Type Parameters

      Parameters

      • file: File

        The document to export

      • type: T

        The output format type (e.g., "nodebuffer", "blob", "string")

      • Optionalprettify: boolean | "" | " " | " " | "\t"

        Whether to prettify the XML output (boolean or PrettifyType)

      • overrides: readonly IXmlifyedFile[] = []

        Optional array of file overrides for custom XML content

      Returns Promise<OutputByType[T]>

      A promise resolving to the exported document in the specified format

    • Exports a document to an ArrayBuffer.

      Parameters

      • file: File

        The document to export

      • Optionalprettify: boolean | "" | " " | " " | "\t"

        Whether to prettify the XML output

      • overrides: readonly IXmlifyedFile[] = []

        Optional array of file overrides

      Returns Promise<ArrayBuffer>

      A promise resolving to the document as an ArrayBuffer

    • Exports a document to a base64-encoded string.

      Parameters

      • file: File

        The document to export

      • Optionalprettify: boolean | "" | " " | " " | "\t"

        Whether to prettify the XML output

      • overrides: readonly IXmlifyedFile[] = []

        Optional array of file overrides

      Returns Promise<string>

      A promise resolving to the document as a base64 string

    • Exports a document to a Blob (for browser environments).

      Parameters

      • file: File

        The document to export

      • Optionalprettify: boolean | "" | " " | " " | "\t"

        Whether to prettify the XML output

      • overrides: readonly IXmlifyedFile[] = []

        Optional array of file overrides

      Returns Promise<Blob>

      A promise resolving to the document as a Blob

    • Exports a document to a Node.js Buffer.

      Parameters

      • file: File

        The document to export

      • Optionalprettify: boolean | "" | " " | " " | "\t"

        Whether to prettify the XML output

      • overrides: readonly IXmlifyedFile[] = []

        Optional array of file overrides

      Returns Promise<Buffer<ArrayBufferLike>>

      A promise resolving to the document as a Buffer

    • Exports a document to a Node.js Stream.

      Parameters

      • file: File

        The document to export

      • Optionalprettify: boolean | "" | " " | " " | "\t"

        Whether to prettify the XML output

      • overrides: readonly IXmlifyedFile[] = []

        Optional array of file overrides

      Returns Stream

      A readable stream containing the document data

    • Exports a document to a string representation.

      Parameters

      • file: File

        The document to export

      • Optionalprettify: boolean | "" | " " | " " | "\t"

        Whether to prettify the XML output

      • overrides: readonly IXmlifyedFile[] = []

        Optional array of file overrides

      Returns Promise<string>

      A promise resolving to the document as a string