![]() let squareAnnotation = PDFAnnotation(bounds: CGRect(x: 200, y: 100, width: 100, height: 100), forType: PDFAnnotationSubtype.square, withProperties: nil) But you can leverage the PDFKit framework to view PDF documents in your apps: The traditional approach for viewing a PDF is to open it in a web view. Apart from these basic keys, there are other keys that can be used to create the metadata for a PDF. Since the annotated Core Foundation APIs are automatically memory-managed in Swift, you don’t have to be concerned with the manual retaining and releasing of objects here. ![]() Closes the current PDF context and ends writing to the file. Let stringRect = CGRect(x: (pageSize.width / 2 - stringSize.width / 2), y: 20, width: stringSize.width, height: stringSize.height) Let stringSize = attributedPDFTitle.size() let attributedPDFTitle = NSAttributedString(string: pdfTitle, attributes: ) Let's draw the title of the PDF on top of the page. Let font = UIFont.preferredFont(forTextStyle. let pageSize = UIGraphicsGetPDFContextBounds().size Creates a new page in the current PDF context. UIGraphicsBeginPDFContextToFile(filePath, CGRect.zero, pdfMetadata) Creates a new PDF file at the specified path. KCGPDFContextOwnerPassword: "myPassword123" Used to enable/disable different permissions. Encrypts the document with the value as the owner password. The name of the application creating the PDF. Let filePath = (documentsDirectory as NSString).appendingPathComponent( "foo.pdf") as String let pdfTitle = "Swift-Generated PDF" let pdfMetadata = [ Let documentsDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory. It’s important to note that PDFKit doesn’t allow creating a PDF, and as such, Core Graphics needs to be used: There’s a set of auxiliary dictionary keys that are part of the PDF, and these keys are used to specify the metadata for the PDF. ![]() The metadata information for a PDF has to be set while generating the PDF context for its creation. ![]() Lastly, you’ll find out how to add annotations and write changes to the PDF. Then, you’ll learn how you can display a PDF with PDFKit. First, you’ll see how to work with Core Graphics to create a PDF. In this tutorial, you’ll learn how to use the basics of PDFKit to configure and modify a PDF document. One such way is with the PDFKit framework from Apple, which has been available since iOS 11 and allows for configuring the metadata of a PDF document and customizing the PDF by adding widgets and annotations. In the past, we talked about the different ways to create a PDF on iOS. PDF is one of the most popular file formats in the world, and viewing PDF files is supported on almost all devices and operating systems out of the box. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |