itextsharp:强制图像占用vb.net中的整个宽度

时间:2009-12-14 22:58:48

标签: vb.net pdf itextsharp

以下是生成的PDF图片。如何强制图像占据pdf文件的整个宽度? alt text http://img52.imageshack.us/img52/3324/fullscreencapture121420u.png

1 个答案:

答案 0 :(得分:4)

ScalePercent方法适用于此。

    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)