Configuration options for patching
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: ">>" },
});
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.