言語を指定していないので、VB.Netで回答しますが、必要に応じて簡単にC#に変換できます。あなたの最初の質問に
、ちょうど適切なUnicodeコードポイントU+00A0
を使用する改行なしスペースを使用する:
はVB.Netで
あなたはそれが好きで宣言したい:
Dim NBSP As Char = ChrW(&HA0)
そして、C#での:必要な場所
Char NBSP = '\u00a0';
は、その後、あなたはそれを連結することができます
Dim Text2 As String = "This is" & NBSP & "also" & NBSP & "a test"
non-breaking hyphen (U+2011)も参考になる場合があります。
2番目の質問には、はいすべての列の幅を設定できます。あなたが使用している場合のでしかし、列幅は常に相対的な幅として設定されています。
T.SetTotalWidth(New Single() {2.0F, 1.0F})
あなたが実際にあなたが、特定のテーブルのために、最初の列が二列の2倍の大きさでなければならないことであると言っていますかNOT最初の列は2ピクセル幅で、2列目は1ピクセルです。これは理解することが非常に重要です。上記のコードは次の2行とまったく同じである。
T.SetTotalWidth(New Single() {4.0F, 2.0F})
T.SetTotalWidth(New Single() {100.0F, 50.0F})
列幅は、(私が正しく覚えている場合)は、デフォルトで書き込み可能なページの幅の80%であり、表の幅に対するものです。あなたは絶対的な幅にテーブルの幅を修正したい場合は、二つのプロパティを設定する必要があります。
Option Explicit On
Option Strict On
Imports System.IO
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
''//File that we will create
Dim OutputFile As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "TableTest.pdf")
''//Standard PDF init
Using FS As New FileStream(OutputFile, FileMode.Create, FileAccess.Write, FileShare.None)
Using Doc As New Document(PageSize.LETTER)
Using writer = PdfWriter.GetInstance(Doc, FS)
Doc.Open()
''//Create our table with two columns
Dim T As New PdfPTable(2)
''//Set the relative widths of each column
T.SetTotalWidth(New Single() {2.0F, 1.0F})
''//Set the table width
T.TotalWidth = 200.0F
''//Lock the table from trying to expand
T.LockedWidth = True
''//Our non-breaking space character
Dim NBSP As Char = ChrW(&HA0)
''//Normal string
Dim Text1 As String = "This is a test"
''//String with some non-breaking spaces
Dim Text2 As String = "This is" & NBSP & "also" & NBSP & "a test"
''//Add the text to the table
T.AddCell(Text1)
T.AddCell(Text2)
''//Add the table to the document
Doc.Add(T)
Doc.Close()
End Using
End Using
End Using
Me.Close()
End Sub
End Class
:すべて一緒に上記を置く
''//Set the width
T.TotalWidth = 200.0F
''//Lock it from trying to expand
T.LockedWidth = True
を、以下のiTextSharp 5.1.1.0を標的に完全な作業のWinFormsアプリです
お返事ありがとうございます。私が使用している言語はC#でした。コードをよく見て、何をすべきかを理解することができます。再度、感謝します。 – Vinay
Char NBSP = '\ u00A0'; iTextSharpで私のために 'Â'を表示します。それはatmのための修正を見つけることができません。 – James
実際、これはユニコードエンコードを使用していなかったためと思われます。しかし、エンコードをUTF-8に変更しました。私の と が今働いています。とにかく+1。 – James