### Illustrate SDK Usage in iOS Playground (Swift) Source: https://www.nutrient.io/guides/ios/samples/playground This Swift code sample demonstrates how to use the PSPDFKit SDK within an iOS Playground. It serves as a basic example that developers can adapt for their specific integration needs. ```swift import PSPDFKit // This is a placeholder for the actual SDK usage code. // In a real scenario, you would initialize and use PSPDFKit components here. // Example: Initializing a PDF document // let document = PSPDFDocument(url: Bundle.main.url(forResource: "example", withExtension: "pdf")) // Example: Presenting a PDF view controller // let controller = PSPDFViewController(document: document) // self.present(controller, animated: true, completion: nil) print("PSPDFKit SDK usage example loaded.") ``` -------------------------------- ### Set Up PSPDFKit as an E-Reader in iOS Source: https://www.nutrient.io/guides/ios/samples Learn how to set up PSPDFKit as an e-reader using a Swift example. This guide provides resources for building an e-reader app. ```Swift // Example setup for e-reader let pdfViewController = PSPDFViewController() // Configure PDFViewController for reading experience // e.g., disable editing, enable page navigation ``` -------------------------------- ### Use Instant JSON to Collaborate on PDFs in iOS Source: https://www.nutrient.io/guides/ios/samples A collection of examples showing how to use the Instant JSON data exchange format for PDF collaboration. Get additional resources from the Instant JSON guide. ```Swift // Example of saving annotations as Instant JSON let annotationProvider = PSPDFInstantJSONAnnotationProvider() let jsonString = annotationProvider.saveAnnotationsToJSON(pdfViewController.document.annotations) // Send jsonString to collaborate ``` -------------------------------- ### Create Bookmarks UI in iOS Source: https://www.nutrient.io/guides/ios/samples Learn to build a user interface for creating named bookmarks in iOS. This guide provides a Swift code example for bookmark implementation. ```swift // Example code for building a bookmark creation UI would go here. ``` -------------------------------- ### Sound Annotation Options (Swift) Source: https://www.nutrient.io/guides/ios/migration-guides/pspdfkit-9-3-migration-guide Example of setting sample rate and bits per sample for sound recording options. ```swift .sampleRate(hertz: SoundAnnotation.RecorderOption.SampleRate) .bitsPerSample(SoundAnnotation.RecorderOption.Depth) ``` -------------------------------- ### Set up PSPDFKit as an E-Reader in Swift Source: https://www.nutrient.io/guides/ios/samples Learn how to set up PSPDFKit as an e-reader with a Swift example. Explore more resources in our blog article on building an e-reader app. ```swift // Example code for setting up PSPDFKit as an e-reader in Swift // This snippet demonstrates the core functionality for building an e-reader app. // Explore blog articles for additional resources. ``` -------------------------------- ### PDF Streaming (Swift) Source: https://www.nutrient.io/guides/ios/samples Learn efficient document loading by accessing parts on demand using Swift. This guide provides code samples and practical examples for streaming documents and views in your iOS app. ```swift /* This example demonstrates PDF streaming (loading document parts on demand) using Swift with PSPDFKit. It focuses on optimizing performance for large documents by loading content lazily. Key concepts involve configuring the PSPDFViewController or PSPDFDocument for efficient memory usage. This approach is essential for a smooth user experience with large files. */ import PSPDFKit // Assuming you have a PSPDFViewController instance // To enable or configure PDF streaming, you can modify PSPDFConfiguration. // PSPDFKit often handles basic streaming optimizations by default. // Example of setting a lazy page loading strategy: let document = PSPDFDocument(url: /* URL to your PDF file */) let configuration = PSPDFConfiguration { // .lazy: Loads pages only when they are about to be displayed. // .aggressive: Loads surrounding pages proactively. // .demand: Loads pages only when explicitly requested. $0.pageLoadingStrategy = .lazy $0.enableAnnotationFlattening = true // Example of another configuration } let pdfViewController = PSPDFViewController(document: document!, configuration: configuration) // The PSPDFViewController will now attempt to load pages lazily, improving performance. print("PDF streaming configured with lazy page loading.") ``` -------------------------------- ### Customize Sharing View with Delegation in SwiftUI Source: https://www.nutrient.io/guides/ios/samples Tailor PSPDFKit components in SwiftUI using the delegation pattern. This guide offers practical insights and implementation tips with a code example. ```swift // This is a placeholder for the actual code snippet // In a real scenario, this would contain Swift code demonstrating delegation for sharing. // Example: /* class MySharingDelegate: PSPDFSharingDelegate { func sharingController(_ controller: PSPDFSharingController, didCompleteWithResult result: PSPDFSharingResult) { print("Sharing completed with result: \(result)") } } */ ``` -------------------------------- ### Build Bookmark Creation UI in Swift for iOS Source: https://www.nutrient.io/guides/ios/samples Develop a user interface for creating named bookmarks in your iOS application. This guide includes a Swift code example and resources for bookmark implementation. ```swift // Example code for bookmark creation UI in Swift // (Actual code would involve UI elements for bookmark naming and saving) ``` -------------------------------- ### PDF Streaming with SwiftUI Source: https://www.nutrient.io/guides/ios/samples Explore how to load document parts on demand in SwiftUI with PSPDFKit, including example code. ```swiftui // Example code for PDF streaming with SwiftUI (details not provided). ``` -------------------------------- ### Customize Link Annotation View in iOS Source: https://www.nutrient.io/guides/ios/samples Discover how to customize link annotations in iOS with PSPDFKit. Access comprehensive API guides and explore code examples for implementation. ```Swift let linkAnnotation = PSPDFLinkAnnotation() linkAnnotation.color = .blue linkAnnotation.underlined = true ``` -------------------------------- ### Customize PDF Sharing Options in iOS Source: https://www.nutrient.io/guides/ios/samples Learn how to customize document sharing options in iOS. This guide includes a Swift code example to enhance your app's sharing capabilities. ```swift // Example code for customizing PDF sharing options would go here. ``` -------------------------------- ### Add Video, Audio, Image Annotation to PDF in iOS Source: https://www.nutrient.io/guides/ios/samples Explore multimedia gallery examples featuring videos, images, and audio. Access additional resources in the iOS PDF annotations library. ```Swift // Example for adding an image annotation let imageAnnotation = PSPDFImageAnnotation() imageAnnotation.bounds = CGRect(x: 50, y: 50, width: 100, height: 100) imageAnnotation.image = UIImage(named: "my_image") // Add to PDF page ``` -------------------------------- ### PDF Streaming with SwiftUI (Swift) Source: https://www.nutrient.io/guides/ios/samples Explore loading document parts on demand in SwiftUI using PSPDFKit. This comprehensive example and source code guide are perfect for optimizing your app's performance by reducing memory usage. ```swift /* This example demonstrates PDF streaming (loading document parts on demand) in SwiftUI using PSPDFKit. It requires PSPDFKit and basic SwiftUI knowledge. The goal is to improve performance by loading only necessary parts of the PDF. This approach is particularly useful for large documents. */ import SwiftUI import PSPDFKit import PSPDFKitUI struct PDFStreamerView: View { // Use PSPDFKit's DocumentReference for managing the document lifecycle @StateObject private var documentRef = PSPDFDocumentReference(url: /* URL to your PDF file */) var body: some View { if let document = documentRef.document { // PSPDFView is a SwiftUI view wrapper for PSPDFViewController PSPDFView(document: document) .edgesIgnoringSafeArea(.all) } else { ProgressView("Loading PDF...") } } } // To enable streaming, PSPDFKit typically handles this automatically when using // PSPDFView or PSPDFViewController with large documents. You can also configure // specific caching and loading strategies via PSPDFConfiguration. // Example of configuring PSPDFConfiguration for streaming (if needed): // let configuration = PSPDFConfiguration { // $0.pageLoadingStrategy = .lazy // } // let pdfViewController = PSPDFViewController(document: document, configuration: configuration) // In SwiftUI with PSPDFView, default configurations often include optimizations. ``` -------------------------------- ### Implement Custom PDF Bookmark Provider in iOS using Plist Source: https://www.nutrient.io/guides/ios/samples Learn to implement a custom bookmark provider in iOS using a plist file. This guide offers Swift code examples and additional resources for bookmark management. ```swift // Example code for implementing a custom PDF bookmark provider using a plist // (Actual code would involve reading bookmark data from a plist file) ``` -------------------------------- ### Customize PDF Sharing Options in iOS with Swift Source: https://www.nutrient.io/guides/ios/samples Learn how to tailor the document sharing options within your iOS application. This guide includes a Swift code example to enhance your app's sharing capabilities. ```swift // Example code for customizing PDF sharing options // (Actual code would involve configuring UIActivityViewController or similar) ``` -------------------------------- ### Modify PDF Document Data with PSPDFKit iOS Source: https://www.nutrient.io/guides/ios/migration-guides/pspdfkit-9-migration-guide This example shows how to retrieve the data of a PDF document using PSPDFKit's `PSPDFProcessor`. It demonstrates the updated method `dataWithError:` which is the preferred way to get PDF data, including error handling. ```Objective-C PSPDFProcessor *processor = [[PSPDFProcessor alloc] init]; // Assume processor is configured with a PDF document NSError *error; NSData *pdfData = [processor dataWithError:&error]; if (error) { NSLog(@"Error getting PDF data: %@", error); } else { NSLog(@"Successfully retrieved PDF data: %lu bytes", (unsigned long)pdfData.length); } ``` -------------------------------- ### Use Custom PDF Bookmark Provider in iOS Source: https://www.nutrient.io/guides/ios/samples Learn to implement a custom bookmark provider in iOS using a plist file. This guide offers additional resources and code examples for bookmark management. ```swift // Example code for a custom PDF bookmark provider would go here. ``` -------------------------------- ### Disable Bookmark Editing in Swift Source: https://www.nutrient.io/guides/ios/samples Learn how to disable bookmark editing in PDFs with a Swift example. Explore more on document features in comprehensive guides. ```swift // Example code for disabling bookmark editing in PDFs using Swift // This snippet shows how to prevent users from editing bookmarks. // The guide offers more information on document features. ``` -------------------------------- ### Highlight Text in PDF Similar to Apple Books in iOS Source: https://www.nutrient.io/guides/ios/samples Learn to replicate Apple Books' text highlighting in iOS. This guide covers programmatically creating PDF annotations and provides Swift examples. ```Swift // Example of programmatic text highlighting let textAnnotation = PSPDFTextAnnotation() textAnnotation.textRanges = [PSPDFTextRange(start: 5, end: 10)] // Example text range ``` -------------------------------- ### SwiftUI Document Browser for Opening and Creating PDFs Source: https://www.nutrient.io/guides/ios/getting-started/example-projects Demonstrates how to implement a document browser in SwiftUI for opening and creating PDF documents using the Nutrient library. This example showcases modern UI development with SwiftUI. ```Swift /* This code snippet is a placeholder. Actual code for SwiftUI Document Browser would be included here. Example functionalities include: - Displaying a list of PDF documents. - Allowing users to create new PDF documents. - Handling document selection and opening. - Integrating with file management services. */ // Placeholder for SwiftUI Document Browser // import SwiftUI // import Nutrient // // struct DocumentBrowserView: View { // @State private var documents: [URL] = [] // // var body: some View { // NavigationView { // List(documents, id: \.self) { // Text($0.lastPathComponent) // } // .navigationTitle("PDF Documents") // } // } // } // // // Additional code for document creation and opening logic would be here. ``` -------------------------------- ### Create Password-Protected PDF in iOS Source: https://www.nutrient.io/guides/ios/samples This guide demonstrates how to create password-protected PDF documents in iOS. It includes a Swift code example for secure PDF generation. ```swift import UIKit import PSPDFKit func createSecurePDF() { // Create a new PDF document let document = PSPDFDocument(url: URL(fileURLWithPath: "/path/to/new_secure.pdf")) // Set a password document.password = "mySecretPassword" // Add content to the PDF (e.g., a blank page) document.addPage(withSize: .USLetter, contents: nil) // Save the document do { try document.save(password: "mySecretPassword") print("Secure PDF created successfully.") } catch { print("Error creating secure PDF: \(error)") } } ``` -------------------------------- ### Initialize ComparisonProcessor Source: https://www.nutrient.io/guides/ios/compare-documents Demonstrates the initialization of the ComparisonProcessor with a ComparisonConfiguration object. ```swift let processor = ComparisonProcessor() let configuration = ComparisonConfiguration( oldDocumentStrokeColor: .red, newDocumentStrokeColor: .blue ) processor.configuration = configuration ``` -------------------------------- ### Nutrient Catalog: Multimedia Annotations (Videos, GIFs) Source: https://www.nutrient.io/guides/ios/getting-started/example-projects Demonstrates the integration of multimedia annotations, such as videos and GIFs, using the Nutrient Catalog example project. This allows embedding rich media within PDF documents. ```Swift /* This code snippet is a placeholder. Actual code for multimedia annotations would be included here. Example functionalities include: - Adding video annotations to PDF pages. - Embedding animated GIFs as annotations. - Managing playback and display of multimedia content. */ // Placeholder for multimedia annotation // let annotationManager = AnnotationManager() // annotationManager.addVideoAnnotation(to: page, videoURL: url) // annotationManager.addGifAnnotation(to: page, gifURL: url) ``` -------------------------------- ### Configure PDF Annotation Toolbar in iOS Source: https://www.nutrient.io/guides/ios/samples Learn to manually configure the annotation toolbar in iOS without UINavigationController. Access guides for additional resources and examples. ```Swift let pdfViewController = PSPDFViewController() pdfViewController.toolbarConfiguration = .customToolbar ``` -------------------------------- ### Create Fixed-Size PDF Annotations in iOS Source: https://www.nutrient.io/guides/ios/samples Learn to create a fixed-size stamp annotation for iOS that remains unchanged during zoom. Access guides for more resources and examples. ```Swift let annotation = PSPDFStampAnnotation() annotation.bounds = CGRect(x: 100, y: 100, width: 50, height: 50) annotation.isSizeable = false // Make it fixed-size ``` -------------------------------- ### Set up PSPDFKit for E-Learning Exams and Grading in Swift Source: https://www.nutrient.io/guides/ios/samples Discover how to set up PSPDFKit for e-learning exams and grading. Explore additional resources in our blog on grading papers in an LMS application. ```swift // Example code for setting up PSPDFKit for e-learning exams and grading in Swift // This snippet facilitates grading papers in an LMS application. // Explore blog resources for more insights. ``` -------------------------------- ### Automatically Select and Edit Free Text Annotations in Swift Source: https://www.nutrient.io/guides/ios/samples Learn how to automatically select and edit Free Text Annotations using a Swift example with PSPDFKit. ```swift // Example code for selecting and editing free text annotations (details not provided). ``` -------------------------------- ### Customize Sharing View (SwiftUI) Source: https://www.nutrient.io/guides/ios/samples Tailor PSPDFKit components using the delegation pattern in SwiftUI. This code example offers practical insights into customizing the sharing view. ```swift /* This example demonstrates customizing the sharing view in SwiftUI using PSPDFKit's delegation pattern. It requires PSPDFKitUI and an understanding of SwiftUI's protocols and delegates. The goal is to intercept and modify the default sharing behavior or UI. This approach is useful for integrating custom sharing logic or branding. */ import SwiftUI import PSPDFKit import PSPDFKitUI // Define a delegate for customizing sharing actions class CustomSharingDelegate: NSObject, PSPDFSharingDelegate { func pdfViewController(_ pdfViewController: PSPDFViewController, shouldShareContent content: PSPDFSharingContent, for annotation: PSPDFAnnotation?) -> Bool { print("Custom sharing delegate: Should share content? \(content.description)") // Implement custom logic here, e.g., filter content or modify recipients return true // Allow sharing by default } func pdfViewController(_ pdfViewController: PSPDFViewController, didFinishSharingWith result: PSPDFSharingResult) { print("Custom sharing delegate: Sharing finished with result \(result.rawValue)") // Handle sharing completion, e.g., show success/failure messages } // You can also override methods to provide custom UI for sharing options } // Example integration within a SwiftUI view: struct SharingCustomizationView: View { @State private var pdfViewController: PSPDFViewController? = nil private let sharingDelegate = CustomSharingDelegate() var body: some View { PSPDFViewContainer(pdfViewController: $pdfViewController) .onAppear { // Assign the delegate to the PSPDFViewController pdfViewController?.delegate = sharingDelegate print("Custom sharing delegate assigned.") } .edgesIgnoringSafeArea(.all) } } ``` -------------------------------- ### Disable Bookmark Editing in PDFs with Swift Source: https://www.nutrient.io/guides/ios/samples Learn how to disable bookmark editing in PDFs using a Swift example. Explore more on document features in comprehensive guides. ```swift // Example: Disabling editing of bookmarks import UIKit import PSPDFKit class DocumentViewController: PSPDFViewController { override func viewDidLoad() { super.viewDidLoad() // Set the flag to disable bookmark editing self.isBookmarkEditingEnabled = false } } ``` -------------------------------- ### Presenting Annotation Creation Menu (Swift) Source: https://www.nutrient.io/guides/ios/migration-guides/pspdfkit-12-migration-guide Demonstrates the programmatic presentation of the annotation creation menu using the `tryToShowAnnotationMenu(at:in:)` method. This method is used when a user long-presses on space without selectable text or annotations. ```swift tryToShowAnnotationMenu(at:in:) ``` -------------------------------- ### Nutrient Catalog: PDFViewController and Toolbar Customizations Source: https://www.nutrient.io/guides/ios/getting-started/example-projects Demonstrates customizations for PDFViewController and toolbars within the Nutrient Catalog example project. This project provides over 100 code examples for various PDF functionalities in iOS. ```Swift /* This code snippet is a placeholder. Actual code for PDFViewController and Toolbar customizations would be included here. Example functionalities include: - Customizing the appearance and behavior of PDFViewController. - Modifying the toolbar items, layout, and actions. */ // Placeholder for PDFViewController customization // class CustomPDFViewController: PDFViewController { // // Custom implementations here // } // Placeholder for Toolbar customization // func setupCustomToolbar(for viewController: PDFViewController) { // // Toolbar setup logic here // } ``` -------------------------------- ### Disable Bookmark Renaming in Swift Source: https://www.nutrient.io/guides/ios/samples Learn how to override the default bookmark cell to disable renaming. Access a guide on iOS PDF bookmarks for resources and code examples. ```swift // Example code for disabling bookmark renaming by overriding the default bookmark cell in Swift // This snippet demonstrates how to prevent users from renaming bookmarks. // The guide on iOS PDF bookmarks provides more resources. ``` -------------------------------- ### Disable Annotation Reviews in Swift Source: https://www.nutrient.io/guides/ios/samples Learn how to disable viewing and setting annotation reviews in iOS documents. Explore guides and Swift code examples for effective implementation. ```swift // Example code for disabling annotation reviews in iOS documents using Swift // This snippet demonstrates how to control the visibility and setting of reviews. // Guides are available for more resources. ``` -------------------------------- ### Minimal Nutrient Integration in iOS Application Source: https://www.nutrient.io/guides/ios/getting-started/example-projects Provides a minimal integration example for the Nutrient library in a basic iOS application. It includes code for simple use cases of `Processor` and `PDFLibrary`. ```Swift /* This code snippet is a placeholder. Actual code for minimal integration would be included here. Example functionalities include: - Initializing the Nutrient library. - Performing basic PDF operations using Processor and PDFLibrary. - Integrating into a standard iOS application structure. */ // Placeholder for minimal integration // import Nutrient // // func setupNutrient() { // // Initialize Nutrient library // Nutrient.initialize() // } // // func processSimplePDF(url: URL) { // let processor = Processor() // processor.processFile(at: url) { result in // // Handle processing result // } // } ``` -------------------------------- ### Open Password-Protected PDFs in iOS with Swift Source: https://www.nutrient.io/guides/ios/samples Learn how to unlock password-protected PDFs in iOS with Swift. This guide provides resources and examples to streamline document security and access. ```swift // Code example for opening password-protected PDFs in iOS // Requires PSPDFKit framework and handling of password input. ``` -------------------------------- ### Minimal Swift Class for Foundation Libraries Source: https://www.nutrient.io/guides/ios/migration-guides/pspdfkit-9-migration-guide A minimal Swift class to ensure Foundation libraries are loaded, addressing `dyld` errors like 'Library not loaded: @rpath/libswiftCore.dylib' for Objective-C-only test targets on iOS 11 and 12. ```swift import Foundation @objc class EnsureFoundationLoaded : NSObject { @objc static func ensure() {} override init() { super.init() EnsureFoundationLoaded.ensure() } } ``` -------------------------------- ### PDF Streaming on Demand with Swift Source: https://www.nutrient.io/guides/ios/samples Explore how to load document parts on demand with Swift using PSPDFKit, including code samples. ```swift // Example code for PDF streaming on demand (details not provided). ``` -------------------------------- ### Customize the Annotation Toolbar in Swift (Swift) Source: https://www.nutrient.io/guides/ios/samples Learn how to customize the annotation toolbar in Swift, including grouping tools for optimal display in limited space. Explore example code for practical implementation. ```swift // Example: Customizing the annotation toolbar // This can involve rearranging, grouping, or replacing default buttons. import UIKit import PSPDFKit class CustomAnnotationToolbarViewController: PSPDFViewController { override func viewDidLoad() { super.viewDidLoad() // Access and modify the default toolbar or replace it with a custom one. // The exact approach depends on the PSPDFKit version and customization needs. // Example: If you want to hide certain tools or reorder them, // you might need to access the underlying toolbar view controller // and modify its configuration. // For grouping tools, you might create custom buttons that trigger // a popover or a segmented control showing related annotation types. } // You might override methods like `rightBarButtonItems` or `leftBarButtonItems` // in a subclass to inject custom buttons or replace existing ones. } ``` -------------------------------- ### Set Up PSPDFKit for E-Learning Exams in iOS Source: https://www.nutrient.io/guides/ios/samples Discover how to set up PSPDFKit for e-learning exams and grading. This guide explores resources on grading papers within an LMS application. ```Swift // Example setup for e-learning exam let pdfViewController = PSPDFViewController() // Configure PDFViewController for exam mode // e.g., enable specific annotation types, set grading options ``` -------------------------------- ### Get Annotation Menu Items with PDFPageView Source: https://www.nutrient.io/guides/ios/migration-guides/14-2-migration-guide Replaces `PDFPageView.menuItems(for:)`. Use `PDFViewControllerDelegate.pdfViewController(_:menuForAnnotations:onPageView:appearance:suggestedMenu:)` to get menu items for annotations. ```swift PDFViewControllerDelegate.pdfViewController(_:menuForAnnotations:onPageView:appearance:suggestedMenu:) ``` -------------------------------- ### Add Analytics to PDF Components in iOS Source: https://www.nutrient.io/guides/ios/samples Example implementation of `PDFAnalyticsClient` for logging events to the console in iOS. This provides insights into user interactions with PDF components. ```Swift import PSPDFKit class AnalyticsClient: NSObject, PDFAnalyticsClient { func logEvent(_ event: String, properties: [String: Any]?) { print("Event: \(event), Properties: \(properties ?? [:])") } } // Assign the client to the document pdfDocument.analyticsClient = AnalyticsClient() ``` -------------------------------- ### Store PDF Annotations in JSON Files for Multiple Users Source: https://www.nutrient.io/guides/ios/samples Learn to store annotations in JSON files for multiple users with a Swift example using PSPDFKit. ```swift // Example code for storing annotations in JSON files (details not provided). ``` -------------------------------- ### Basic Page Rendering (Swift) Source: https://www.nutrient.io/guides/ios/migration-guides/migrating-from-apple-pdfkit Shows the basic method for rendering a PDF page into a graphics context using PSPDFKit's Document class in Swift. ```swift let document: Document let pageIndex: Int let image: UIImage = document.render(at: pageIndex) ``` -------------------------------- ### HTML-to-PDF Conversion in iOS Source: https://www.nutrient.io/guides/ios/samples Convert a URL or simple HTML page to a PDF document. Get additional resources by visiting the guide on generating PDFs from HTML in iOS. ```Swift let htmlConverter = PSPDFHTMLConverter() let pdfData = try htmlConverter.convertHTMLFromURL(url: URL(string: "http://example.com")) // Save pdfData to a file ``` -------------------------------- ### Customize PDF View Margins in Swift Source: https://www.nutrient.io/guides/ios/samples Learn how to adjust document view margins in iOS to fit your custom UI. Explore guides on PDF customization for more resources and examples. ```swift // Example code for adjusting document view margins in iOS to fit custom UI in Swift // This snippet demonstrates how to modify PDF view margins. // The PDF customization guide offers more resources. ``` -------------------------------- ### Customizing PSPDFKit Components with Options Source: https://www.nutrient.io/guides/ios/migration-guides/pspdfkit-6-migration-guide This code illustrates how to provide custom implementations for PSPDFKit components like file managers and application policies by passing them in the options dictionary during initialization. This is an alternative to the removed plugin architecture. ```Objective-C +[PSPDFKitGlobal setLicenseKey:options:] ``` ```Objective-C PSPDFApplicationPolicyKey PSPDFFileManagerKey PSPDFCoordinatedFileManagerKey ``` -------------------------------- ### Process PDF using PSPDFProcessor Instance (Swift - New) Source: https://www.nutrient.io/guides/ios/migration-guides/pspdfkit-7-6-migration-guide Demonstrates the new instance-level method for processing a PDF with PSPDFProcessor, including configuration and security options. ```swift let processor = PSPDFProcessor(configuration: processorConfig, securityOptions: securityOptions) processor.write(to: outputURL) ``` -------------------------------- ### Customize PDF Form Element Appearance in Swift Source: https://www.nutrient.io/guides/ios/samples Learn how to customize the appearance of forms in iOS. This guide provides Swift examples for supported PDF form fields and their customization. ```swift // Example code for customizing PDF form element appearance in Swift // This snippet illustrates how to modify the look of form fields. // The guide details supported fields and customization methods. ``` -------------------------------- ### Present AIAssistantViewController with Document Collection (Swift) Source: https://www.nutrient.io/guides/ios/ai/multiple-document-support-uikit This snippet shows how to create an AIAssistantSession using a document collection and configuration. The session is then used to instantiate and present the AIAssistantViewController, which manages the AI Assistant connection and chat interface. ```swift let documentCollection: [String] = ["doc1", "doc2"] let configuration = AIAssistantConfiguration(jwt: "YOUR_JWT_HERE") let session = AIAssistantSession(documentCollection: documentCollection, configuration: configuration) let viewController = AIAssistantViewController(session: session) // Present viewController ``` -------------------------------- ### Use Custom Protocol Links in iOS PDFs Source: https://www.nutrient.io/guides/ios/samples This guide covers how to use custom link protocols and link annotations in PDFs on iOS. It provides practical code examples. ```swift // Example code for using custom protocol links would go here. ``` -------------------------------- ### Setting License Key in Swift for iOS Source: https://www.nutrient.io/guides/ios/getting-started/adding-the-license-key This snippet shows how to set the PSPDFKit license key in Swift for an iOS application. It's recommended to set the key early in the application lifecycle, potentially in `main.m` if using storyboards to ensure it's called before `willFinishLaunchingWithOptions`. ```swift PSPDFKit.setLicenseKey("YOUR_LICENSE_KEY") ``` -------------------------------- ### Customize Page Labels in iOS Document View Source: https://www.nutrient.io/guides/ios/samples This guide explains how to customize page labels in your iOS document view. It includes a Swift example and access to the PSPDFPageLabelFormatter API. ```swift // Example code for a custom page label formatter would go here. ``` -------------------------------- ### Add Custom View Controller for Screen Mirroring in Swift Source: https://www.nutrient.io/guides/ios/samples Learn how to add your own view controller for screen mirroring in Swift. Explore example code to customize your app's display seamlessly. ```swift // Code example for adding a custom view controller for screen mirroring // Requires knowledge of iOS view controller management. ``` -------------------------------- ### Display Measurements on PDF Pages or Spreads in iOS Source: https://www.nutrient.io/guides/ios/samples Learn how to add auxiliary views to spreads/pages in your iOS app. Explore the PDFPageView API guide and example codes for customization. ```Swift let pdfPageView = PSPDFPageView() let measurementView = UIView(frame: CGRect(x: 10, y: 10, width: 50, height: 20)) pdfPageView.insertSubview(measurementView, at: 0) ``` -------------------------------- ### Nutrient Catalog: Annotation Processing with Processor Source: https://www.nutrient.io/guides/ios/getting-started/example-projects Illustrates annotation processing using the `Processor` class in the Nutrient Catalog example project. This covers handling and manipulating annotations within PDF documents. ```Swift /* This code snippet is a placeholder. Actual code for annotation processing with Processor would be included here. Example functionalities include: - Implementing custom annotation logic. - Processing existing annotations within a PDF document. - Adding new annotations programmatically. */ // Placeholder for Processor usage // import Nutrient // // let processor = Processor() // processor.processAnnotations(in: pdfDocument) { result in // // Handle processing results // } ``` -------------------------------- ### Insert Page into PDF from Another Document in iOS Source: https://www.nutrient.io/guides/ios/samples Learn to use PSPDFDocumentEditor to copy pages from other PDFs. Explore the guide for step-by-step instructions and source code examples in Swift. ```Swift func insertPageFromDocument(sourceDocumentPath: String, pageIndex: Int, destinationDocumentPath: String, insertAtIndex: Int) throws { let editor = PSPDFDocumentEditor() let sourceDocument = try editor.open(sourceDocumentPath) let destinationDocument = try editor.open(destinationDocumentPath) try destinationDocument.insertPage(from: sourceDocument, at: pageIndex, forPage: insertAtIndex) try destinationDocument.save(to: destinationDocumentPath) } ``` -------------------------------- ### Usage Example: Rotating Pages and Adding a New Page Source: https://www.nutrient.io/guides/ios/features/document-editor Demonstrates how to rotate the first two pages and insert a new page at the beginning of a document using the API. ```APIDOC ## Usage Example (Swift) This example shows rotating the first two pages and inserting a new page at the front of a document loaded in a `PDFViewController`. ```swift // Assuming pdfViewController is an instance of PDFViewController if let editor = pdfViewController.documentEditor { // Rotate first two pages let rotatePage1 = PDFDocumentEditor.Rotation.clockwise let rotatePage2 = PDFDocumentEditor.Rotation.counterClockwise editor.rotatePage(at: 0, for: rotatePage1) editor.rotatePage(at: 1, for: rotatePage2) // Add a new page at the front let newPageConfig = PDFNewPageConfiguration() editor.addPages(in: newPageConfig, count: 1) // Save changes (example using save(toPath:)) editor.save(toPath: "/path/to/modified/document.pdf") { _ in print("Document saved successfully") } } ``` ``` -------------------------------- ### Value Transformers Source: https://www.nutrient.io/guides/ios/migration-guides/pspdfkit-3-migration-guide Explains the shift in how value transformers are exposed in v3 compared to v2. ```APIDOC ## Value Transformers ### Description JSON serialization uses various value transformers to convert things — for example, enums — into more a useful representation (strings). The `NSValueTransformer` subclasses have been directly exposed in v2. In PSPDFKit 3 for iOS, we use the more appropriate way of only exposing the name (like `PSPDFLinesTransformerName`). You can fetch the subclasses from the global registry of the `NSValueTransformer` class with `valueTransformerForName:`. ### Method N/A (Describes internal implementation changes) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Disable Bookmark Renaming in Swift Source: https://www.nutrient.io/guides/ios/samples Learn how to override the default bookmark cell to disable renaming. Access the guide on iOS PDF bookmarks for more resources and code examples in Swift. ```swift // Example: Disabling renaming of bookmarks by customizing the cell // This often involves subclassing PSPDFBookmarkTableViewCell or providing // a custom cell configuration. import UIKit import PSPDFKit class CustomBookmarkListViewController: PSPDFBookmarkListViewController { override func viewDidLoad() { super.viewDidLoad() self.delegate = self } } extension CustomBookmarkListViewController: PSPDFBookmarkListViewControllerDelegate { func pdfBookmarkListViewController(_ bookmarkListViewController: PSPDFBookmarkListViewController, cellFor bookmark: PSPDFBookmark, at indexPath: IndexPath) -> PSPDFBookmarkTableViewCell { // Get the default cell let cell = super.pdfBookmarkListViewController(bookmarkListViewController, cellFor: bookmark, at: indexPath) as! PSPDFBookmarkTableViewCell // Disable the text field used for renaming cell.bookmarkNameTextField.isEnabled = false cell.bookmarkNameTextField.isUserInteractionEnabled = false return cell } } ``` -------------------------------- ### Disable Annotation Reviews in iOS Documents (Swift) Source: https://www.nutrient.io/guides/ios/samples Learn how to disable viewing and setting annotation reviews in iOS documents. Explore guides and Swift code examples for implementation. ```swift // Example: Disabling the ability to add or view reviews for annotations import UIKit import PSPDFKit class DocumentViewController: PSPDFViewController { override func viewDidLoad() { super.viewDidLoad() // Disable the review functionality for all annotations self.annotationManager.isReviewEnabled = false } } ``` -------------------------------- ### Setting up PDF pages on iOS Source: https://www.nutrient.io/guides/ios/generating-pdfs/generating-pdf-reports Demonstrates how to set up the initial pages for a PDF report by preserving cover and final pages from a template, adding a new page with a pattern, and inserting content from another document. ```swift import SwiftUI import PDFKit struct ContentView: View { var body: some View { VStack { Button("Generate PDF") { generateReport() } } .padding() } func generateReport() { // Placeholder for PDF generation logic print("Generating PDF report...") } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } ``` -------------------------------- ### Disable PDF Annotation Editing (Swift) Source: https://www.nutrient.io/guides/ios/samples Learn how to use annotation flags to disable editing for annotations in iOS. This guide provides a Swift code example for effective implementation. ```swift // Example: Disabling editing for all annotations import UIKit import PSPDFKit class DocumentViewController: PSPDFViewController { override func viewDidLoad() { super.viewDidLoad() // Set the annotation editing behavior to disabled self.annotationEditingBehavior = .disabled // Alternatively, you can disable editing for specific annotation types // or conditionally based on user roles or document properties. // Example: Disable editing only for existing annotations // self.annotationManager.setAnnotationFlag(.readOnly, for: .all, recursive: true) } } ``` -------------------------------- ### Customize Appearance of PDF Form Elements (Swift) Source: https://www.nutrient.io/guides/ios/samples Learn how to customize the appearance of PDF forms in iOS. This guide includes Swift examples for supported PDF form fields. ```swift // Example: Customizing the appearance of PDF form elements // This often involves using PSPDFFormElement and its appearance properties. import UIKit import PSPDFKit class DocumentViewController: PSPDFViewController { override func viewDidLoad() { super.viewDidLoad() self.delegate = self } } extension DocumentViewController: PSPDFViewControllerDelegate { func pdfViewController(_ pdfViewController: PSPDFViewController, didTap formElement: PSPDFFormElement, in annotation: PSPDFAnnotation) { // Customize appearance properties of the form element // For example, changing the text field border color: // if let textField = formElement as? PSPDFTextField { // textField.borderColor = UIColor.red // textField.borderWidth = 2.0 // } // Or changing the checkbox color: // if let checkBox = formElement as? PSPDFCheckBox { // checkBox.checkedImageTintColor = UIColor.green // } } } ``` -------------------------------- ### Create Password-Protected PDFs in iOS Source: https://www.nutrient.io/guides/ios/samples Learn to generate password-protected PDF documents within your iOS application. This guide provides Swift code examples for secure PDF creation. ```swift // Example code for creating a password-protected PDF in iOS // (Actual code would involve setting security options during PDF generation) ``` -------------------------------- ### Hide or Show All PDF Annotations in iOS (Swift) Source: https://www.nutrient.io/guides/ios/samples Learn to hide or show all document annotations in iOS using PSPDFKit. Access the Swift code example and guide for managing annotations. ```swift // This is a placeholder for the actual code snippet // In a real scenario, this would contain Swift code for managing annotation visibility. // Example: /* pdfViewController.hideAllAnnotations = true // or false */ ``` -------------------------------- ### Creating a PDFLibrary Instance Source: https://www.nutrient.io/guides/ios/search/indexed-full-text-search/matching-options Instructions on how to create a new instance of PDFLibrary, including cache directory management. ```APIDOC ## Creating a PDFLibrary Instance ### Description This section explains how to instantiate `PDFLibrary` using a specified path for its cache directory. The library will create the directory if it does not exist, and subsequent calls with the same path will return the same instance. ### Method `PDFLibrary(path:)` ### Endpoint N/A ### Parameters #### Initializer Parameters - **`path`** (String) - Required - The path to an empty directory where the SQLite database cache will be stored. The directory will be created if it doesn't exist. ### Request Example ```swift let cachePath = "/path/to/your/cache/directory" let pdfLibrary = PDFLibrary(path: cachePath) ``` ### Response #### Success Response (200) - **pdfLibraryInstance** (PDFLibrary) - A new or existing instance of `PDFLibrary` associated with the provided path. #### Response Example ```swift // pdfLibrary is now an initialized PDFLibrary object. ``` ``` -------------------------------- ### Integrate PSPDFKit with Carthage Source: https://www.nutrient.io/guides/ios/migration-guides/pspdfkit-9-4-migration-guide This shows the recommended way to integrate PSPDFKit using Carthage with the new public JSON URL. Ensure you are using a compatible version of Carthage for this integration. ```shell git "https://github.com/pspdfkit/pspdfkit-ios-xcframework.git" "~> 9.4.0" ``` -------------------------------- ### Settings View with PDFViewController in SwiftUI Source: https://www.nutrient.io/guides/ios/samples Learn to create a custom page view settings interface using PDFViewController in SwiftUI. This guide provides a step-by-step example and source code for implementation. ```swift // This is a placeholder for the actual code snippet // In a real scenario, this would contain Swift code demonstrating the settings view. // Example: /* struct SettingsView: View { @Binding var isAutoSaveEnabled: Bool var body: some View { Form { Toggle("Auto-Save", isOn: $isAutoSaveEnabled) } .navigationTitle("Settings") } } */ ``` -------------------------------- ### Customize Note Annotation View Controller in Swift Source: https://www.nutrient.io/guides/ios/samples Learn to hide timestamp and author labels in PSPDFNoteAnnotationViewController. Access the API guide and example code for seamless customization of note annotations. ```swift // Example code for customizing PSPDFNoteAnnotationViewController in Swift // This snippet shows how to hide timestamp and author labels. // The API guide provides further details. ``` -------------------------------- ### Status HUD Support for Multiple Windows Source: https://www.nutrient.io/guides/ios/migration-guides/pspdfkit-9-migration-guide Details on how Status HUD now supports multiple windows on iOS 13+ and related API changes. ```APIDOC ## Status HUD Support for Multiple Windows Previously, the status HUD was a singleton. With the introduction of support for multiple windows in iOS 13, each window scene needs its own status HUD. The following changes address this: ### Method Changes - **Removed:** `+[PSPDFStatusHUD items]` _Changed to `+[PSPDFStatusHUD itemsForHUDOnWindow:]`. - **Removed:** `+[PSPDFStatusHUD popAllItemsAnimated:completion:]` _Changed to `+[PSPDFStatusHUD popAllItemsAnimated:forHUDOnWindow:completion:]`. - **Removed:** `-[PSPDFStatusHUDItem pushAnimated:completion:]` _Changed to `-[PSPDFStatusHUDItem pushAnimated:onWindow:completion:]`. - **Removed:** `-[PSPDFStatusHUDItem pushAndPopWithDelay:animated:completion:]` _Changed to `-[PSPDFStatusHUDItem pushAndPopWithDelay:animated:onWindow:completion:]`. ``` -------------------------------- ### Add Custom Thumbnail View Filter in iOS Source: https://www.nutrient.io/guides/ios/samples Learn how to subclass ThumbnailViewController to create a custom filter for ink annotations in iOS. This guide offers resources and examples for filtering annotations. ```swift // Example code for adding a custom thumbnail view filter would go here. ``` -------------------------------- ### Presenting Menus with Text or Image Selection Source: https://www.nutrient.io/guides/ios/migration-guides/pspdfkit-12-3-migration-guide PSPDFKit 12.3 introduces new methods for selecting text or images and simultaneously presenting their associated menus. ```APIDOC ## Present Menus with Text or Image Selection ### Description These new methods in `PDFPageView` allow for the selection of text or images directly, with the option to present the associated context menu immediately. ### Method - `select(glyphs:presentMenu:animated:)` - `select(image:presentMenu:animated:)` ### Endpoint N/A (Methods within `PDFPageView` class) ### Parameters #### `select(glyphs:presentMenu:animated:)` - **glyphs** (Array) - The text glyphs to select. - **presentMenu** (Bool) - If `true`, the menu will be presented after selection. - **animated** (Bool) - If `true`, the selection and menu presentation will be animated. #### `select(image:presentMenu:animated:)` - **image** (PDFImage) - The image to select. - **presentMenu** (Bool) - If `true`, the menu will be presented after selection. - **animated** (Bool) - If `true`, the selection and menu presentation will be animated. #### Deprecated Methods (to be removed in future versions): - `PDFViewController.showMenuIfSelected(with:animated:)` - `PDFPageView.showMenuIfSelected(with:animated:)` - `PDFPageView.showMenu(for:animated:)` - `PDFPageView.showMenuIfSelected(animated:)` ### Request Example ```swift // Assuming 'pageView' is an instance of PDFPageView and 'image' is a PDFImage object pageView.select(image: image, presentMenu: true, animated: true) ``` ### Response #### Success Response (N/A - Action modifies UI state) - The specified text or image is selected, and the corresponding menu is presented if `presentMenu` is true. #### Response Example N/A ``` -------------------------------- ### Add Custom Pencil Interactions in iOS (Swift) Source: https://www.nutrient.io/guides/ios/samples Learn how to register custom actions for UIPencilInteraction in iOS. This guide provides example code in Swift for Apple Pencil double-tap support. ```swift // Example code for custom pencil interactions would go here. ``` -------------------------------- ### Presenting Menu for Selected Annotations (Swift) Source: https://www.nutrient.io/guides/ios/migration-guides/pspdfkit-12-migration-guide Shows how to select annotations and present their associated menu simultaneously using the `select(annotations:presentMenu:animated:)` method. The `presentMenu` parameter must be set to `true` for the menu to appear. ```swift select(annotations:presentMenu:animated:) ``` -------------------------------- ### Adaptive Toolbar Configuration (Swift) Source: https://www.nutrient.io/guides/ios/migration-guides/pspdfkit-5-migration-guide Details the adaptive nature of annotation and text toolbars, with updated configurations allowing for 'sets' of options to best fit available space. Refer to PSPDFAnnotationToolbarConfiguration for specifics. ```swift struct PSPDFAnnotationToolbarConfiguration { // Configuration options for adaptive toolbars // Can include sets of configurations for different screen sizes } struct PSPDFTextToolConfiguration { // Similar adaptive configuration for text toolbars } ``` -------------------------------- ### Nutrient Catalog: Forms and Digital Signatures Source: https://www.nutrient.io/guides/ios/getting-started/example-projects Covers the implementation of PDF forms and digital signatures within the Nutrient Catalog example project. This includes creating, filling, and signing interactive PDF forms. ```Swift /* This code snippet is a placeholder. Actual code for forms and digital signatures would be included here. Example functionalities include: - Creating interactive PDF form fields. - Populating form data programmatically. - Applying and verifying digital signatures. */ // Placeholder for form handling // let formFiller = FormFiller() // formFiller.fillField(named: "username", with: "exampleUser") // Placeholder for digital signatures // let signatureManager = SignatureManager() // signatureManager.signDocument(with: privateKey) ``` -------------------------------- ### SwiftUI Split Screen for PDFs (Swift) Source: https://www.nutrient.io/guides/ios/samples Utilize SwiftUI to display two PSPDFViewControllers side by side, creating an effective split-screen design. This Swift code example guides you through the implementation. ```swift /* This example demonstrates using SwiftUI to display two PSPDFViewControllers side by side (split screen). It requires PSPDFKitUI and knowledge of SwiftUI's `HStack` and layout management. The goal is to show two documents or views of the same document simultaneously. This is particularly useful for comparisons or multi-document workflows. */ import SwiftUI import PSPDFKit import PSPDFKitUI struct SplitScreenPDFView: View { @State private var pdfViewController1: PSPDFViewController? = nil @State private var pdfViewController2: PSPDFViewController? = nil // Example document URLs let documentURL1: URL? = Bundle.main.url(forResource: "document1.pdf", withExtension: nil) let documentURL2: URL? = Bundle.main.url(forResource: "document2.pdf", withExtension: nil) var body: some View { HStack { // First PDF View if let docURL1 = documentURL1 { PSPDFViewContainer(pdfViewController: $pdfViewController1) .onAppear { pdfViewController1 = PSPDFViewController(document: PSPDFDocument(url: docURL1)!) } .frame(maxWidth: .infinity) } else { Text("Document 1 not found") } Divider() // Visual separator // Second PDF View if let ``` -------------------------------- ### SDK Usage Example for iOS Annotation (Swift) Source: https://www.nutrient.io/guides/ios/samples/create-free-text-annotations-continuously This code sample demonstrates the basic usage of an SDK to facilitate annotation tasks within an iOS application. It is intended as a starting point and may require adaptation to specific project needs. No external dependencies are explicitly mentioned, but it implies interaction with the SDK's functionalities. ```swift // This code sample is an example that illustrates how to use our SDK. // Please adapt it to your specific use case. ``` -------------------------------- ### Show Author Name on Annotation Selection in Swift Source: https://www.nutrient.io/guides/ios/samples Learn how to display author names on annotation selection in PSPDFKit using Swift. Explore the example code and the PSPDFAnnotation API guide. ```swift // Code example for displaying author names when an annotation is selected // Requires PSPDFAnnotation API and event handling. ```