Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports SelectPdf

Namespace SelectPdf.Samples
    Partial Public Class pdf_image_element
        Inherits System.Web.UI.Page

        Protected Sub BtnCreatePdf_Click(sender As Object, e As EventArgs)
            ' create a new pdf document
            Dim doc As New PdfDocument()

            ' add a new page to the document
            Dim page As PdfPage = doc.AddPage()

            ' get image path
            Dim imgFile As String = Server.MapPath("~/files/logo.png")

            ' define a rendering result object
            Dim result As PdfRenderingResult

            ' create image element from file path with real image size
            Dim img1 As New PdfImageElement(0, 0, imgFile)
            result = page.Add(img1)

            ' create image element from system Image object with fixed size in pdf 
            ' (aspect ratio not preserved)
            Dim img As System.Drawing.Image = System.Drawing.Image.FromFile(imgFile)
            Dim img2 As New PdfImageElement(0, result.PdfPageLastRectangle.Bottom + 50, _
                                            100, 100, img)
            result = page.Add(img2)

            ' add text element
            Dim font1 As PdfFont = doc.AddFont(PdfStandardFont.Helvetica)
            font1.Size = 10
            Dim text1 As New PdfTextElement(0, result.PdfPageLastRectangle.Bottom + 50, _
                                            Helper.SomeText(), font1)
            page.Add(text1)

            ' add image over text (no transparency)
            Dim img3 As New PdfImageElement(0, result.PdfPageLastRectangle.Bottom + 50, imgFile)
            result = page.Add(img3)

            ' add image over text (with transparency) next to the previous image
            Dim img4 As New PdfImageElement(result.PdfPageLastRectangle.Right + 30, _
                                            result.PdfPageLastRectangle.Top, imgFile)
            img4.Transparency = 50
            result = page.Add(img4)

            ' save pdf document
            doc.Save(Response, False, "Sample.pdf")

            ' close pdf document
            doc.Close()
        End Sub
    End Class
End Namespace
