views:

240

answers:

1

the following is a generated PDF with a few images. how do i force the image to take up the entire width of the pdf file? alt text

+2  A: 

The ScalePercent method works pretty well for this.

    Dim pgSize As New iTextSharp.text.Rectangle(595, 792) //A4 width, Letter height
    Dim leftMargin as integer = 20
    Dim rightMargin as integer = 20
    Dim doc As New iTextSharp.text.Document(pgSize, leftMargin, rightMargin, 48, 24)
    //Create PDF and write other stuff.
    Dim img As System.Drawing.Image = My.Resources.My_Image
    Dim png As System.Drawing.Imaging.ImageFormat = System.Drawing.Imaging.ImageFormat.Png
    Dim pic1 As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(img, png)

    Dim scaleFactor As Single = (pgSize.Width - leftMargin - rightMargin) / img.Width * 100

    pic1.ScalePercent(scaleFactor)
    pic1.SetAbsolutePosition(my_X, my_Y)
    doc.Add(pic1)
Stewbob