2009-12-18 143 views

回答

4

您可以創建一個Rectangle對象並設置它的BackgroundColor屬性。用你的Rectangle初始化Document

This tutorial在SourceForge上的iTextSharp站點上對此進行了描述(請參閱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

color不存在命名空間和錯誤是在你的代碼:

pageSize.BackgroundColor = New **Color**(&Hff, &Hff, &Hde)