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.
@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: