Drawing Images in PDF

The drawImage method of drawing area is used to draw images. It takes the following arguments:

  • A string containing the URL of the image to draw
  • The x-coordinate of the point to draw the image at (optional)
  • The y-coordinate of the point to draw the image at (optional)
  • The image drawing options (optional)

For example:

doc.drawImage("resources/myImage1.png", 0, 30);

Like drawText method, it also updates the current text coordinates and uses them if arguments that determine the drawing coordinates are omitted, so any subsequent text or image will be placed below the current one.

The image drawing settings determine the size of the image and whether it should be scaled or stretched. By default, image will be rendered in its original size.

The following code draws an image at a specified position stretched to fit a rectangle of dimensions 100x25:

doc.drawImage("resources/myImage2.png", 0, 0, {
    height: 25,
    width: 100