我正在使用 iTextSharp 将来自微软报告查看器的多个 pdf 连接在一起。下面代码中的 page.AddImage(image__1) 抛出错误 Object reference not set to an object of an instance。我没有看到什么设置为空。有没有其他方法可以让我从报表查看器加入报表并添加水印图像?
mybytes = MSRptViewer1.LocalReport.Render("PDF", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
reader = New iTextSharp.text.pdf.PdfReader(mybytes)
numberOfPages = reader.NumberOfPages
currentPageNumber = 0
Dim imageFile As String = Server.MapPath("WaterMark.png")
Dim buffer As Byte() = IO.File.ReadAllBytes(imageFile)
Dim image__1 As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(buffer)
image__1.SetAbsolutePosition(100, 100)
Do While (currentPageNumber < numberOfPages)
currentPageNumber += 1
doc.SetPageSize(PageSize.LETTER)
doc.NewPage()
page = writer.GetImportedPage(reader, currentPageNumber)
page.AddImage(image__1)
rotation = reader.GetPageRotation(currentPageNumber)
If (rotation = 90) Or (rotation = 270) Then
cb.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, reader.GetPageSizeWithRotation(currentPageNumber).Height)
Else
cb.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, 0)
End If
Loop