Hi there,
I have a table that spam over multiple pages and I want to print/stamp a horizontal line at the bottom of each page.
Using the code below I’m able to see the line only on the first two pages, no matter which size/position I use for the Aspose.Pdf.Drawing.Line or the Aspose.Pdf.Drawing.Graph.
Is there anything that I’m doing wrong here?
This is the output PDF TestLine.pdf (24.6 KB)
And this is my code:
Document document = new Document(); Page page = document.Pages.Add(); page.PageInfo.Margin = defaultPageMargins; Aspose.Pdf.Table table = new Aspose.Pdf.Table(); table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.Bottom, .1f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray)); table.HorizontalAlignment = HorizontalAlignment.Center; table.ColumnWidths = "45 50 50 40 90 90 55 55 55"; table.DefaultCellTextState.FontSize = 8; Row headerRow = table.Rows.Add(); headerRow.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.Bottom, 1f, Aspose.Pdf.Color.Parse("#004307")); headerRow.DefaultCellTextState.FontStyle = FontStyles.Bold; headerRow.DefaultCellPadding = defaultCellPadding; headerRow.Cells.Add("Col A"); headerRow.Cells.Add("Col B"); headerRow.Cells.Add("Col C"); headerRow.Cells.Add("Type").Alignment = HorizontalAlignment.Center; headerRow.Cells.Add("Desc"); headerRow.Cells.Add("Description"); headerRow.Cells.Add("FF").Alignment = HorizontalAlignment.Right; headerRow.Cells.Add("LL").Alignment = HorizontalAlignment.Right; headerRow.Cells.Add("BB").Alignment = HorizontalAlignment.Right; for (int row_count = 0; row_count < 120; row_count++) { // Add row to table Aspose.Pdf.Row row = table.Rows.Add(); row.DefaultCellPadding = defaultCellPadding; // Add table cells row.Cells.Add("XYZ"); row.Cells.Add("dasdasd adsasasd as"); row.Cells.Add("01/01/2021"); row.Cells.Add("LX").Alignment = HorizontalAlignment.Center; row.Cells.Add("desription"); row.Cells.Add("Another Desription"); row.Cells.Add((12312).ToString("N2", CultureInfo.CurrentCulture)).Alignment = HorizontalAlignment.Right; row.Cells.Add((12312).ToString("N2", CultureInfo.CurrentCulture)).Alignment = HorizontalAlignment.Right; row.Cells.Add("435").Alignment = HorizontalAlignment.Right; } page.Paragraphs.Add(table); logger.LogDebug($"Number pages in the doc: {document.Pages.Count}"); document.ProcessParagraphs(); logger.LogDebug($"Number pages in the doc after save: {document.Pages.Count}"); for (int i = 1; i <= document.Pages.Count; i++) //foreach (var p in document.Pages) { var p = document.Pages[i]; logger.LogDebug(p.Number.ToString()); logger.LogDebug($"Page Info - PW={p.PageInfo.Width} PH={p.PageInfo.Height} PLLX={p.Rect.LLX} PLLY={p.Rect.LLY} PURX={p.Rect.URX} PURY={p.Rect.URY}"); logger.LogDebug($"Page Margin - MB={p.PageInfo.Margin.Bottom} MT={p.PageInfo.Margin.Top} ML={p.PageInfo.Margin.Left} MR={p.PageInfo.Margin.Right}"); var lineHeight = (float)(p.Rect.Height - p.PageInfo.Margin.Bottom - p.PageInfo.Margin.Top); var lineWidth = (float)(p.PageInfo.Width - p.PageInfo.Margin.Left - p.PageInfo.Margin.Right); var marginTBTotal = (float)(p.PageInfo.Margin.Left + p.PageInfo.Margin.Right); logger.LogDebug($"Calculated line size/position lineHeight={lineHeight} lineWidth={lineWidth}"); Aspose.Pdf.Drawing.Graph graph = new Aspose.Pdf.Drawing.Graph((float)p.PageInfo.Width, (float)p.Rect.Height); graph.Top = 0; graph.Left = 0; Aspose.Pdf.Drawing.Line line = new Aspose.Pdf.Drawing.Line(new float[] { 0, marginTBTotal, lineWidth, marginTBTotal }); line.GraphInfo.Color = _appColor; graph.Shapes.Add(line); p.Paragraphs.Add(graph); } using (Stream outputStream = new FileStream(_dataDir + "TestLine.pdf", FileMode.Create, FileAccess.Write)) { document.Save(outputStream); document.Dispose(); }
This is the output of the iteration over the pages:
1
Page Info - PW=595 PH=842 PLLX=0 PLLY=0 PURX=595 PURY=842
Page Margin - MB=40 MT=40 ML=30 MR=30
Calculated line size/position lineHeight=762 lineWidth=535
2
Page Info - PW=595 PH=842 PLLX=0 PLLY=0 PURX=595 PURY=842
Page Margin - MB=40 MT=40 ML=30 MR=30
Calculated line size/position lineHeight=762 lineWidth=535
3
Page Info - PW=595 PH=842 PLLX=0 PLLY=0 PURX=595 PURY=842
Page Margin - MB=40 MT=40 ML=30 MR=30
Calculated line size/position lineHeight=762 lineWidth=535
4
Page Info - PW=595 PH=842 PLLX=0 PLLY=0 PURX=595 PURY=842
Page Margin - MB=40 MT=40 ML=30 MR=30
Calculated line size/position lineHeight=762 lineWidth=535