Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Apr 07, 2022 12:52 pm

Hi

I am trying make a table with som space to the edge of the paper both left and right, but I can't see that I can set the table width only the cell width. But even if I set the column widt very low, the table still fills the page width.

How do I limit the width of the table??

Regards Steen

steenmaigaardDTU
 
Posts: 7
Joined: Fri Oct 08, 2021 7:59 am

Fri Apr 08, 2022 5:42 am

Hello,

Thank you for your inquiry.
According to your description, I did a preliminary test and reproduced the issue you mentioned. I have logged the issue into our bug tracking system with the ticket number SPIREPDF-5069. Our development team will investigate and fix it. Once it is resolved, I will inform you in time. Sorry for the inconvenience caused.
In addition, our Spire.PDF supports limiting the width of the Grid, which is more comprehensive and efficient than the table. Please refer to the code below.
Code: Select all
PdfDocument document = new PdfDocument();
PdfPageBase page = document.Pages.Add();
String[] data = {
        "Vendor\r\nName;Address;City",
        "Cacor Corporation;161 Southfield Rd;Southfield",
        "Underwater;50 N 3rd Street;Indianapolis",
        "J.W. Luscher Mfg.;65 Addams Street;Berkely" ,
        "E-iceblue; ; "};
//create a grid
PdfGrid grid = new PdfGrid();

//add rows
for (int r = 0; r < data.Length; r++)

{ PdfGridRow row = grid.Rows.Add(); }
//add columns
grid.Columns.Add(3);

//set the width of columns
float width = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1);
grid.Columns[0].Width = 80;
grid.Columns[1].Width = 80;
grid.Columns[2].Width = 80;

//set the height of rows
float height = page.Canvas.ClientSize.Height - (grid.Rows.Count + 1);
grid.Rows[0].Height = 25f;
grid.Rows[1].Height = 12.5f;
grid.Rows[2].Height = 12.5f;
grid.Rows[3].Height = 12.5f;
grid.Rows[4].Height = 12.5f;

//insert data to grid
for (int r = 0; r < data.Length; r++)
{
    String[] rowData = data[r].Split(';');
    for (int c = 0; c < rowData.Length; c++)

    { grid.Rows[r].Cells[c].Value = rowData[c]; }
}
grid.Rows[0].Style.Font = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Bold), true);
grid.Draw(page, new PointF(10, 30));
document.SaveToFile("result.pdf", FileFormat.PDF);

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Fri Apr 08, 2022 7:46 am

Hello,

Thank you for your patience.
For the issue SPIREPDF-5069, after investigation, we found that if you want to specify the width of the table, you need to add the code "table.Style.IsFixWidth = true" to make the column width value take effect. Please refer to the code below:
Code: Select all
...
PdfTable table = new PdfTable();
//Add code
table.Style.IsFixWidth = true;
table.Columns[0].Width = 60f;
...

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Mon Apr 18, 2022 8:35 am

Hello,

Hope you are doing well!
How is your issue going? Did the code we provided work for you? Any feedback will be greatly appreciated.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Wed Apr 20, 2022 6:12 am

Hello. Thanks for the uppdate everything now works fine.

Regards Steen

steenmaigaardDTU
 
Posts: 7
Joined: Fri Oct 08, 2021 7:59 am

Wed Apr 20, 2022 6:34 am

Hello,

You are welcome.

If you encounter other issues related to our products in the future, please feel free to contact us.

Have a nice day!

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.PDF

cron