

Let renderer = UIGraphicsPDFRenderer(bounds:pageRect, format: format)

1 2 3 let pdfView PDFView(frame: ) toresizingMask. Then, we will create an object of PDFView and we will add this view inside the super view. Let pageRect = CGRect(x:0, y:0, width: 500, height: 600) In your SwiftUI project integrated with Apryse iOS, create a new SwiftUI View file (Command+N -> Select 'SwiftUI View') named DocumentView.swift and import the PDFNet and Tools modules at the top of the Swift file, below the existing SwiftUI import: import SwiftUI import PDFNet import Tools. Choose the iOS Application Single View App template and create a new project. Let format = UIGraphicsPDFRendererFormat()įormat.documentInfo = pdfMetaData as To instantiate it, you need to specify its bounds and an optional parameter for its format, as follows: let pdfMetaData = [kCGPDFContextCreator: "My First PDF File",
#Ios pdfkit pdfview add as subview how to#
we describe how to add a PDF viewer to your iOS app using Swift with PDFKit.

To create PDF file with the PDFKit, all you need is instantiate the key class UIGraphicsPDFRenderer in PDFKit framework. In this file, Ive added the following code: import SwiftUI import PDFKit. This is especially useful for apps that need to generate receipts, bills, invoices or any other confidential or important documents. You can do something like this: //configure the pdfView or use it from an outlet in Storyboard let pdfView PDFView (frame: ) let url (forResource: 'pdfFile', withExtension: 'pdf') pdfView.document PDFDocument (url: url) //the important setting pdfView.displayDirection. PDF is useful so we can generate files that cannot be modified and shared or sent to others. PDFKit is the framework by Apple that you need to display and manipulate PDF files in your app. I added a PDFView as a subview, and a UIBarButtonItem to the navigationItem, that serves to toggle annotation mode.
