Corrupted document when using async await for image load
Kohys58 opened this issue · comments
Hello,
Sorry to bother, I can't figure out why my attempt to generate content using async loop isn't working.
I'm on react-native v0.72.6, docx v8.4.0.
I'm trying to generate an array of Pararaph through mapping my element in an asynchronous way, required by the loading image functionnality of the package I use to load my image, it works well when I do it directly in the new Document constructor, but when I try with this function :
const createPlansVertexDoc = async (pvs: IPlanVertexRapport[]): Promise<Paragraph[]> =>
await Promise.all(pvs.map(
async (item, index) =>
new Paragraph({
alignment: AlignmentType.CENTER,
children: [
new ImageRun({
data: await ReactNativeBlobUtil.fs.readFile(item.local_image_generateur_plan_vertex, "base64"),
transformation: {
width: 600,
height: 300,
}
}),
]
}),
));
Then on the section part I call it this way :
...await createPlansVertexDoc(plansRapport),
I don't get what i'm doing the wrong, my data is well structured, I verified, the image path exists and the image is here, (verified also by calling it directly as mentionned).
But when I try to do it that way it doesn't work, have no idea why, tried everything I could think of.
I apologize for my English, this is not my native language.
Had nothing to do with my way of writing the function, i was just using new PageBreak() directly in the children array of the sections not inside a Paragraph...
Also had a wrongly typed function call before, when I removed it, my code Editor raised the issue that lead me to figuring it out, otherwise, error wasn't triggering