[RESOLVED] Image size proble when create pdf using itextsharp dll

thanks in advance

i am  creating pdf using itextsharp dll, but image is not display a proper size in pdf.my code is below


  '*******************************set Images

        Dim gif As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Images/Img1.jpg"))
        gif.ScaleToFit(334.0F, 265.0F)
        Dim gif1 As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Images/Img2.jpg"))

        Dim gif2 As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Images/Img3.jpg"))
        Dim gif3 As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Images/Img4.jpg"))
        Dim gif4 As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Images/Img5.jpg"))
        Dim logo As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Images/Logo.gif"))

        Dim g As Image = Image.GetInstance(Server.MapPath("~/Images/Img1.jpg"))


        Dim doc As Document = New Document
        PdfWriter.GetInstance(doc, New FileStream(Request.PhysicalApplicationPath + "\2.pdf", FileMode.Create))
        Dim table As Table = New Table(3)
        table.BorderWidth = 1
        table.Width = 50
        table.BorderColor = New Color(0, 0, 255)

        table.Padding = 3
        table.Spacing = 1
        ' Dim cell As Cell = New Cell("header")
        Dim cell As Cell = New Cell(logo)
        cell.Header = True
        cell.Colspan = 3

        ' cell = New Cell("example cell with colspan 1 and rowspan 2")
        cell = New Cell(g) '*******************************************************************
        cell.Width = 334
        cell.Header = 265
        cell.Rowspan = 2
        cell.BorderColor = New Color(255, 0, 0)

        Dim cell1_1 As Cell = New Cell(gif1)

        Dim cell2_1 As Cell = New Cell(gif2)

        Dim cell1_2 As Cell = New Cell(gif3)

        Dim cell2_2 As Cell = New Cell(gif4)

        table.AddCell("cell test1")
        cell = New Cell("big cell")
        cell.Rowspan = 2
        cell.Colspan = 2
        cell.HorizontalAlignment = Element.ALIGN_CENTER
        cell.VerticalAlignment = Element.ALIGN_MIDDLE
        cell.BackgroundColor = New Color(192, 192, 192)
        table.AddCell("cell test2")


Hi himanshu_jadav54Member,

You can try to put the image inside a Chunk and scaling will work.

And use chartImg.SetAbsolutePosition(50, 50); to layout the position.

It is better that you design the image sieze before you use it in the pdf file.

Please check the following link:



thoughts on "[RESOLVED] Image size proble when create pdf using itextsharp dll"

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>