0

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.

ekolis
  • 6,270
  • 12
  • 50
  • 101
  • I wonder if `TextBorder` is the wrong way to set the border on the `Text` object. But how else can I do it? – ekolis Oct 20 '20 at 18:58
  • It seems like you are using old Aspose.Pdf.Generator approach which has been discontinued from Aspose.PDF. It is recommended to use DOM (Aspose.Pdf) model in order to add text and content inside PDF. You may achieve similar output by adding tables inside PDF (https://docs.aspose.com/pdf/net/add-and-extract-a-table/). Please also make sure to use the latest version of the API with the suggested example. In case you face any issue, we recommend creating post over official support forum(https://forum.aspose.com/c/pdf). This is Asad Ali and I work as Developer Evangelist at Aspose. – Asad Ali Oct 21 '20 at 19:17
  • We have added an answer below with a sample code snippet as per our suggestions in the previous comment. You may please check and try it. Also, you may please accept the answer OR let us know if you need further information and have different requirements. – Asad Ali Nov 24 '20 at 13:34

1 Answers1

1

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

Asad Ali
  • 361
  • 1
  • 15