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

Free Support Forum - aspose.com

The height of split table

Hello,


I need to get a real table height. I used to use table.GetHeight API method, but sometimes a table may be split with a repeated header. In this case the height of the header is ignored by your API. In other words the API returns the same result no matter if a table is split or it’s not.

Could you please advise how to calculate the table height properly in this case.

Hi Dmitry,


Thanks for your inquiry. We have already noticed that GetHeight() method is not returns correct table height and logged a ticket PDFNEWNET-38273 in our issue tracking system for the rectification. We will notify you as soon as it is resolved.

We are sorry for the inconvenience caused.

Best Regards,

Also your API GetTableHeight method ignores border line width (no matter if a table is split or it’s not). The more lines the more discrepancies with the real value.

Dmitry,


Thanks for sharing your findings, We have passed on the information to our product team, they will consider during the issue resolution. We will notify you as soon as we made some significant progress towards issue resolution.

Thanks for your patience and cooperation.

Best Regards,

@ShmelP

We would like to request you to use below code snippet in your environment and then share your kind feedback with us. Adobe Acrobat displays the table height as 3.42 inches. Converting it to basic unit of Aspose.PDF API, Point, where 1 inch equals 72 points: 3.42 inches * 72 = 246.24, likewise GetHeight method return the value 247.

string outFile = "38273.pdf";
var AsposePdf = new Document();
AsposePdf.PageInfo = new PageInfo()
{
    Height = 595,
    Width = 841,
    Margin = new MarginInfo() { Left = 30, Top = 60, Right = 30, Bottom = 30 }
};

Page section = AsposePdf.Pages.Add();
section.PageInfo = AsposePdf.PageInfo;

Table table = new Table();
table.Margin = new MarginInfo { Left = 0, Bottom = 0, Right = 0, Top = 0 };
table.DefaultCellPadding = new MarginInfo() { Left = 2, Bottom = 4, Right = 2, Top = 4 };
table.Border = new BorderInfo(BorderSide.All, 0.5f);

float minHeight = 0;
float cellHeight = 0;
float width = (float)(AsposePdf.PageInfo.Width - AsposePdf.PageInfo.Margin.Left - AsposePdf.PageInfo.Margin.Right);
List<float> widths = new List<float>();
widths.Add(width / 732 * 124);
widths.Add(width / 732 * 124);
widths.Add(width / 732 * 80);
widths.Add(width / 732 * 190);
widths.Add(width / 732 * 90);
widths.Add(width / 732 * 124);

StringBuilder builder = new StringBuilder();
for (int i = 0; i < widths.Count; i++)

{ builder.Append(widths[i] + " "); }
table.ColumnWidths = builder.ToString();

MarginInfo defaultTextMargin = new MarginInfo() { Left = 0, Right = 0, Top = 3, Bottom = 3 };
TextState defaultBigFont = new TextState() { FontSize = 8.5f, Font = FontRepository.FindFont("Helvetica-Bold") };
TextState defaultSmallFont = new TextState() { FontSize = 8f, Font = FontRepository.FindFont("Helvetica") };

//Première colonne Number Reference Priority
TextFragment numberText = new TextFragment("DEF-0008");
numberText.TextState.ApplyChangesFrom(defaultBigFont);
numberText.Margin = new MarginInfo() { Left = 0, Right = 0, Top = 0, Bottom = 3 };

TextFragment refText = new TextFragment("Old DEF-013");
refText.TextState.ApplyChangesFrom(defaultSmallFont);
refText.Margin = defaultTextMargin;

TextFragment prioText = new TextFragment("[B] - Needed before hand over");
prioText.TextState.ApplyChangesFrom(defaultSmallFont);
prioText.Margin = defaultTextMargin;

//Deuxième colonne = Package Discipline System

TextFragment pkgText = new TextFragment("SGJV");
pkgText.TextState.ApplyChangesFrom(defaultBigFont);
pkgText.Margin = defaultTextMargin;

TextFragment discText = new TextFragment("[10730] POWER SUPPLY & DISTRIBUTION");
discText.TextState.ApplyChangesFrom(defaultSmallFont);
discText.Margin = defaultTextMargin;

TextFragment sysText = new TextFragment("S3");
sysText.TextState.ApplyChangesFrom(defaultSmallFont);
sysText.Margin = defaultTextMargin;

//Troisième colonne = Items

TextFragment itemText = new TextFragment("");
itemText.TextState.ApplyChangesFrom(defaultSmallFont);
itemText.Margin = defaultTextMargin;

//Quatrième colonne = Details
TextFragment descText = new TextFragment(@"During a joint inspection with Carlos Ferreira (SGJV) on
May 22, 2014, the following grounding pad deficencies
identified by SGJV were reviewed:
1. P2-4: The I/B ground Plate was out of
position.
2. P2-4: The Center ground Plate was too low.
3. P2-4: The O/B ground Plate was out of
position and too low.
4. P2-5: The I/B ground Plate was out of
position.
5. P2-5: The O/B ground Plate was out of
position.
6. P2-6: The I/B ground Plate was out of
position.
7. P2-6: The Center ground Plate was too low.
8. P2-6: The O/B ground Plate was out of
position.
9. P2-7: The I/B ground Plate was out of
position.
10. P2-7: The O/B ground Plate was missing.
11. P2-8: Ground cable tails were missing.");
descText.TextState.ApplyChangesFrom(defaultSmallFont);
descText.Margin = defaultTextMargin;

//Cinquième colonne = Raised By/Date Action By/Required Date
TextFragment rbText = new TextFragment("Simon Gould");
rbText.TextState.ApplyChangesFrom(defaultSmallFont);
rbText.Margin = defaultTextMargin;

TextFragment drText = new TextFragment("05/22/2014");
drText.TextState.ApplyChangesFrom(defaultSmallFont);
drText.Margin = new MarginInfo() { Left = 0, Right = 0, Top = 0, Bottom = 6 };

TextFragment abText = new TextFragment("Garry Robertson");
abText.TextState.ApplyChangesFrom(defaultSmallFont);
abText.Margin = defaultTextMargin;

TextFragment dreqText = new TextFragment("n/a");
dreqText.TextState.Font = FontRepository.FindFont("Helvetica");
dreqText.TextState.FontSize = 8f;
dreqText.Margin = defaultTextMargin;
//Sixième colonne = Status

string statusString = "";
int j = 0;
TextFragment stepText = new TextFragment();
TextSegment seg = new TextSegment("Approval of Correction");
seg.TextState.Font = FontRepository.FindFont("Helvetica-Bold");
seg.TextState.FontSize = 8f;
stepText.Segments.Add(seg);

seg = new TextSegment(" since: ");
seg.TextState = defaultSmallFont;
stepText.Segments.Add(seg);

seg = new TextSegment("06/02/2014");
seg.TextState.Font = FontRepository.FindFont("Helvetica-Bold");
seg.TextState.FontSize = 8f;
stepText.Segments.Add(seg);

seg = new TextSegment(" by: ");
seg.TextState = defaultSmallFont;
stepText.Segments.Add(seg);

seg = new TextSegment("Simon Gould");
seg.TextState.Font = FontRepository.FindFont("Helvetica-Bold");
seg.TextState.FontSize = 8f;
stepText.Segments.Add(seg);

stepText.Margin = defaultTextMargin;

TextFragment step2Text = new TextFragment("(2/3 steps completed)");
step2Text.TextState.Font = FontRepository.FindFont("Helvetica");
step2Text.TextState.FontSize = 7f;
step2Text.Margin = defaultTextMargin;

TextFragment step3Text = new TextFragment("nno");
step3Text.TextState.Font = FontRepository.FindFont("ZapfDingbats");
step3Text.TextState.FontSize = 7f;
step3Text.Margin = defaultTextMargin;
System.Console.Out.WriteLine("CellHeigh:{0} ", cellHeight);

Row row = table.Rows.Add();
row.VerticalAlignment = VerticalAlignment.Top;

//Première colonne Number Reference Priority
Cell cell = row.Cells.Add();
cell.Alignment = HorizontalAlignment.Left;
cell.Paragraphs.Add(numberText);
cell.Paragraphs.Add(refText);
cell.Paragraphs.Add(prioText);

//Deuxième colonne = Package Discipline System
cell = row.Cells.Add();
cell.Alignment = HorizontalAlignment.Left;
cell.Paragraphs.Add(pkgText);
cell.Paragraphs.Add(discText);
cell.Paragraphs.Add(sysText);

//Troisième colonne = Items
cell = row.Cells.Add();
cell.Alignment = HorizontalAlignment.Left;
cell.Paragraphs.Add(itemText);

//Quatrième colonne = Details
cell = row.Cells.Add();
cell.Alignment = HorizontalAlignment.Left;
cell.Paragraphs.Add(descText);

//Cinquième colonne = Raised By/Date Action By/Required Date
cell = row.Cells.Add();
cell.Alignment = HorizontalAlignment.Left;
cell.Paragraphs.Add(rbText);
cell.Paragraphs.Add(drText);
cell.Paragraphs.Add(abText);
cell.Paragraphs.Add(dreqText);

//Sixième colonne = Status
cell = row.Cells.Add();
cell.Alignment = HorizontalAlignment.Left;
cell.Paragraphs.Add(stepText);
cell.Paragraphs.Add(step2Text);
cell.Paragraphs.Add(step3Text);

section.Paragraphs.Add(table);
double tableHeight = 0;
foreach (Table myTable in section.Paragraphs)
{
    tableHeight = myTable.GetHeight();
    System.Console.Out.WriteLine("tableHeight:{0} ", tableHeight);
}
AsposePdf.Save(outFile);

We hope this will be helpful. Please feel free to contact us if you need any further assistance.