We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Place components like Table,Image in Aspose PDF Page Java

Hi All,

Is it possible to place the components like Table/Image in a PDF page by providing some co-ordinates (X.Y) values?

If so, please let me know how to go about it?


You can insert an image or table object in the floating box, and then set the width, height and position the floating box with respect to the page. FloatingBox accepts absolute positioning rather than flow layout, so you get the power to specify the position instead of letting the page rendering engine to place it. You can use Top, Left, Bottom and Right properties to adjust the position of a floating box. Please try the following code example:


// The path to the documents directory.
string dataDir = @"C:\Pdf\test285\";

// Load source PDF document
Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
Aspose.Pdf.Page page = doc.Pages.Add();

// Initializes a new instance of the Table
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
// Set the table border color as LightGray
table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
// Set the border for table cells
table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
// Create a loop to add 10 rows
for (int row_count = 1; row_count < 10; row_count++)
    // Add row to table
    Aspose.Pdf.Row row = table.Rows.Add();
    // Add table cells
    row.Cells.Add("Column (" + row_count + ", 1)");
    row.Cells.Add("Column (" + row_count + ", 2)");
    row.Cells.Add("Column (" + row_count + ", 3)");
FloatingBox box = new FloatingBox((float)table.GetWidth(), (float)table.GetHeight());
box.Top = 500;
box.BackgroundColor = Aspose.Pdf.Color.Blue;
// Save updated document containing table object
doc.Save(dataDir + "document_with_table_out.pdf");

This is the output PDF: document_with_table_out.pdf (2.3 KB). Please also refer to these help topics: Add table to a PDF page and Add Image to Existing PDF File