Issue
I am in process of making a Flutter App where we can select pictures and then generate a MS word file with selected images inserted in Table. Initially I though I will generate a pdf with table and convert to word and made progress on that. I generated pdf but when I convert to word I see its getting converted as one big image and not as Table with images as I need to alter images sometimes in word. Now I am struck can anyone help with some way forward.
Solution
Try using this package docx_template
final f = File("template.docx");
final docx = await DocxTemplate.fromBytes(await f.readAsBytes());
// Load test image for inserting in docx
final testFileContent = await File('test.jpg').readAsBytes();
Content c = Content();
c
..add(TextContent("docname", "Simple docname"))
..add(TableContent("table", [
RowContent()
..add(TextContent("key1", "Paul"))
..add(ImageContent('img', testFileContent)),
]))
final d = await docx.generate(c);
final of = File('generated.docx');
if (d != null) await of.writeAsBytes(d);
Answered By – Kaushik Chandru
Answer Checked By – Katrina (FlutterFixes Volunteer)