DrawImage

Draw an image for the given width and height at the specifiy location.

DrawImage(ImageName As String, x As Single, y As Single, ImageWidth As Single, ImageHeight As Single)

Values passed to this procedure:

ImageNameThe internal name of the image to be drawn. The internal name is assigned to the image when it's loaded into the document using LoadImageFile.
x, yx, y coordinates on the page to draw the image.
ImageWidthThe display width of the image.
ImageHeightThe display height of the image.

Example

Dim imageInfo As ImageInformation

Dim reSizeImage As pdfImageSize
Dim MaxImageSize As pdfImageSize    'Used to set the maximum size that an image will be displayed at.

Dim cPDF As New vbPDF

'In order to display an image, vbPDF needs to know some information on that image. This is stored in the 'imageInformation structure. ImageInfo is an array of imageInformation declared above and is populated by 'calling the GetImageFileInfo.
imageInfo = GetImageFileInfo("c:\flag.jpg")
If LCase(imageInfo.Extension) <> ".jpg" Then
  'Not jpeg format. Need to convert it.
  If Not ReCreateImage(imageInfo.FullFileName, "c:\newFlag.jpg", imageInfo.HorizontalResolution) Then
    imageInfo.ValidImage = False
  End If
  If imageInfo.ValidImage Then
    'Since a new image has been created, we need to reload the image information.
    imageInfo = GetImageFileInfo(strTemp)
  End If
End If

If imageInfo.ValidImage Then
  'vbPDF can not displayed Format8bppIndexed jpeg images. If an image is Format8bppIndexed, you should use
  'the ReCreateImage procedure to change it before loading it.

  If imageInfo.PixelFormat = "Format8bppIndexed" Then
    If Not ReCreateImage(imageInfo.FullFileName, "c:\newFlag.jpg", imageInfo.HorizontalResolution) Then
      imageInfo.ValidImage = False
    End If
    If imageInfo.ValidImage Then
      'Since a new image has been created, we need to reload the image information.
      imageInfo = GetImageFileInfo("c:\newFlag.jpg")
    End If
  End If

  If imageInfo.ValidImage Then
    'The PDFName is the internal name used by pdf to reference the image with in the pdf document.
    'Each image must have a unique name. The name can be anything, but should not contain a space.

    imageInfo.PDFName = "flag"
  End If
End If

With cPDF
  .ReportFileName = "c:\Images.pdf"
  .ScaleMode = pdf.ScaleMode.Inch

  'The image will be resized to fit the page, with a 1/2 inch border.
  MaxImageSize = New pdfImageSize(.PageWidthInInch - 0.5, .PageHeightInInch - 0.5)

  If Not .CreatePDFFile() Then
    Exit Sub
  End If

  'An image must be loaded prior to the page it will be displayed on is created.
  If imageInfo.ValidImage Then
    imageInfo.ValidImage = LoadImageFile(imageInfo.FullFileName, imageInfo.ImageSize.Width,
                                         imageInfo.ImageSize.Height, imageInfo.Length, imageInfo.PDFName)
  End If

  .StartPage()

  If imageInfo(i).ValidImage Then
    'ScalePDFImageSize takes in the actual image size and returns a new size that will maintan the image
    'aspect ratio.

    reSizeImage = ScalePDFImageSize(imageInfo(i).ImageSize, MaxImageSize)

    .DrawImage(imageInfo(i).PDFName, .PageWidthInInch / 2 - reSizeImage.Width / 2, .PageHeightInInch / 2 +
               reSizeImage.Height / 2, reSizeImage.Width, reSizeImage.Height)
  End If

  .EndPage()

  .ClosePDFFile()
End With