PavelS0 / docx_template_dart

A Docx template engine
Apache License 2.0
40 stars 20 forks source link

How to add ImageContent dynamically #16

Closed Doppelklick closed 1 year ago

Doppelklick commented 3 years ago

Hi,

I'm trying to add images dynamically into a list.

  final listImages = <Content>[];
  for (var i = 0; i < 10; i++)
    listImages.add(ImageContent("img", testFileContent));

  Content c = Content();

  c..add(TextContent("docname", "Simple test"))
   ..add(ListContent("list", listImages));

But it doesn't work :/

Doppelklick commented 2 years ago

Hi, I've tried it again and tried to modify the example. But meanwhile I think that my use case doesn't work.

    Content c = Content();     
      c
        ..add(TextContent("docname", "Simple docname"))  
    ..add(TextContent("passport", "Passport NE0323 4456673"))  
    ..add(TableContent("table", [  
      RowContent()
        ..add(TextContent("key1", "Alex")). 
        ..add(TextContent("key2", "Houser"))
        ..add(TextContent("key3", "CEO & Founder"))
        ..add(ListContent("tablelist", [
          TextContent("value", "Mercedes-Benz C-Class S205"),
          TextContent("value", "Lexus LX 570")
        ]))
        ..add(ImageContent('img', testFileContent))
    ]))
    ..add(ListContent("multilineList", [
      PlainContent("multilinePlain")
        ..add(TextContent('multilineText', 'line 1')),
      PlainContent("multilinePlain")
        ..add(TextContent('multilineText', 'line 2')),

// **** THIS DOESN'T WORK *** 
      PlainContent("multilinePlain")..add(ImageContent('img', testFileContent)),

      PlainContent("multilinePlain")
        ..add(TextContent('multilineText', 'line 3')),
    ]));

Can confirm, that this does not work?

Best, Dominik

PavelS0 commented 2 years ago

Hello.

I added the following line to the standard example PlainContent("multilinePlain")..add(ImageContent('img', testFileContent)),

Then, I added a stub image to the template, applied the 'img' tag with 'img' name and everything works.

example.zip

Doppelklick commented 2 years ago

Thank you for your reply. Now it is possible to add the image.

But if I don't add an image to the line - the placeholder is shown :-(

I need to build a docx with a list of text blocks and sometimes there is a optional image.

PavelS0 commented 2 years ago

aaahh. I can try add option or new tag or change current logic and delete image from template if ImageContent not passed. maybe I'll make an update later today

Doppelklick commented 2 years ago

Hi, did you find a solution?

ideva-SAS commented 2 years ago

Hi would you have a solution to not display the image location so empty? may be the possibility to change the size of the location? Best regards

PavelS0 commented 1 year ago

Option to delete image added