Render multiple images in a row

Hello,

I have a array of images. I want to render the all images in array two images in a row. I have attached my syntax. It throws an error.

It works when trying to render 1 image per row. Also, is there any way to fill (stretch) the last row if only one image in the last row

Regards,

@NaraSg

To render multiple images in a row using Aspose.Words, you can utilize a table to arrange the images effectively. Below is a C# example demonstrating how to achieve this:

using Aspose.Words;
using Aspose.Words.Drawing;

// Load your document
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Create a table with two columns
Table table = builder.StartTable();

// Assuming you have an array of image paths
string[] imagePaths = { "image1.png", "image2.png", "image3.png", "image4.png" };

for (int i = 0; i < imagePaths.Length; i++)
{
    // Insert the image
    builder.InsertImage(imagePaths[i]);

    // End the cell
    builder.EndRow();

    // Check if we need to start a new row
    if ((i + 1) % 2 == 0 && i + 1 < imagePaths.Length)
    {
        builder.InsertCell(); // Start a new cell for the next row
    }
}

// End the table
builder.EndTable();

// Save the document
doc.Save("output.docx");

In this example, images are inserted into a table with two columns. If there is an odd number of images, the last row will contain a single image, which may not stretch to fill the space. To ensure the last image fills the remaining space, you can adjust the width of the last cell accordingly.

If you encounter any errors, please provide the specific error message for further assistance.

Hello,

I am interested in achieving the above result using LINQ reporting syntax in template. Not from code-behind.

Regards,
Narayanan

@NaraSg Could you please attach your template document here for our reference? We will check the issue and provide you more information.

Hello,
Attached the template.
Sample.docx (53.6 KB)

Images(json datasource) is an array of object containing two properties

  1. , a string for filename
  2. byte array to hold the data (say png images)).

Thank you

Regards,
Narayanan

@NaraSg The problem occurs because floating shapes are used in your template. Two of shapes are visually inside foreach, but actually are placed outside foreach:

Please try sing the following modified template: modified.docx (53.1 KB)