Free Support Forum - aspose.com

How to get page width to calculate columns

We need to do some custom calculating of column widths.

1. How can I find out the maximum amount of horizontal space that the table has to work with?

2. When you say e.g. “minimum column width” as on the page:
http://www.aspose.com/Products/Aspose.Pdf/Api/Aspose.Pdf.Table.GetMinColumnWidth.html
what are the units here, are these millimeters, pixels?

3. I suppose I need to take the following into consideration:

- segment/page margins
- table margins
- border size

when figuring out how much space is left as I add each column

or is there an easier way?

Thanks,

Edward

Dear Edward,

Thanks for your consideration.

1)The default unit of width is point,which is 1/72 inch.

2) If you use GetMinColumnWidth, you need not consider border width since the method has counted it. So the page width minus page margins and table margins is the reserved space for your table.


Dear Edward,

Thanks for your consideration.

I am sorry. You should consider the border size. Page width minus page margins and table margins and border width is the reserved space for your table.


Ok, but where do I get how much space the table has to fill?

I was expecting something like:

pdf.maxWidth

or

segment.maxWidth

Thanks,

Edward

Dear Edward,

Thanks for your consideration.

Do you mean you want to get the space which can be used for paragraphs by the section.maxWidth?

Exactly. Right now when calculating column widths, I use this line:

float maximumTableWidth = 684;

which I simply found out manually, but this only true if I have the page in landscape mode and with the specific margins that I have.

This is the number of points that my columns are allowed to take up on the page. But if I change the page to portrait and change the margins than I have to recalculate this manually.

Is there a way of getting this number automatically, so that I could say something like:

float maximumTableWidth = page.MaximumPointsForTableColumns;

or something like that?

Thanks,

Edward

Dear Edward,

Thanks for your consideration.

You can write your code like the following:

float pagewidth;
if(section.IsLandscape)
pagewidth = section.PageInfo.PageHeight;
else
pagewidth = section.PageInfo.PageWidth;

float maximumTableWidth = pagewidth - section.PageInfo.Margin.Left - section.PageInfo.Margin.Right -
tableBorderWidth;