docx
    Preparing search index...

    Function patchDocument

    • Patches an existing .docx document by replacing placeholders with new content.

      This function opens an existing Word document, searches for placeholder text (e.g., {{name}}), and replaces it with the provided content while preserving the original document structure and optionally the original formatting.

      Type Parameters

      Parameters

      Returns Promise<OutputByType[T]>

      A promise resolving to the patched document in the specified output format

      // Patch with paragraph content
      const buffer = await patchDocument({
      outputType: "nodebuffer",
      data: templateBuffer,
      patches: {
      name: {
      type: PatchType.PARAGRAPH,
      children: [new TextRun({ text: "John Doe", bold: true })],
      },
      },
      });

      // Patch with custom delimiters
      const buffer = await patchDocument({
      outputType: "nodebuffer",
      data: templateBuffer,
      patches: { ... },
      placeholderDelimiters: { start: "<<", end: ">>" },
      });