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.
Fri Jan 08, 2021 2:48 pm
I have a PDF table - I set the column widths to match the size of the data but when it displays the table expands to the width of the whole page - how do I get it to keep the widths that I set
-

BigAl1958
-
- Posts: 11
- Joined: Thu Jun 08, 2017 3:45 pm
Mon Jan 11, 2021 2:25 am
Hello,
Thanks for your inquiry and sorry for the late reply as weekend.
Please refer to the following code to keep the widths that match the size of the data.
- Code: Select all
PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add();
PdfGrid grid = new PdfGrid();
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 11f), true);
PdfPen pen = new PdfPen(Color.Black);
grid.Style.CellPadding = new PdfPaddings(1, 1, 1, 1);
grid.Style.Font = font;
grid.Style.TextPen = pen;
PdfGridRow row1 = grid.Rows.Add();
grid.Columns.Add(2);
string str = "Insert content to table";
PdfStringFormat format = new PdfStringFormat();
foreach (PdfGridColumn col in grid.Columns)
{
SizeF size = font.MeasureString(str, format);
float width = size.Width;
col.Width = width+5;
}
for (int i = 0; i < grid.Columns.Count; i++)
{
row1.Cells[i].Value = str;
}
grid.Draw(page, new PointF(0, 20));
doc.SaveToFile("PDFTable.pdf", FileFormat.PDF);
If you have any other questions, please feel free to contact us.
Sincerely,
Marcia
E-iceblue support team
-


Marcia.Zhou
-
- Posts: 858
- Joined: Wed Nov 04, 2020 2:29 am
Fri Jan 15, 2021 7:58 am
Hello,
Hope you are doing well.
Has the issue been solved now? Could you please give us some feedback at your convenience?
Thanks in advance.
Sincerely,
Marcia
E-iceblue support team
-


Marcia.Zhou
-
- Posts: 858
- Joined: Wed Nov 04, 2020 2:29 am
Fri Jan 22, 2021 8:19 am
Worked perfectly!
-

BigAl1958
-
- Posts: 11
- Joined: Thu Jun 08, 2017 3:45 pm
Mon Jan 25, 2021 2:18 am
Hello,
Glad to hear that your issue has been solved.
If you encounter any issues related to our product in the future, just feel free to contact us.
Have a nice day!
Sincerely,
Marcia
E-iceblue support team
-


Marcia.Zhou
-
- Posts: 858
- Joined: Wed Nov 04, 2020 2:29 am