答案 0 :(得分:4)
您可以创建Rectangle
对象并设置其BackgroundColor
属性。使用Rectangle
初始化Document
。
This tutorial描述了这一点(参见PageSize部分)。
同一网站有一个code sample,可以展示您需要做什么。 (见'第1步')。样本在C#中,我知道你想在VB.NET中使用它,所以我通过developerfusion网站上的C# to VB.NET converter运行它。我无法测试编译机器的结果我现在不是,但代码看起来很合理:
Imports System
Imports System.IO
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Public Class Chap0102
Public Shared Sub Main()
Console.WriteLine("Chapter 1 example 2: PageSize")
' step 1: creation of a document-object
Dim pageSize As New Rectangle(144, 720)
pageSize.BackgroundColor = New Color(&Hff, &Hff, &Hde)
Dim document As New Document(pageSize)
Try
' step 2:
' we create a writer that listens to the document
' and directs a PDF-stream to a file
PdfWriter.getInstance(document, New FileStream("Chap0102.pdf", FileMode.Create))
' step 3: we open the document
document.Open()
' step 4: we Add some paragraphs to the document
For i As Integer = 0 To 4
document.Add(New Paragraph("Hello World"))
Next
Catch de As DocumentException
Console.[Error].WriteLine(de.Message)
Catch ioe As IOException
Console.[Error].WriteLine(ioe.Message)
End Try
' step 5: we close the document
document.Close()
End Sub
End Class
试一试。
答案 1 :(得分:1)
color
,错误在您的代码中:
pageSize.BackgroundColor = New **Color**(&Hff, &Hff, &Hde)
答案 2 :(得分:0)
pageSize.BackgroundColor.BackgroundColor = BaseColor.WHITE