{"id":19756891,"url":"https://github.com/compdfkit/compdfkit-pdf-sdk-ios-swift","last_synced_at":"2025-07-16T04:40:19.010Z","repository":{"id":214302098,"uuid":"736121901","full_name":"ComPDFKit/compdfkit-pdf-sdk-ios-swift","owner":"ComPDFKit","description":"Show how to use the ComPDFKit Swift PDF SDK to build a robust PDF viewer and editor in your iOS projects.","archived":false,"fork":false,"pushed_at":"2025-07-09T08:10:13.000Z","size":471910,"stargazers_count":20,"open_issues_count":2,"forks_count":3,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-09T09:26:03.552Z","etag":null,"topics":["compdfkit","ios","macos","pdf","pdf-document","pdf-editor","pdf-viewer","swift"],"latest_commit_sha":null,"homepage":"https://www.compdf.com/ios","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ComPDFKit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license_key_ios.xml","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-12-27T03:39:14.000Z","updated_at":"2025-07-09T08:09:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"56034060-6316-4665-88b9-31881e624751","html_url":"https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift","commit_stats":{"total_commits":2,"total_committers":1,"mean_commits":2.0,"dds":0.0,"last_synced_commit":"68d12c2c25cc587e3d8a8f132db15565e07adf4d"},"previous_names":["compdfkit/compdfkit-pdf-sdk-ios-swift"],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/ComPDFKit/compdfkit-pdf-sdk-ios-swift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ComPDFKit%2Fcompdfkit-pdf-sdk-ios-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ComPDFKit%2Fcompdfkit-pdf-sdk-ios-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ComPDFKit%2Fcompdfkit-pdf-sdk-ios-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ComPDFKit%2Fcompdfkit-pdf-sdk-ios-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ComPDFKit","download_url":"https://codeload.github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ComPDFKit%2Fcompdfkit-pdf-sdk-ios-swift/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265482099,"owners_count":23773998,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compdfkit","ios","macos","pdf","pdf-document","pdf-editor","pdf-viewer","swift"],"created_at":"2024-11-12T03:17:21.324Z","updated_at":"2025-07-16T04:40:19.000Z","avatar_url":"https://github.com/ComPDFKit.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Introduction\n\nComPDFKit PDF SDK for Swift is developed and maintained by [ComPDF](https://www.compdf.com/), enabling developers to quickly and seamlessly integrate advanced PDF functionalities—such as viewing, editing, annotating, and signing—into any iOS or macOS application.\n\nMore Information can be found at: https://www.compdf.com/guides/pdf-sdk/ios/overview\n\n\n\n# Table of Contents\n- [Related](#related)\n- [Requirements](#requirements)\n- [How to Make an iOS App in Swift with ComPDFKit](#how-to-make-an-ios-app-in-swift-with-compdfkit)\n- [Supports](#support)\n- [License](#license)\n- [Note](#note)\n\n# Related\n\n- [ComPDFKit PDF SDK for iOS Documentation Guide](https://www.compdf.com/guides/pdf-sdk/ios/overview)\n\n- [ComPDFKit PDF Library for Android](https://github.com/ComPDFKit/compdfkit-pdf-sdk-android)\n\n- [How to Build a Swift PDF Editor and Reader to Edit PDF on iOS](https://www.compdf.com/blog/build-an-ios-pdf-viewer-or-editor-in-swift)\n\n- [How to Build an iOS PDF Viewer or Editor in Objective-C](https://www.compdf.com/blog/build-an-ios-pdf-viewer-or-editor-in-objective-c)\n\n- [Code Samples for iOS](https://www.compdf.com/guides/pdf-sdk/ios/examples)\n\n- [ComPDF API Reference](https://api.compdf.com/api-reference/overview)\n\n  \n\n# Requirements\n\n[ComPDFKit PDF SDK for iOS](https://www.compdf.com/guides/pdf-sdk/ios/overview) requires the latest stable version of Xcode available at the time the release was made. This is a hard requirement, as each version of Xcode is bundled with a specific version of the iOS Base SDK, which often defines how UIKit and various other frameworks behave. \n\n- iOS 10.0 or higher.\n- Xcode 13.0 or newer for Objective-C or Swift.\n\n\n\n# How to Make an iOS App in Swift with ComPDFKit\n\nThis section will help you to quickly get started with ComPDFKit PDF SDK to make an iOS/macOS app in Swift with step-by-step instructions, which include the following steps:\n\n- Create a new iOS/macOS project in Swift.\n- Integrate ComPDFKit into your apps.\n- Apply the license key.\n- Display a PDF document.\n\n## Video Guide!\n\n[\u003cimg src=\"image/youtube-image-20250521.png\" alt=\"youtube-image-20250521\" width=\"600\" height=\"350\"/\u003e](https://youtu.be/pA-Dsv-qe0c?si=jaij_XNujPdM02xF%0A)\n\n\n\n## Create a New iOS Project in Swift\n\nIn this guide, we use Xcode 12.4 to create a new iOS project.\n\n1. Fire up Xcode, choose **File** -\u003e **New** -\u003e **Project...**, and then select **iOS** -\u003e **Single View Application**. Click **Next**.\n\n\u003cimg align=\"center\" src=\"image/2-2.png\" width=\"50%\" height=\"50%\" /\u003e\n\n2. Choose the options for your new project. Please make sure to choose Swift as the programming language. Then, click **Next**.\n\n\u003cimg align=\"center\" src=\"image/2-3.png\" width=\"50%\" height=\"50%\" /\u003e\n\n3. Place the project to the location as desired. Then, click **Create**.\n\n\n\n## Integrate ComPDFKit into Your Apps\n\nTo add the dynamic xcframework ***\"ComPDFKit.xcframework\"*** into the ***\"PDFViewer\"*** project, please follow the steps below:\n\n1. Right-click the ***\"PDFViewer\"*** project, select **Add Files to \"PDFViewer\"...**.\n\n   \u003cimg align=\"center\" src=\"image/2-4.png\" width=\"50%\" height=\"50%\" /\u003e\n\n2. Find and choose ***\"ComPDFKit.xcframework\"*** in the download package, and then click **Add**.\n\n   **Note:** *Make sure to check the **Copy items if needed** option.*\n\n   \u003cimg align=\"center\" src=\"image/2-5.png\" width=\"50%\" height=\"50%\" /\u003e\n\n3. Then, the ***\"PDFViewer\"*** project will look like the following picture.\n\n   \u003cimg align=\"center\" src=\"image/2-6.png\" width=\"50%\" height=\"50%\" /\u003e\n\n4. Add the dynamic xcframework ***\"ComPDFKit.xcframework\"*** to the Xcode's **Embedded Binaries**. Left-click the project, find **Embedded Binaries** in the **General** tab, and choose **Embed \u0026 Sign**.\n\n   \u003cimg align=\"center\" src=\"image/2-7.png\" width=\"50%\" height=\"50%\" /\u003e\n\n5. For earlier versions of Xcode (like Xcode 13), the Bitcode option might be turned on by default, which requires it to be turned off to run. The precise steps to do this are illustrated as shown in the picture below. \n\n   \u003cimg align=\"center\" src=\"image/2-7-1.jpg\" alt=\"2-7-1\" width=\"50%\" height=\"50%\" /\u003e\n\n\n\n## Apply the License Key\n\nGo to [ComPDF Pricing](https://www.compdf.com/pricing) to get a free license to test this project.\n\n1. Import the header file ***\"ComPDFKit\"*** to `AppDelegate.swift`.\n\n2. License initialize:\n\n   **Online license:** \n\n   Follow the code below and call the method `CPDFKit.verify(withOnlineLicense: \"YOUR_LICENSE_KEY_GOES_HERE\") { code, message in}`   in  ` func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -\u003e Bool`. You need to replace the  **LICENSE_KEY** with the license you obtained.\n\n      ```swift\n     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -\u003e Bool {\n     // Set your online license key here. ComPDFKit is commercial software.\n     // Each ComPDFKit license is bound to a specific app bundle id.\n     // com.compdfkit.pdfviewe\n       \n       CPDFKit.verify(withOnlineLicense: \"YOUR_LICENSE_KEY_GOES_HERE\") { code, message in\n       }\n   }\n      ```\n\n   **Offline license:**\n\n    Follow the code below and call the method `CPDFKit.verifyWithKey:\"LICENSE_SECRET\"` in `func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -\u003e Bool `. You need to replace the  **LICENSE_KEY**  with the license you obtained.\n\n   ```swift\n     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -\u003e Bool {\n     // Set your license key here. ComPDFKit is commercial software.\n     // Each ComPDFKit license is bound to a specific app bundle id.\n     // com.compdfkit.pdfviewer\n       \n       CPDFKit.verify(withKey: \"YOUR_LICENSE_KEY_GOES_HERE\")\n       return true\n   }\n   ```\n\n\n3. Compile and run the project. If the console outputs \"version information\", it means that the license has been set successfully. Otherwise, please check \"Troubleshooting\" or check error logs in the console to quickly identify and solve the issue. \n\n\n## Display a PDF Document\n\nSo far, we have added ***\"ComPDFKit.xcframework\"*** to the ***\"PDFViewer\"*** project and finished the initialization of the ComPDFKit PDF SDK. Now, let’s start building a simple PDF viewer with just a few lines of code.\n\n1. Prepare a test PDF file, and drag and drop it into the newly created **PDFView** project. In this way, you can load and preview the local PDF document using `NSBundle`. The following image shows an example of importing a PDF document named \"Online5\" into the project.\n\n   \u003cimg align=\"center\" src=\"image/2-7-2.jpg\" alt=\"2-7-2\" width=\"50%\" height=\"50%\" /\u003e\n\n2. Import `ComPDFKit`  at the top of your `UIViewController.swift` subclass implementation:\n\n   ```swift\n   import ComPDFKit\n   ```\n\n3. Create a `CPDFDocument` object through **NSURL**, and create a `CPDFView` to display it. The following code shows how to load PDF data using a local PDF path and display it by `CPDFView`.\n\n   ```swift\n   guard let filePath = Bundle.main.path(forResource: \"Online5\", ofType: \"pdf\") else { return  }\n   let url = URL(fileURLWithPath: filePath)\n   let document = CPDFDocument(url: url)\n   \n   let rect = self.view.bounds\n   let pdfView = CPDFView(frame: self.view.bounds)\n   pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight]\n   pdfView.document = document\n   ```\n\n4. Add the created `CPDFView` to the view of the current controller. The sample code is shown below.\n\n   ```swift\n   self.view.addSubview(pdfView)\n   ```\n\n5. The code shown here is a collection of the steps mentioned above:\n\n   ```swift\n   override func viewWillAppear(_ animated: Bool) {\n        super.viewWillAppear(animated)\n           \n        guard let filePath = Bundle.main.path(forResource: \"Online5\", ofType: \"pdf\") else { return  }\n        let url = URL(fileURLWithPath: filePath)\n        let document = CPDFDocument(url: url)\n   \n        let rect = self.view.bounds\n        let pdfView = CPDFView(frame: self.view.bounds)\n        pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight]\n        pdfView.document = document\n        self.view.addSubview(pdfView)\n   }\n   ```\n\n6. Connect your device or simulator, and use the shortcut **Command_R** to run the App. The PDF file will be opened and displayed.\n\n   \u003cimg align=\"center\" src=\"image/2-7-3.jpg\" alt=\"2-7-3\" width=\"50%\" height=\"50%\" /\u003e\n\n\n\n## Troubleshooting\n\n1. Bitcode\n\n   Even when all configurations are correct, there may still be compilation errors. First, check if the Bitcode is disabled. In earlier versions of Xcode (such as Xcode 13), the Bitcode option may be enabled by default. It needs to be set to **No** in order to run the app.\n\n2. License\n\n   If a License setting error occurs, ensure that the Identity ([Bundle ID](https://www.compdf.com/faq/how-to-find-the-bundle-id)) setting in **General** matches the Bundle ID you provided when contacting us for the license. If an expired License message appears, please contact the [ComPDFKit team](https://www.compdf.com/contact-sales) to obtain the latest License and Key.\n\n\n3. Cannot Run on i386 Architecture Simulator\n\n   The version of Xcode 12.5 or newer, doesn't support i386 simulators. Apple dropped the i386 after switching to ARM processors and no longer maintains i386 architecture simulators. Please use ARM simulators or x86_64 architecture simulators to test and develop your program.\n\n   So you need to search for **Excluded Architectures** in **Build Settings** in **TARGETS**, and then double-click it. A pop-up window will be popped up, click the plus sign (as shown below) to add **i386**.\n\n   \u003cimg align=\"center\" src=\"image/2-7-4.png\" alt=\"2-7-4\" width=\"50%\" height=\"50%\" /\u003e\n\n4. No PDF Displayed\n\n   Check if the special encoding is required in the path we passed in, or if the local path we passed in exists.\n\n\n5. Other Problems\n\n   If you meet some other problems when integrating our ComPDFKit PDF SDK for iOS, feel free to contact [ComPDFKit's support team](https://www.compdf.com/support).\n\n\n# Support\n\nComPDF offers professional technical support and 5*24 responsive service.\n\n- For detailed information, please visit our [Guides](https://www.compdf.com/guides/pdf-sdk/ios/overview) page.\n\n- Stay updated with the latest improvements through our [Changelog](https://www.compdf.com/pdf-sdk/changelog-ios).\n\n- For technical assistance, please reach out to our [Technical Support](https://www.compdf.com/support).\n\n- To get more details and an accurate quote, please contact our [Sales Team](https://www.compdf.com/contact-sales) or [Send an Email](mailto:support@compdf.com) to us.\n\n\n\n\n# License\n\nComPDF offers developers a [30-day free trial](https://www.compdf.com/pricing) license for free testing your iOS projects. Additionally, you'll have access to a fully-featured product with no limitations on file or user count.\n\n\n# Note\nWe are glad to announce that you can [register a ComPDF API account](https://api.compdf.com/signup) for a free trial to process 1000 documents per month for free.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompdfkit%2Fcompdfkit-pdf-sdk-ios-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcompdfkit%2Fcompdfkit-pdf-sdk-ios-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompdfkit%2Fcompdfkit-pdf-sdk-ios-swift/lists"}