2

这是我的代码

 Dim doc As iTextSharp.text.Document = New iTextSharp.text.Document()
 Dim path As String = Request.MapPath("Sample PDFs") & "\Sample.tif"
PdfWriter.GetInstance(doc, New FileStream(Request.PhysicalApplicationPath + _
                                 "render\1.pdf", FileMode.Create))

Dim data As clsData = New clsData(GetConnection, enumEgswFetchType.DataTable)
 Dim int As Integer = data.GetPageCount(path)
doc.Open()

For ctr As Integer = 0 To int - 1
 Dim img As iTextSharp.text.Image
Dim image As New System.Web.UI.WebControls.Image
image.ImageUrl = "ctrls/ViewTif.aspx?path=" + path.ToString + "&page=" + ctr.ToString

img = iTextSharp.text.Image.GetInstance(image, System.Web.UI.WebControls.Image)

doc.Add(image)
Next

doc.Close()
Response.Redirect("~/1.pdf")

有什么方法可以将 webcontrol 图像添加到 itext 中?image 变量是一个动态图像,其源页面从 tif 文件返回 jpeg 图像。或者有什么办法可以直接将 tif 以 pdf 格式放入 itext?

4

1 回答 1

0

有需要使用的理由System.Web.UI.WebControls.Image吗?iTextSharp.text.Image.GetInstance()接受 URL的重载之一:

Dim TestFile = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.pdf")
Using FS As New FileStream(TestFile, FileMode.Create, FileAccess.Write, FileShare.None)
    Using Doc As New Document()
        Using Writer = PdfWriter.GetInstance(Doc, FS)
            Doc.Open()

            Doc.Add(New Paragraph("Hello World"))

            ''//Get the image from a URL
            Dim Img = iTextSharp.text.Image.GetInstance("http://www.google.com/images/srpr/logo4w.png")
            ''//Optionally adjust it
            Img.ScaleAbsolute(100, 200)
            ''//Add it to the document
            Doc.Add(Img)

            Doc.Close()
        End Using
    End Using
End Using
于 2013-07-10T13:30:27.960 回答