0

如果可能,请在 vb.net 中

4

2 回答 2

4

您可以创建一个Rectangle对象并设置其BackgroundColor属性。使用你Rectangle来初始化你的Document.

SourceForge 上的 iTextSharp 站点上的本教程对此进行了描述(请参阅 PageSize 部分)。

同一个站点有一个代码示例,演示了您需要做什么。(参见“步骤 1”)。该示例使用 C# 编写,我知道您希望它使用 VB.NET,因此我通过developerfusion 站点上的C# 到 VB.NET 转换器运行它。我无法从我现在不是的机器上测试编译结果,但代码看起来很合理:

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

试试看。

于 2009-12-18T06:56:49.873 回答
1

color命名空间中不存在,错误在您的代码中:

pageSize.BackgroundColor = New **Color**(&Hff, &Hff, &Hde) 
于 2010-07-18T06:29:41.810 回答