How to Insert Image Dynamically using .NET | LINQ Reporting Engine

https://forum.aspose.com/t/how-to-insert-image-dynamically-using-net-linq-reporting/228073/4

Hello Tahir,
can you send me these templates( image linq.zip)
have a nice day

1 Like

@Sami69 Here is the template: image linq.docx (13.9 KB)

Please note, only topic starter and Aspose staff can access the attachments. So i moved your question into a separate topic.

Also, please see our documentation for more information about inverting images using LINQ Reporting Engine:
https://docs.aspose.com/words/net/inserting-images-dynamically/

Hello Alex,

how can i use base64 image inside word file
can you give me a code sample?

Thanks

@Sami69 Just use base64 string as data for your expression in <<image [image_expression]>>. For example see the following template and code:

string base64ImageData = @"iVBORw0KGgoAAAANSUhEUgAAAI4AAABTCAIAAADGP6iuAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAAYtSURBVHhe7dFhbuM4EITRuf8x9nT7ey4wq6CASuUjRbdExqMNCDwYbLK624l//fm9/T+w3h6L9fZYrCf9+udf3GyrsL7t+JESXrd5rO/Rb5M/lW62hVjfgx9JkNkmsb4HP5Ihts1gfRV+m4TkNon1Vfh5EpLbJNY34BcSZN5AS//K6vdgfYl/mBaSy3lFLpV8/UlY1+V/B5BcC7vG0PsQ974Y67r8j5juM7ZKbrkEc4rU6M+ZUSlHXR3IusgrzZcZW8VbbsCoIjXmHMvYVRh1QGCAdQWWAcLzNDNXnBnEPG2s7cLNIfOXYM4BgTHWFdiXkFwCK+7BzC60DKCxAhMMsQHWRdh30GVmJuXwlyr5HN6VSZ/PZGMF2hOSZ1gXYZkgMwOTK1525fwWwmPorcAEQ2yAtXkKxnlHBnxexSs8HDeSLQkxQSbpNcMDzl+Cdp/rWIsnuvTNGSWXwOQutCQkDbGE5EtofykbfVZZx/rgifoscq/Pt3lmF8JdaDHEBJl09prtRZggyIyxPmDcoXsJ7nVYNzeovYXYABoTkgcEbPx0SdvuQx3rQ07MckCxs7DmVKAREB5D7wEBQ8zOAr6vw4QDAhVN3QwtGvfmijNoAYTH0C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wQWIJ10sr8BmvlolU8M3UzuJSzluRMQuaAwDzWCbvhZWAgt9yY023JgYbMPMwXPznmm4VYJy3L3a02pl7f55M5k5Dpylj2djm5EFaI7jOmm6vUdTbhS9HVbavoLHs1R7vGFPPnmLtWwXxBRvzkz4SADkmXifVf5y/qr6sbX/r8ksPzNC2Hp0za2b2MX80rPvJZPE3n657/v7o0YZ5G5eSUyVU09suWLH4Y/8G3ZbvHtpxZS5M/t/j0I+Vf3ioGPO2MkxX15MErPrqy+MHwZwP+O+NwK9uLul156eHGersH/+hJOdlYbzPwH28pk0mf/XSG9Tav/Q3yKUvftPct1ttjsd4ei/X2WKy3x2K9PRbr7bFYb4/Fenss1ttjsd4ei/X2WKy3x2K9PRbr7bFYbw/1+9d/c2zOSqmedYwAAAAASUVORK5CYII=";

Document doc = new Document(@"C:\Temp\in.docx");
ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, base64ImageData, "myimg");
doc.Save(@"C:\Temp\out.docx");

in.docx (15.4 KB)
out.docx (12.7 KB)

Hello Alexey,

thanks for your answer.
I wrote such a code but it didn’t work. I don’t understand where I did wrong.
can you help me?

Thanks

public async Task<byte[]> CRCreateReportDocument(byte[] template,)
{
    var doc = new Document(new MemoryStream(template));
    var keys = new List<string>();
    var values = new List<object>();


    string base64ImageData = @"iVBORw0KGgoAAAANSUhEUgAAAI4AAABTCAIAAADGP6iuAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAAYtSURBVHhe7dFhbuM4EITRuf8x9nT7ey4wq6CASuUjRbdExqMNCDwYbLK624l//fm9/T+w3h6L9fZYrCf9+udf3GyrsL7t+JESXrd5rO/Rb5M/lW62hVjfgx9JkNkmsb4HP5Ihts1gfRV+m4TkNon1Vfh5EpLbJNY34BcSZN5AS//K6vdgfYl/mBaSy3lFLpV8/UlY1+V/B5BcC7vG0PsQ974Y67r8j5juM7ZKbrkEc4rU6M+ZUSlHXR3IusgrzZc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wtl6XMLIH5htgb5GqfVRZlV0LsHtYJ+wSZSRiekHwP7c2vYRk7gxZD7B7WpgW5TzKzBOYbYu+B7yC6z1hXtiTEbmNt2pErJTNLYP4BgXfK75BfxocxtQAyt7EWLEtILpHDv29Lkb8MIAYIG2IzWBtWCjJLYIUg8074JglJQPiAwCTWgpXSzeCQrz6n9l7tgMwZhy91VWhgC7GEpCAzg7VgX6uSkbOBuj+b49cBtBwQmIHJhlhCUpCZwdqw8obxkFzUJv0KiLWQn4HJgoz51UnfrMJasO+bjHfpSRnHBnlxfh4mCzIJsXH4BtaSW7/Vd+zKP2QGxh4QSEgaYjNYC/YNXAonNbp9PKe+5UjWjVs8MyEjyBwQWIJ10sr8BmvlolU8M3UzuJSzluRMQuaAwDzWCbvhZWAgt9yY023JgYbMPMwXPznmm4VYJy3L3a02pl7f55M5k5Dpylj2djm5EFaI7jOmm6vUdTbhS9HVbavoLHs1R7vGFPPnmLtWwXxBRvzkz4SADkmXifVf5y/qr6sbX/r8ksPzNC2Hp0za2b2MX80rPvJZPE3n657/v7o0YZ5G5eSUyVU09suWLH4Y/8G3ZbvHtpxZS5M/t/j0I+Vf3ioGPO2MkxX15MErPrqy+MHwZwP+O+NwK9uLul156eHGersH/+hJOdlYbzPwH28pk0mf/XSG9Tav/Q3yKUvftPct1ttjsd4ei/X2WKy3x2K9PRbr7bFYb4/Fenss1ttjsd4ei/X2WKy3x2K9PRbr7bFYbw/1+9d/c2zOSqmedYwAAAAASUVORK5CYII=";

    ReportingEngine engine = new ReportingEngine();

    //..........
    engine.BuildReport(doc, base64ImageData, "myimg");



    doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedFields;
    doc.MailMerge.Execute(keys.ToArray(), values.ToArray());

    using (var ms = new MemoryStream())
    {
        doc.Save(ms, Aspose.Words.SaveFormat.Pdf);
        return ms.ToArray();
    }
}

@Sami69 Could you please attach your template. According to your code you are using both LINQ Reporting and classic Mail Merge. It is not quite clear what is the purpose of using both approaches.

A post was split to a new topic: Insert Image Dynamically using .NET | LINQ Reporting Engine