Hello,
Hi Alexandre,
Thank you for your prompt response.
I have attached the PDF containing the result of the sampled code.
EDIT: I use Aspose.Pdf version 8.4.1.0. I know it’s outdated. I need to know if the issue is fixed in later releases so I can ask for my employer to get a new license.
Here is the sample code, you can see at the end where I run a GetHeight() on the section tables, it gives me 190 on run time but the PDF is clearly above that, about 283 points. The texts.GetHeight() is for another purpose and doesn’t give me a problem, only the Table.GetHeigth() at the end:
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(“WMS.Reports.Aspose.Total.lic”);
AsposePdf = new Aspose.Pdf.Generator.Pdf();
AsposePdf.PageSetup = new PageSetup()
{
PageHeight = 595,
PageWidth = 841,
Margin = new MarginInfo()
{
Left = 30,
Top = 60,
Right = 30,
Bottom = 30
}
};
Aspose.Pdf.Generator.Section section = AsposePdf.Sections.Add();
section.PageInfo = (PageSetup)AsposePdf.PageSetup.Clone();
Table table = new Table();
//table.ColumnAdjustment = ColumnAdjustmentType.AutoFitToWindow;
table.IsKeptTogether = false;
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((int)BorderSide.All, 0.5f);
float minHeight = 0;
float cellHeight = 0;
float width = AsposePdf.PageSetup.PageWidth - AsposePdf.PageSetup.Margin.Left - AsposePdf.PageSetup.Margin.Right;
List widths = new List();
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);
for (int i = 0; i < widths.Count; i++)
{
table.SetColumnWidth(i, widths[i]);
}
MarginInfo defaultTextMargin = new MarginInfo() { Left = 0, Right = 0, Top = 3, Bottom = 3 };
TextInfo defaultBigFont = new TextInfo() { FontSize = 8.5f, FontName = “Helvetica-Bold” };
TextInfo defaultSmallFont = new TextInfo() { FontSize = 8f, FontName = “Helvetica” };
//Première colonne Number Reference Priority
Text numberText = new Text(“DEF-0008”);
numberText.TextInfo = defaultBigFont;
numberText.Margin = new MarginInfo() { Left = 0, Right = 0, Top = 0, Bottom = 3 };
cellHeight = numberText.GetTextHeight(AsposePdf, widths[0]) + numberText.Margin.Top + numberText.Margin.Bottom;
Text refText = new Text(“Old DEF-013”);
refText.TextInfo = defaultSmallFont;
refText.Margin = defaultTextMargin;
cellHeight += refText.GetTextHeight(AsposePdf, widths[0]) + refText.Margin.Top + refText.Margin.Bottom;
Text prioText = new Text("[B] - Needed before hand over");
prioText.TextInfo = defaultSmallFont;
prioText.Margin = defaultTextMargin;
cellHeight += prioText.GetTextHeight(AsposePdf, widths[0]) + prioText.Margin.Top + prioText.Margin.Bottom;
minHeight = cellHeight > minHeight ? cellHeight : minHeight;
//Deuxième colonne = Package Discipline System
Text pkgText = new Text(“SGJV”);
pkgText.TextInfo = defaultBigFont;
pkgText.Margin = defaultTextMargin;
cellHeight = pkgText.GetTextHeight(AsposePdf, widths[1]) + pkgText.Margin.Top + pkgText.Margin.Bottom;
Text discText = new Text("[10730] POWER SUPPLY & DISTRIBUTION");
discText.TextInfo = defaultSmallFont;
discText.Margin = defaultTextMargin;
cellHeight += discText.GetTextHeight(AsposePdf, widths[1]) + discText.Margin.Top + discText.Margin.Bottom;
Text sysText = new Text(“S3”);
sysText.TextInfo = defaultSmallFont;
sysText.Margin = defaultTextMargin;
cellHeight += sysText.GetTextHeight(AsposePdf, widths[1]) + sysText.Margin.Top + sysText.Margin.Bottom;
minHeight = cellHeight > minHeight ? cellHeight : minHeight;
//Troisième colonne = Items
Text itemText = new Text("");
itemText.TextInfo = defaultSmallFont;
itemText.Margin = defaultTextMargin;
cellHeight = itemText.GetTextHeight(AsposePdf, widths[2]) + itemText.Margin.Top + itemText.Margin.Bottom;
minHeight = cellHeight > minHeight ? cellHeight : minHeight;
//Quatrième colonne = Details
Text descText = new Text(@“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.TextInfo = defaultSmallFont;
descText.Margin = defaultTextMargin;
//Cinquième colonne = Raised By/Date Action By/Required Date
Text rbText = new Text(“Simon Gould”);
rbText.TextInfo = defaultSmallFont;
rbText.Margin = defaultTextMargin;
cellHeight = rbText.GetTextHeight(AsposePdf, widths[4]) + rbText.Margin.Top + rbText.Margin.Bottom;
Text drText = new Text(“05/22/2014”);
drText.TextInfo = defaultSmallFont;
drText.Margin = new MarginInfo() { Left = 0, Right = 0, Top = 0, Bottom = 6 };
cellHeight += drText.GetTextHeight(AsposePdf, widths[4]) + drText.Margin.Top + drText.Margin.Bottom;
Text abText = new Text(“Garry Robertson”);
abText.TextInfo = defaultSmallFont;
abText.Margin = defaultTextMargin;
cellHeight += abText.GetTextHeight(AsposePdf, widths[4]) + abText.Margin.Top + abText.Margin.Bottom;
Text dreqText = new Text(“n/a”);
dreqText.TextInfo.FontName = “Helvetica”;
dreqText.TextInfo.FontSize = 8f;
dreqText.TextInfo.Color = new Color("#B8B8B8");
dreqText.Margin = defaultTextMargin;
cellHeight += dreqText.GetTextHeight(AsposePdf, widths[4]) + dreqText.Margin.Top + dreqText.Margin.Bottom;
minHeight = cellHeight > minHeight ? cellHeight : minHeight;
//Sixième colonne = Status
string statusString = “”;
int j = 0;
Text stepText = new Text();
Segment seg = new Segment(“Approval of Correction”);
seg.TextInfo.FontName = “Helvetica-Bold”;
seg.TextInfo.FontSize = 8f;
stepText.Segments.Add(seg);
seg = new Segment(" since: “);
seg.TextInfo = defaultSmallFont;
stepText.Segments.Add(seg);
seg = new Segment(“06/02/2014”);
seg.TextInfo.FontName = “Helvetica-Bold”;
seg.TextInfo.FontSize = 8f;
stepText.Segments.Add(seg);
seg = new Segment(” by: “);
seg.TextInfo = defaultSmallFont;
stepText.Segments.Add(seg);
seg = new Segment(“Simon Gould”);
seg.TextInfo.FontName = “Helvetica-Bold”;
seg.TextInfo.FontSize = 8f;
stepText.Segments.Add(seg);
stepText.Margin = defaultTextMargin;
cellHeight = stepText.GetTextHeight(AsposePdf, widths[5]) + stepText.Margin.Top + stepText.Margin.Bottom;
Text step2Text = new Text(”(2/3 steps completed)");
step2Text.TextInfo.FontName = “Helvetica”;
step2Text.TextInfo.FontSize = 7f;
step2Text.Margin = defaultTextMargin;
cellHeight += step2Text.GetTextHeight(AsposePdf, widths[5]) + step2Text.Margin.Top + step2Text.Margin.Bottom;
Text step3Text = new Text(“nno”);
step3Text.TextInfo.FontName = “ZapfDingbats”;
step3Text.TextInfo.FontSize = 7f;
step3Text.Margin = defaultTextMargin;
cellHeight += step3Text.GetTextHeight(AsposePdf, widths[5]) + step3Text.Margin.Top + step3Text.Margin.Bottom;
minHeight = cellHeight > minHeight ? cellHeight : minHeight;
Row row = table.Rows.Add();
row.VerticalAlignment = VerticalAlignmentType.Top;
//Première colonne Number Reference Priority
Cell cell = row.Cells.Add();
cell.Alignment = AlignmentType.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 = AlignmentType.Left;
cell.Paragraphs.Add(pkgText);
cell.Paragraphs.Add(discText);
cell.Paragraphs.Add(sysText);
//Troisième colonne = Items
cell = row.Cells.Add();
cell.Alignment = AlignmentType.Left;
cell.Paragraphs.Add(itemText);
//Quatrième colonne = Details
cell = row.Cells.Add();
cell.Alignment = AlignmentType.Left;
cell.Paragraphs.Add(descText);
//Cinquième colonne = Raised By/Date Action By/Required Date
cell = row.Cells.Add();
cell.Alignment = AlignmentType.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 = AlignmentType.Left;
cell.Paragraphs.Add(stepText);
cell.Paragraphs.Add(step2Text);
cell.Paragraphs.Add(step3Text);
section.Paragraphs.Add(table);
foreach (Table myTable in section.Paragraphs)
{
float tableHeight = myTable.GetHeight(AsposePdf);
float tableHeightWithMargins = myTable.GetHeight(AsposePdf) + myTable.Margin.Top + myTable.Margin.Bottom;
}
//FINALISATION DU RAPPORT
String outputFile = String.Join("", TempFileLocation, Guid.NewGuid(), “.pdf”);
FileStream myStream = new FileStream(outputFile, FileMode.Create);
AsposePdf.Save(myStream);
myStream.Close();
Thank you for looking into this.
Hi Alexandre,
Any updates on this? I need to know if there’s a better way to get the height of the currently drawn tables in a section so I can tell how much space left on my page there is and break my page accordingly since the automatic page breaking isn’t sufficient. Unless there is an alternative solution to what I am trying to achieve?
Hi Alexandre,
Thank you for your response.
#3: For unknown reasons sometimes the bottom line of my rows doesn’t draw.drText = new Text(CurrentPunch.dateRaised.Value.ToShortDateString());drText.TextInfo = defaultSmallFont;drText.Margin = new MarginInfo() { Left = 0, Right = 0, Top = 0, Bottom = 6 };
- Each rows are in fact “Tables” of a single row, since the “IsKeptTogether” directive doesn’t exist for rows but only tables.
- Each column is composed of a single cell that, for some, contains multiple Text paragraphs.
Hi Alexandre,