Vb.net 在Aspose.Pdf中,为什么给文本对象一个边框实际上给它两个边框?我如何摆脱内部边界?

Vb.net 在Aspose.Pdf中,为什么给文本对象一个边框实际上给它两个边框?我如何摆脱内部边界?,vb.net,aspose,aspose.pdf,Vb.net,Aspose,Aspose.pdf,以下是我的风格: Dim sectionHeaderStyle As TextInfo = New TextInfo() sectionHeaderStyle.FontName = "Arial" sectionHeaderStyle.FontSize = 16 sectionHeaderStyle.Alignment = AlignmentType.Left sectionHeaderStyle.IsTrueTypeFontBold = True sectionHeader

以下是我的风格:

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
在这里,我使用该样式创建了一个
Text
对象:

<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

公共函数CreateBlankSection(ByVal pdf为pdf,ByVal marginInfo为marginInfo,ByVal sectionHeaderStyle为TextInfo,ByVal mainStyle为TextInfo,ByVal headerText为String)作为节
'将空白部分添加到PDF文档中
Dim sec As Section=pdf.Sections.Add()
sec.PageInfo.PageWidth=8.5*72
sec.PageInfo.PageHeight=11*72
第PageInfo.Margin节=marginInfo
sec.TextInfo=mainStyle
'添加节标题
将文本尺寸标注为文本=秒CreateText(sectionHeaderStyle,headerText)
'返回创建的节
返回秒
端函数
公共函数CreateText(ByVal sec作为节,ByVal样式作为TextInfo,ByVal文本作为字符串)作为文本
Dim txt As Text=新文本(秒,文本)
txt.TextInfo=样式
第节段落添加(txt)
返回文本
端函数
但是当我渲染这个部分时(在这个屏幕截图中,除了标题之外,我还添加了一些表格和文本),我得到了两个边框


这是怎么回事?我怎样才能摆脱内边界?我只需要外部边框。

如您问题下的注释所示,检查以下基于DOM的示例代码段(Aspose.Pdf),并在Pdf文档中创建一个表

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");
下面是由上述代码片段生成的示例输出。您可以注意到文本内容与其边框正确对齐


我想知道在
Text
对象上设置边框的方法是否错误。但我还能怎么做呢?看起来您使用的是旧的Aspose.Pdf.Generator方法,该方法已从Aspose.Pdf停止使用。建议使用DOM(Aspose.Pdf)模型在Pdf中添加文本和内容。您可以通过在PDF()中添加表来实现类似的输出。还请确保在建议的示例中使用最新版本的API。如果您遇到任何问题,我们建议在官方支持论坛()上创建帖子。这是Asad Ali,我在Aspose担任开发人员布道者。根据我们在前面评论中的建议,我们在下面添加了一个答案和一个示例代码片段。你可以检查一下,试试看。此外,如果您需要进一步的信息和不同的要求,您可以接受答案或让我们知道。