是否可以为生成的PDF添加标题?

时间:2013-07-19 13:24:21

标签: asp.net vb.net pdf-generation itextsharp

我有一个图像我想用作我使用下面的代码生成的PDF的标题。是否有可能做到这一点?谢谢!

   Dim Doc1 As New Document
    Dim path As String = "" + Session("Username") + "\"
    If (Not System.IO.Directory.Exists(path)) Then

        System.IO.Directory.CreateDirectory(path)
    End If
    Dim myUniqueFileName = String.Format("{0}.pdf", random)
    Dim pdfWrite As PdfWriter = PdfWriter.GetInstance(Doc1, New FileStream(path & myUniqueFileName, FileMode.Create))
    Dim ev As New itsEvents
    pdfWrite.PageEvent = ev

    Doc1.Open()
    Dim test As String
    test = Session("PDF")
    Doc1.Add(New Paragraph(test))

    Doc1.Close()
End Sub
Public Class itsEvents
    Inherits PdfPageEventHelper
    Public Overrides Sub OnStartPage(ByVal writer As iTextSharp.text.pdf.PdfWriter, ByVal document As iTextSharp.text.Document)
        Dim ch As New Chunk("This is my header " & writer.PageNumber)
        document.Add(ch)
    End Sub
End Class

0 个答案:

没有答案