Images in PDFKit
Adding images to PDFKit documents is an easy task. Just pass an image path to the image
method along with some optional
arguments. PDFKit supports the JPEG and PNG formats. If an X and Y position are not provided, the image is rendered at the
current point in the text flow (below the last line of text). Otherwise, it is positioned absolutely at the specified point.
The image will be scaled according to the following options.
- Neither
width
orheight
provided - image is rendered at full size width
provided but notheight
- image is scaled proportionally to fit in the providedwidth
height
provided but notwidth
- image is scaled proportionally to fit in the providedheight
- Both
width
andheight
provided - image is stretched to the dimensions provided scale
factor provided - image is scaled proportionally by the provided scale factorfit
array provided - image is scaled proportionally to fit within the passed width and height
Here is an example showing some of these options.
This example produces the following output:

That is all there is to adding images to your PDF documents with PDFKit. Now let's look at adding annotations.