

Drawing an image on a PDF is very similar to drawing it in the context of a view: Only the underlying CGImage object of the image you want to draw is required, and this can easily be accessed by the cgImage property on a UIImage object. Hence, we will have to manipulate the context in order to match it to the UIKit coordinate system.

One particular detail we should keep in mind is that the origin for the coordinate system of a PDF starts at the bottom left corner. All the drawing had to be done by accessing the context of the page. Using Core Graphicsīefore the introduction of PDFKit, Core Graphics was the only way to create and modify PDFs on iOS. One is by using Core Graphics, and the other is by using PDFKit. There are a couple ways to draw an image in a PDF using the available frameworks on iOS. As an example, you might need to add an image to a PDF as part of its original content as opposed to later adding it as an annotation.

You can take an existing image and insert it into a PDF in the form of an annotation, or you can make it a part of the PDF content by drawing it. The PDF format allows you to draw and render any type of content you want.
