开发者

itextsharp: how do i place an image all the way at the bottom?

i have an image that i just want 开发者_如何学JAVAto place all the way at the bottom of the page. how do i do this?


    'Set these as needed
    Dim DocumentWidth = 1000
    Dim DocumentHeight = 1000
    Dim ImagePath = "c:\test.jpg"

    Dim ImageWidth As Integer
    Dim ImageHeight As Integer
    Using Img = System.Drawing.Image.FromFile(ImagePath)
        ImageWidth = Img.Width
        ImageHeight = Img.Height
    End Using

    'Create the document
    Dim D As New Document()
    'Set the page size
    D.SetPageSize(New iTextSharp.text.Rectangle(0, 0, DocumentWidth, DocumentHeight))
    'Zero the margins
    D.SetMargins(0, 0, 0, 0)
    'Create and open the PDF writer
    Dim W = PdfWriter.GetInstance(D, New System.IO.FileStream("C:\test.pdf", IO.FileMode.Create, IO.FileAccess.Write, IO.FileShare.Read))
    D.Open()

    'Make a new image object
    Dim I As New iTextSharp.text.Jpeg(New Uri("file:///" & ImagePath))
    'Lower left is (0,0), upper right is (1000,1000)
    I.SetAbsolutePosition(DocumentWidth - ImageWidth, 0)
    'Add the image
    D.Add(I)
    D.Close()


place it at the top of the page upside down, and flip the page.

edit: sorry, i was half kidding. there's an example here of positioning an image using the Image.setAbsolutePosition method. You should be able to calculate the parameters to supply to this function based on the size of the image and the size of the document you're working with.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜