diff --git a/src/patcher/from-docx.ts b/src/patcher/from-docx.ts index 675f72c5a5..8ff48446d8 100644 --- a/src/patcher/from-docx.ts +++ b/src/patcher/from-docx.ts @@ -68,7 +68,14 @@ export const patchDocument = async (data: InputDataType, options: PatchDocumentO const hyperlinkRelationshipAdditions: IHyperlinkRelationshipAddition[] = []; let hasMedia = false; + const binaryContentMap = new Map(); + for (const [key, value] of Object.entries(zipContent.files)) { + if (!key.endsWith('.xml') && !key.endsWith('.rels')) { + binaryContentMap.set(key, await value.async("nodebuffer")) + continue; + } + const json = toJson(await value.async("text")); if (key.startsWith("word/") && !key.endsWith(".xml.rels")) { const context: IContext = { @@ -196,6 +203,10 @@ export const patchDocument = async (data: InputDataType, options: PatchDocumentO zip.file(key, output); } + for (const [key, value] of binaryContentMap) { + zip.file(key, value); + } + for (const { stream, fileName } of file.Media.Array) { zip.file(`word/media/${fileName}`, stream); }