Here is my style:

Dim sectionHeaderStyle As TextInfo = New TextInfo()
sectionHeaderStyle.FontName = "Arial"
sectionHeaderStyle.FontSize = 16
sectionHeaderStyle.Alignment = AlignmentType.Left
sectionHeaderStyle.IsTrueTypeFontBold = True
sectionHeaderStyle.IsTrueTypeFontItalic = False
sectionHeaderStyle.Color = New Aspose.Pdf.Color("Black")
' TODO: why are we getting a double border?
sectionHeaderStyle.TextBorder = New BorderInfo(15) ' 15 is binary 1111 so it means all four borders
sectionHeaderStyle.BackgroundColor = New Aspose.Pdf.Color("Silver")
sectionHeaderStyle.IsUnderline = False

And here is where I create a Text object using that style:

<Extension>
Public Function CreateBlankSection(ByVal pdf As Pdf, ByVal marginInfo As MarginInfo, ByVal sectionHeaderStyle As TextInfo, ByVal mainStyle As TextInfo, ByVal headerText As String) As Section
    ' Add a blank section into the PDF document
    Dim sec As Section = pdf.Sections.Add()
    sec.PageInfo.PageWidth = 8.5 * 72
    sec.PageInfo.PageHeight = 11 * 72
    sec.PageInfo.Margin = marginInfo
    sec.TextInfo = mainStyle

    ' Add the section title
    Dim text As Text = sec.CreateText(sectionHeaderStyle, headerText)

    ' Return the section created
    Return sec
End Function

<Extension>
Public Function CreateText(ByVal sec As Section, ByVal style As TextInfo, ByVal text As String) As Text
    Dim txt As Text = New Text(sec, text)
    txt.TextInfo = style
    sec.Paragraphs.Add(txt)
    Return txt
End Function

But when I render the section (in this screenshot I added some more tables and text besides the header), I get two borders?!

enter image description here

What's going on here? How can I get rid of the inner border? All I want is the outer border.

1

There are 1 answers

0
Asad Ali On

As suggested in the comment under your question, check the following sample code snippet which is DOM Based (Aspose.Pdf), and creates a table in the PDF document.

var doc = new Document();
var page = doc.Pages.Add();
page.PageInfo.Margin = new MarginInfo(10, 10, 10, 10);

Aspose.Pdf.Table pdfTable = new Table
{
 ColumnWidths = "200 100 150"
};

pdfTable.DefaultCellBorder = new BorderInfo(BorderSide.All, 1f);

page.Paragraphs.Add(pdfTable);

var headerRow = pdfTable.Rows.Add();
headerRow.DefaultCellTextState = new TextState() { FontSize = 20f, FontStyle = FontStyles.Bold };
headerRow.Cells.Add("Primary Parent Information");
headerRow.Cells[0].ColSpan = 3;

var secondRow = pdfTable.Rows.Add();
secondRow.Cells.Add("Primary Parent Name");
secondRow.Cells.Add("Date of Birth");
secondRow.Cells.Add("Current Age");

var thirdRow = pdfTable.Rows.Add();
thirdRow.Cells.Add("Clark Kentenburger");
thirdRow.Cells.Add("9/28/1978");
thirdRow.Cells.Add("42");

doc.Save("Table.pdf");

Below is the sample output generated by the above code snippet. You can notice that the text content is properly aligned along with its borders.

Sample Output of the above code snippet