' setIndentationLeft'不是' iTextsharp.text.Paragraph'的成员。

时间:2015-04-13 07:18:13

标签: itextsharp

我正在添加段落,我收到错误

  

p.setindentationLeft不是itextsharp.text.paragraph的成员。

 Dim bf As BaseFont = BaseFont.CreateFont()
 Dim p As New Paragraph(Label + CONTENT, New Font(bf, 12))
 Dim indentation As Single = bf.GetWidthPoint(Label, 12)
 p.setIndentationLeft(indentation)
 p.setFirstLineIndent(-indentation)
 Document.Add(p)
 Document.Add(Chunk.NEWLINE)  

1 个答案:

答案 0 :(得分:1)

您在iTextSharp应用程序中使用iText代码。您需要使用此答案中解释的规则将iText代码转换为iTextSharp代码:converting iText code to iTextSharp code

如有疑问,请注意iTextSharp是一个开源库。您可以随时查阅源代码。在您的情况下,您可以在Paragraph.cs上查看文件Github

您会注意到Java方法setIndentationLeft()实际上是这样实现的:

/// <summary>
/// Get/set the indentation of this paragraph on the left side.
/// </summary>
/// <value>a float</value>
virtual public float IndentationLeft {
    get {
        return indentationLeft;
    }
    set {
        this.indentationLeft = value;
    }
}

这意味着您需要在代码中使用此功能:

p.IndentationLeft = indentation

setFirstLineIndent()方法也是如此:

p.FirstLineIndent = -indentation

如前所述,您应该将Java示例视为伪代码,并且每当您点击而不是成员问题时,您应该应用其中一个遵循以下规则来解决问题:

  • Java中的方法以小写字母开头; .NET中的方法以大写字母开头,因此当人们要求您将Java代码用作伪代码并将Java转换为.NET时,您需要将add()addCell()等方法更改为{{ 1}}和Add()
  • 使用getter和setter更改和查询Java中的成员变量; .NET中的变量使用看起来像属性的方法进行更改和查询。这意味着您需要将AddCell()cell.setBorder(border);等行更改为border = cell.getBorder();cell.Border = border

这是对您之前的一个问题的答案的复制粘贴。如您所见,这个答案也解决了您当前的问题。