在iTextSharp中创建PDF时,如何将图像设置为每页的背景?
我尝试了几种方法,每种方法只将图像放在一个页面上,或根本不起作用。
我不是在PDF中手动创建新页面,而是添加溢出到下一页的文本。
Dim document As Document = New Document()
Dim writer = PdfWriter.GetInstance(document, m)
Dim imagepath As String = context.Server.MapPath("img.png")
Dim image As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(imagepath)
writer.PageEvent = New pdfPageEvents(image)
.
.
.
Public Class pdfPageEvents
Inherits iTextSharp.text.pdf.PdfPageEventHelper
Dim image As iTextSharp.text.Image
Public Sub New(ByVal backgroundImage As iTextSharp.text.Image)
image = backgroundImage
End Sub
Public Overrides Sub OnStartPage(ByVal writer As PdfWriter, ByVal doc As Document)
writer.Add(image)
End Sub
End Class