

You can choose to fit the image exactly, or choose a paper size, like Letter. There are several options that help you handle the most common cases. PDFKit takes the CGImageRef that you provide and compresses it using high-quality JPEG encoding.īecause CGImageRef is a native data type in CoreGraphics, additional conversions are unnecessary. Your app supplies images using CGImageRef.
Pdfkit swiftui pdf#
In iOS 16 and macOS Ventura, there's a new, flexible API that lets your app create PDF pages using images as inputs. Next, let's talk about a new API for creating PDF pages from images. You can tab through these text fields and enter text, just like you would expect. Documents that contain form fields are automatically recognized, even if they don't contain built-in text fields. In addition to live text, PDFKit has improved form handling.

OCR is done in place, so there's no need to make a copy of the document.Īnd, if you choose to save text for the whole document, there's an option to do so when saving. You wouldn't want to grind through OCR on all the pages of a PDF document when you open it, so PDFKit does it on demand, as you interact with each page, if you interact with it. It's just a scanned bitmap, with no text at all. Now, with Live Text, you can select and search text in a PDF document like this one. Unlike with photos, with a PDF, if you see text, it generally is text, and people expect it to behave as such without doing anything special. It's different than in Photos, where the text is often a small amount that you can tap to copy. Now, let's talk about new features introduced in iOS 16 and macOS Ventura. To learn more about the fundamentals of PDFKit, check out the great presentation "Introducing PDFKit" in the link below. Whereas the content of a PDFPage is not intended to be edited, annotations are interactive by nature and often editable.Įach of these objects will play a role in what I'll cover today. Pages render content and store resources like fonts and images that are unique to that page.Īt the leaves of our object graph are PDFAnnotations. You can't have a tree without one of these.Įach document contains one or more PDFPage objects. It's the root of the PDF object graph, or the trunk of the tree. It's not common to subclass PDFDocument, but you will always use one. It displays the content of a PDF document and lets people navigate, set zoom level, and copy text to the Pasteboard.

PDFView is the widget that you include in your layout using SwiftUI or Interface Builder. PDFKit consists of 4 core classes that cover most of the functionality you'll need in your app.
Pdfkit swiftui mac#
It's available on iOS, macOS, and Mac Catalyst, and it can also be used in SwiftUI by way of UIViewRepresentable, a wrapper that lets you integrate UI views into your app. PDFKit is a full-featured framework that helps your app view, edit, and write PDF files. Let's start with a quick refresher on how PDFKit works. First a quick review of PDFKit, and then, look at what's new, including Live text and forms, a new way to make PDF pages from images, and, finally, overlay views. (equalTo: ).isActive = trueįinally, create a URL pointing to a PDF you have in your bundle somewhere (or one in your documents directory), then create a PDFDocument object from that and pass it to the PDF view: guard let path = : I'm Conrad Carlen, and today, I'll be talking about what's new in PDFKit. anslatesAutoresizingMaskIntoConstraints = false
Pdfkit swiftui code#
Next, add this code to your viewDidLoad() method to create a PDFView and make it fill all available space: let pdfView = PDFView() To try it out, start by importing the PDFKit framework: import PDFKit Apple’s PDFKit framework provides a huge range of code to help us work with PDFs, and one of the most useful is PDFView – it renders PDFs to the screen and lets users interact with them.
