Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
184 views
in Technique[技术] by (71.8m points)

vb.net - how to format paragraph string to show content left, Right or middle of pdf document using iTextsharp ' vb

how to format paragraph string to show content left, Right or middle of pdf document using iTextsharp in visual basic and absolute position on the document.

Thanks

as per suggestion by Bruno Lowagie I am using

Dim table As New PdfPTable(3)
table.setWidthPercentage(100)
table.addCell(getCell("Text to the left", PdfPCell.ALIGN_LEFT))
table.addCell(getCell("Text in the middle", PdfPCell.ALIGN_CENTER))
table.addCell(getCell("Text to the right", PdfPCell.ALIGN_RIGHT))
document.add(table)

Public Function getCell(ByVal text As String, ByVal alignment As Integer) As PdfPCell
Dim cell As New PdfPCell(New Phrase(text))
cell.setPadding(0)
cell.setHorizontalAlignment(alignment)
cell.setBorder(PdfPCell.NO_BORDER)
Return cell
End Function

I am getting error cell.setPadding, cell.setHorizontalAlignment,cell.setBorder all are notmember of iTextsharp.Text.pdf.PdfPCell also table.setWidthPercentage(100) shows error argument not specified parameter 'page size'

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I am not a visual basic programmer (the last time I used visual basic was in 1996 and I said: never again!), but just by using Google, I adapted your example like this:

Dim table As New PdfPTable(3)
table.WidthPercentage = 100
table.AddCell(GetCell("Text to the left", PdfPCell.ALIGN_LEFT))
table.AddCell(GetCell("Text in the middle", PdfPCell.ALIGN_CENTER))
table.AddCell(GetCell("Text to the right", PdfPCell.ALIGN_RIGHT))
document.Add(table)

Public Function GetCell(ByVal text As String, ByVal alignment As Integer) As PdfPCell
    Dim cell As New PdfPCell(New Phrase(text))
    cell.Padding = 0
    cell.HorizontalAlignment = alignment
    cell.Border = PdfPCell.NO_BORDER
    Return cell
End Function

This is commonly known:

  • Methods in Java start with lower case; methods in .NET start with upper case, so when people ask you to use Java code as pseudo code and to convert Java to .NET, you need to change methods such as add() and addCell() into Add() and AddCell().
  • Member-variables in Java are changed and consulted using getters and setters; variables in .NET are changed and consulted using methods that look like properties. This means the you need to change lines such as cell.setBorder(border); and border = cell.getBorder(); into cell.Border = border and border = cell.Border.

iText and iTextSharp are kept in sync, which means that, using the two rules explained above, a developer won't have any problem to convert iText code into iTextSharp code.

When in doubt about a method, one can always do as I did, Google for these methods and properties! You'll find examples such as:

If you want a whole bunch of examples in one place, download The Best iText Questions on StackOverflow


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...