Pergunta

Eu tenho uma imagem que eu só quero colocar até o final da página. Como eu faço isso?

Foi útil?

Solução

    '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()

Outras dicas

Coloque -o na parte superior da página de cabeça para baixo e vire a página.

EDIT: Desculpe, eu estava meio brincando. Há um exemplo aqui de posicionar uma imagem usando o método da imagem.SetabSolutePosition. Você poderá calcular os parâmetros para fornecer a essa função com base no tamanho da imagem e no tamanho do documento com o qual você está trabalhando.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top