【问题标题】:Convert WebControl Image to iText.text.image将 WebControl 图像转换为 iText.text.image
【发布时间】:2013-07-06 14:26:45
【问题描述】:

这是我的代码

 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 中?

【问题讨论】:

  • 请解释什么不起作用
  • 它不是在创建图像

标签: asp.net vb.net pdf itextsharp tiff


【解决方案1】:

您是否有理由需要使用System.Web.UI.WebControls.ImageiTextSharp.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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-29
    • 1970-01-01
    • 1970-01-01
    • 2021-12-17
    • 2015-12-31
    • 2011-02-01
    • 2012-12-04
    • 1970-01-01
    相关资源
    最近更新 更多