Reputation: 45
I am using MigraDoc (v1.50.5147) with .NET Framework 4.5.2 on Visual Studio 2015.
I am making a simple Packing Slip PDF document, that shows a list of containers and parts inside each container. There is one single table (no nested tables) with a header that is repeating across all pages. There are some rows which I have given a border (to indicate a container) and the rows underneath without border (to indicate parts inside the container). The "container" row and "part" rows are all kept together, to not be separated across page breaks.
I have everything exactly how I want... except for an undesired, extra border that is showing up at the bottom of every page prior to the page break. It seems that the "container" rows' borders are causing this, but I want to keep the "container" rows' borders.
Is there a way I can get rid of this extra border at the bottom of every page? (even though it does have a nice effect, it would be good if this was possible to control)
Not using PDFSharp, but solutions are welcome to involve PDFSharp if this cannot be solved without MigraDoc alone.
Here is the minimum reproducible code:
static void Main(string[] args)
{
Document document = new Document();
Section section = document.AddSection();
section.PageSetup = document.DefaultPageSetup.Clone();
Unit sectionWidth = section.PageSetup.PageWidth - section.PageSetup.LeftMargin - section.PageSetup.RightMargin;
Table table = section.AddTable();
table.TopPadding = "0.5mm";
table.BottomPadding = "0.5mm";
Column column = table.AddColumn(sectionWidth * 0.10);
column = table.AddColumn(sectionWidth * 0.20);
column = table.AddColumn(sectionWidth * 0.7);
Row row = table.AddRow(); // header row
row.Borders.Width = "1pt"; // this border has no effect on the extra border caused by "container" rows' borders below
Paragraph paragraph = row.Cells[0].AddParagraph();
paragraph.AddFormattedText("QTY", TextFormat.Bold);
paragraph = row.Cells[1].AddParagraph();
paragraph.AddFormattedText("UNIT", TextFormat.Bold);
paragraph = row.Cells[2].AddParagraph();
paragraph.AddFormattedText("NUMBER", TextFormat.Bold);
row.HeadingFormat = true; // to make header row repeat on page break
row.KeepWith = 1; // keeps header row with below dummy space row on page break
row = table.AddRow(); // dummy space row
for (int i = 1; i <= 50; i++) // repeat container+parts rows as many times as desired
{
row = table.AddRow(); // this is the "container" row
table.SetEdge(0, row.Index, 3, 1, Edge.Box, BorderStyle.Single, "1pt"); // this causes extra border at bottom... without this, border isn't there
//row.Borders.Top.Width = "1pt"; row.Borders.Bottom.Width = "1pt"; // this also causes extra border at bottom... without this, border isn't there
row.Cells[0].AddParagraph("1");
row.Cells[1].AddParagraph("BOX");
row.Cells[2].AddParagraph("BOX NUMBER");
row.KeepWith = 2; // keeps "container" row together with the below "part" rows (put 3 if also using dummy space row below)
row = table.AddRow(); // one "part" row
row.Cells[0].AddParagraph("3");
row.Cells[1].AddParagraph("PCS");
row.Cells[2].AddParagraph("PART NUMBER");
row = table.AddRow(); // another "part" row
row.Cells[0].AddParagraph("3");
row.Cells[1].AddParagraph("PCS");
row.Cells[2].AddParagraph("PART NUMBER\n\n"); // single \n didn't make space; double \n made space, but still extra border at bottom... thought the dummy space row below was causing extra border so tried \n instead, but dummy space row wasn't the cause...
//row = table.AddRow(); // dummy space row; with or without it, still extra border at bottom, caused by setting a border on the "container" row above
}
PdfDocumentRenderer renderer = new PdfDocumentRenderer();
renderer.Document = document;
renderer.RenderDocument();
renderer.Save("document.pdf");
}
Here is a screenshot showing the extra border:
Upvotes: 0
Views: 41