如何格式化段落字符串以使用iTextsharp'vb显示pdf文档的左侧,右侧或中间内容 [英] how to format paragraph string to show content left, Right or middle of pdf document using iTextsharp ' vb

查看:199
本文介绍了如何格式化段落字符串以使用iTextsharp'vb显示pdf文档的左侧,右侧或中间内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何格式化段落字符串以在文本的基本和绝对位置使用iTextsharp显示pdf文档的左侧,右侧或中间内容。



谢谢



按照Bruno Lowagie的建议我正在使用

  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.setHorizo​​ntalAlignment(alignment)
cell.setBorder(PdfPCell.NO_BORDER)
返回格元
结束函数

我收到错误
cell.setPadding,cell.setHorizo​​ntalAlignment,cell.setBorder all notme myextsharp.Text.pdf.PdfPCell的mber也表table.setWidthPercentage(100)显示错误参数未指定参数'page size'

解决方案

我不是一个视觉基础程序员(我最后一次使用visual basic是在1996年,我说:再也没有!),但只是通过使用Google,我改编了你的例子:

  Dim table As New PdfPTable(3)
table.WidthPercentage = 100
table.AddCell(GetCell(左边的文字,PdfPCell.ALIGN_LEFT))
table.AddCell(GetCell(中间的文字,PdfPCell.ALIGN_CENTER))
table.AddCell(GetCell(右边的文字, PdfPCell.ALIGN_RIGHT))
document.Add(table)

公共函数GetCell(ByVal text As String,ByVal alignment As Integer)As PdfPCell
Dim cell As New PdfPCell(New短语(文本))
cell.Padding = 0
cell.Horizo​​ntalAlignment = alignment
cell.Border = PdfPCell.NO_BORDER
返回单元格
结束函数

众所周知:




  • Java中的方法以小写字母开头; .NET中的方法以大写字母开头,因此当人们要求您使用Java代码作为伪代码并将Java转换为.NET时,您需要更改方法,例如 add() addCell()进入添加() AddCell()

  • 使用getter和setter更改和查询Java中的成员变量; .NET中的变量使用看起来像属性的方法进行更改和查询。这意味着您需要更改行,例如 cell.setBorder(border); border = cell.getBorder(); 进入 cell.Border = border border = cell.Border



iText和iTextSharp保持同步,这意味着,使用上面解释的两个规则,开发人员将iText代码转换为iTextSharp代码没有任何问题。 / p>

如果对某种方法有疑问,我可以像往常一样对Google进行这些方法和属性!您将找到以下示例:





如果你想要在一个地方的大量示例,下载 StackOverflow上的最佳iText问题


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'

解决方案

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

这篇关于如何格式化段落字符串以使用iTextsharp'vb显示pdf文档的左侧,右侧或中间内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆