├── .gitignore ├── LICENSE.md ├── PDFViewer.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ ├── IDEWorkspaceChecks.plist │ └── swiftpm │ └── Package.resolved ├── PDFViewer ├── .DS_Store ├── Assets.xcassets │ ├── .DS_Store │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── ContentView.swift ├── Helpers │ ├── AnchorButton.swift │ ├── BarButtonWatcher.swift │ └── PDFExtensions.swift ├── Info.plist ├── PDFView │ ├── PDFView.swift │ ├── PDFViewActions.swift │ ├── PDFViewConfiguration.swift │ ├── PDFViewCoordinator.swift │ └── PDFViewDelegates.swift ├── PDFViewer.entitlements ├── PDFViewerApp.swift ├── PDFViewerDocument.swift ├── PageLabel.swift └── Preview Content │ └── Preview Assets.xcassets │ └── Contents.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | 28 | ## App packaging 29 | *.ipa 30 | *.dSYM.zip 31 | *.dSYM 32 | 33 | ## Playgrounds 34 | timeline.xctimeline 35 | playground.xcworkspace 36 | 37 | .DS_Store 38 | 39 | # Swift Package Manager 40 | # 41 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 42 | # Packages/ 43 | # Package.pins 44 | # Package.resolved 45 | # *.xcodeproj 46 | # 47 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata 48 | # hence it is not needed unless you have added a package configuration file to your project 49 | # .swiftpm 50 | 51 | .build/ 52 | 53 | # CocoaPods 54 | # 55 | # We recommend against adding the Pods directory to your .gitignore. However 56 | # you should judge for yourself, the pros and cons are mentioned at: 57 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 58 | # 59 | # Pods/ 60 | # 61 | # Add this line if you want to avoid checking in source code from the Xcode workspace 62 | # *.xcworkspace 63 | 64 | # Carthage 65 | # 66 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 67 | # Carthage/Checkouts 68 | 69 | Carthage/Build/ 70 | 71 | # Accio dependency management 72 | Dependencies/ 73 | .accio/ 74 | 75 | # fastlane 76 | # 77 | # It is recommended to not store the screenshots in the git repo. 78 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 79 | # For more information about the recommended setup visit: 80 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 81 | 82 | fastlane/report.xml 83 | fastlane/Preview.html 84 | fastlane/screenshots/**/*.png 85 | fastlane/test_output 86 | 87 | # Code Injection 88 | # 89 | # After new code Injection tools there's a generated folder /iOSInjectionProject 90 | # https://github.com/johnno1962/injectionforxcode 91 | 92 | iOSInjectionProject/ 93 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The PSPDFKit Sample applications are licensed with a modified BSD 2 | license. In plain language: you're allowed to do whatever you wish 3 | with the code, modify, redistribute, embed in your products (free or 4 | commercial), but you must include copyright, terms of usage and 5 | disclaimer as stated in the license. 6 | 7 | You will require a commercial PSPDFKit License to run these examples 8 | in non-demo mode. Please refer to sales@pspdfkit.com for details. 9 | 10 | Copyright © 2010-2020 PSPDFKit GmbH. 11 | All rights reserved. 12 | 13 | Redistribution and use in source or binary forms, 14 | with or without modification, are permitted provided 15 | that the following conditions are met: 16 | 17 | - Redistributions of source code must retain the above copyright 18 | notice, this list of conditions and the following disclaimer. 19 | 20 | - Redistributions in binary form must reproduce the above copyright 21 | notice, this list of conditions and the following disclaimer in the 22 | documentation and/or other materials provided with the 23 | distribution. 24 | 25 | - Redistributions of PSPDFKit Samples must include attribution to 26 | PSPDFKit, either in documentation or other appropriate media. 27 | 28 | - Neither the name of the PSPDFKit, PSPDFKit GmbH, nor its developers 29 | may be used to endorse or promote products derived from 30 | this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 35 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 36 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 37 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 38 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 39 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 40 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 41 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 42 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 43 | -------------------------------------------------------------------------------- /PDFViewer.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 52; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 78C1EAEE2524A507000EEC2C /* PDFViewerApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C1EAED2524A507000EEC2C /* PDFViewerApp.swift */; }; 11 | 78C1EAF02524A507000EEC2C /* PDFViewerDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C1EAEF2524A507000EEC2C /* PDFViewerDocument.swift */; }; 12 | 78C1EAF22524A507000EEC2C /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C1EAF12524A507000EEC2C /* ContentView.swift */; }; 13 | 78C1EAF42524A508000EEC2C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 78C1EAF32524A508000EEC2C /* Assets.xcassets */; }; 14 | 78C1EAF72524A508000EEC2C /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 78C1EAF62524A508000EEC2C /* Preview Assets.xcassets */; }; 15 | 78C1EB012524A6B0000EEC2C /* PDFView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C1EB002524A6B0000EEC2C /* PDFView.swift */; }; 16 | 78C1EB092524A947000EEC2C /* PDFExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C1EB082524A947000EEC2C /* PDFExtensions.swift */; }; 17 | 78C1EB0E2524A961000EEC2C /* PSPDFKit in Frameworks */ = {isa = PBXBuildFile; productRef = 78C1EB0D2524A961000EEC2C /* PSPDFKit */; }; 18 | 78C1EB122524AABE000EEC2C /* PDFViewCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C1EB112524AABE000EEC2C /* PDFViewCoordinator.swift */; }; 19 | 78C1EB192524AE0D000EEC2C /* PageLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C1EB182524AE0D000EEC2C /* PageLabel.swift */; }; 20 | 78C1EB1B2524AFB8000EEC2C /* PDFViewConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C1EB1A2524AFB8000EEC2C /* PDFViewConfiguration.swift */; }; 21 | 78C1EB1D2524B2E6000EEC2C /* PDFViewActions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C1EB1C2524B2E6000EEC2C /* PDFViewActions.swift */; }; 22 | 78C1EB202524B5D9000EEC2C /* InterposeKit in Frameworks */ = {isa = PBXBuildFile; productRef = 78C1EB1F2524B5D9000EEC2C /* InterposeKit */; }; 23 | 78C1EB222524B5E6000EEC2C /* BarButtonWatcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C1EB212524B5E6000EEC2C /* BarButtonWatcher.swift */; }; 24 | 78C1EB242524B799000EEC2C /* AnchorButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C1EB232524B799000EEC2C /* AnchorButton.swift */; }; 25 | 78C1EB262524B99B000EEC2C /* PDFViewDelegates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C1EB252524B99B000EEC2C /* PDFViewDelegates.swift */; }; 26 | /* End PBXBuildFile section */ 27 | 28 | /* Begin PBXCopyFilesBuildPhase section */ 29 | 78C1EB162524AC67000EEC2C /* CopyFiles */ = { 30 | isa = PBXCopyFilesBuildPhase; 31 | buildActionMask = 2147483647; 32 | dstPath = ""; 33 | dstSubfolderSpec = 10; 34 | files = ( 35 | ); 36 | runOnlyForDeploymentPostprocessing = 0; 37 | }; 38 | /* End PBXCopyFilesBuildPhase section */ 39 | 40 | /* Begin PBXFileReference section */ 41 | 78C1EAEA2524A507000EEC2C /* PDFViewer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PDFViewer.app; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | 78C1EAED2524A507000EEC2C /* PDFViewerApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFViewerApp.swift; sourceTree = ""; }; 43 | 78C1EAEF2524A507000EEC2C /* PDFViewerDocument.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFViewerDocument.swift; sourceTree = ""; }; 44 | 78C1EAF12524A507000EEC2C /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 45 | 78C1EAF32524A508000EEC2C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 46 | 78C1EAF62524A508000EEC2C /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 47 | 78C1EAF82524A508000EEC2C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 48 | 78C1EB002524A6B0000EEC2C /* PDFView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFView.swift; sourceTree = ""; }; 49 | 78C1EB052524A845000EEC2C /* PDFViewer.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = PDFViewer.entitlements; sourceTree = ""; }; 50 | 78C1EB082524A947000EEC2C /* PDFExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PDFExtensions.swift; sourceTree = ""; }; 51 | 78C1EB112524AABE000EEC2C /* PDFViewCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFViewCoordinator.swift; sourceTree = ""; }; 52 | 78C1EB182524AE0D000EEC2C /* PageLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageLabel.swift; sourceTree = ""; }; 53 | 78C1EB1A2524AFB8000EEC2C /* PDFViewConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFViewConfiguration.swift; sourceTree = ""; }; 54 | 78C1EB1C2524B2E6000EEC2C /* PDFViewActions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFViewActions.swift; sourceTree = ""; }; 55 | 78C1EB212524B5E6000EEC2C /* BarButtonWatcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BarButtonWatcher.swift; sourceTree = ""; }; 56 | 78C1EB232524B799000EEC2C /* AnchorButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnchorButton.swift; sourceTree = ""; }; 57 | 78C1EB252524B99B000EEC2C /* PDFViewDelegates.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFViewDelegates.swift; sourceTree = ""; }; 58 | /* End PBXFileReference section */ 59 | 60 | /* Begin PBXFrameworksBuildPhase section */ 61 | 78C1EAE72524A507000EEC2C /* Frameworks */ = { 62 | isa = PBXFrameworksBuildPhase; 63 | buildActionMask = 2147483647; 64 | files = ( 65 | 78C1EB0E2524A961000EEC2C /* PSPDFKit in Frameworks */, 66 | 78C1EB202524B5D9000EEC2C /* InterposeKit in Frameworks */, 67 | ); 68 | runOnlyForDeploymentPostprocessing = 0; 69 | }; 70 | /* End PBXFrameworksBuildPhase section */ 71 | 72 | /* Begin PBXGroup section */ 73 | 78C1EAE12524A507000EEC2C = { 74 | isa = PBXGroup; 75 | children = ( 76 | 78C1EAEC2524A507000EEC2C /* PDFViewer */, 77 | 78C1EAEB2524A507000EEC2C /* Products */, 78 | ); 79 | sourceTree = ""; 80 | }; 81 | 78C1EAEB2524A507000EEC2C /* Products */ = { 82 | isa = PBXGroup; 83 | children = ( 84 | 78C1EAEA2524A507000EEC2C /* PDFViewer.app */, 85 | ); 86 | name = Products; 87 | sourceTree = ""; 88 | }; 89 | 78C1EAEC2524A507000EEC2C /* PDFViewer */ = { 90 | isa = PBXGroup; 91 | children = ( 92 | 78C1EB052524A845000EEC2C /* PDFViewer.entitlements */, 93 | 78C1EAFF2524A6A0000EEC2C /* PDFView */, 94 | 78C1EAED2524A507000EEC2C /* PDFViewerApp.swift */, 95 | 78C1EAEF2524A507000EEC2C /* PDFViewerDocument.swift */, 96 | 78C1EAF12524A507000EEC2C /* ContentView.swift */, 97 | 78C1EB182524AE0D000EEC2C /* PageLabel.swift */, 98 | 78C1EB0B2524A94B000EEC2C /* Helpers */, 99 | 78C1EAF32524A508000EEC2C /* Assets.xcassets */, 100 | 78C1EAF82524A508000EEC2C /* Info.plist */, 101 | 78C1EAF52524A508000EEC2C /* Preview Content */, 102 | ); 103 | path = PDFViewer; 104 | sourceTree = ""; 105 | }; 106 | 78C1EAF52524A508000EEC2C /* Preview Content */ = { 107 | isa = PBXGroup; 108 | children = ( 109 | 78C1EAF62524A508000EEC2C /* Preview Assets.xcassets */, 110 | ); 111 | path = "Preview Content"; 112 | sourceTree = ""; 113 | }; 114 | 78C1EAFF2524A6A0000EEC2C /* PDFView */ = { 115 | isa = PBXGroup; 116 | children = ( 117 | 78C1EB002524A6B0000EEC2C /* PDFView.swift */, 118 | 78C1EB112524AABE000EEC2C /* PDFViewCoordinator.swift */, 119 | 78C1EB1A2524AFB8000EEC2C /* PDFViewConfiguration.swift */, 120 | 78C1EB1C2524B2E6000EEC2C /* PDFViewActions.swift */, 121 | 78C1EB252524B99B000EEC2C /* PDFViewDelegates.swift */, 122 | ); 123 | path = PDFView; 124 | sourceTree = ""; 125 | }; 126 | 78C1EB0B2524A94B000EEC2C /* Helpers */ = { 127 | isa = PBXGroup; 128 | children = ( 129 | 78C1EB082524A947000EEC2C /* PDFExtensions.swift */, 130 | 78C1EB212524B5E6000EEC2C /* BarButtonWatcher.swift */, 131 | 78C1EB232524B799000EEC2C /* AnchorButton.swift */, 132 | ); 133 | path = Helpers; 134 | sourceTree = ""; 135 | }; 136 | /* End PBXGroup section */ 137 | 138 | /* Begin PBXNativeTarget section */ 139 | 78C1EAE92524A507000EEC2C /* PDFViewer */ = { 140 | isa = PBXNativeTarget; 141 | buildConfigurationList = 78C1EAFB2524A508000EEC2C /* Build configuration list for PBXNativeTarget "PDFViewer" */; 142 | buildPhases = ( 143 | 78C1EAE62524A507000EEC2C /* Sources */, 144 | 78C1EAE72524A507000EEC2C /* Frameworks */, 145 | 78C1EAE82524A507000EEC2C /* Resources */, 146 | 78C1EB162524AC67000EEC2C /* CopyFiles */, 147 | 78C1EB172524AC6E000EEC2C /* ShellScript */, 148 | ); 149 | buildRules = ( 150 | ); 151 | dependencies = ( 152 | ); 153 | name = PDFViewer; 154 | packageProductDependencies = ( 155 | 78C1EB0D2524A961000EEC2C /* PSPDFKit */, 156 | 78C1EB1F2524B5D9000EEC2C /* InterposeKit */, 157 | ); 158 | productName = PDFViewer; 159 | productReference = 78C1EAEA2524A507000EEC2C /* PDFViewer.app */; 160 | productType = "com.apple.product-type.application"; 161 | }; 162 | /* End PBXNativeTarget section */ 163 | 164 | /* Begin PBXProject section */ 165 | 78C1EAE22524A507000EEC2C /* Project object */ = { 166 | isa = PBXProject; 167 | attributes = { 168 | LastSwiftUpdateCheck = 1220; 169 | LastUpgradeCheck = 1220; 170 | TargetAttributes = { 171 | 78C1EAE92524A507000EEC2C = { 172 | CreatedOnToolsVersion = 12.2; 173 | }; 174 | }; 175 | }; 176 | buildConfigurationList = 78C1EAE52524A507000EEC2C /* Build configuration list for PBXProject "PDFViewer" */; 177 | compatibilityVersion = "Xcode 9.3"; 178 | developmentRegion = en; 179 | hasScannedForEncodings = 0; 180 | knownRegions = ( 181 | en, 182 | Base, 183 | ); 184 | mainGroup = 78C1EAE12524A507000EEC2C; 185 | packageReferences = ( 186 | 78C1EB0C2524A961000EEC2C /* XCRemoteSwiftPackageReference "PSPDFKit-SP" */, 187 | 78C1EB1E2524B5D9000EEC2C /* XCRemoteSwiftPackageReference "InterposeKit" */, 188 | ); 189 | productRefGroup = 78C1EAEB2524A507000EEC2C /* Products */; 190 | projectDirPath = ""; 191 | projectRoot = ""; 192 | targets = ( 193 | 78C1EAE92524A507000EEC2C /* PDFViewer */, 194 | ); 195 | }; 196 | /* End PBXProject section */ 197 | 198 | /* Begin PBXResourcesBuildPhase section */ 199 | 78C1EAE82524A507000EEC2C /* Resources */ = { 200 | isa = PBXResourcesBuildPhase; 201 | buildActionMask = 2147483647; 202 | files = ( 203 | 78C1EAF72524A508000EEC2C /* Preview Assets.xcassets in Resources */, 204 | 78C1EAF42524A508000EEC2C /* Assets.xcassets in Resources */, 205 | ); 206 | runOnlyForDeploymentPostprocessing = 0; 207 | }; 208 | /* End PBXResourcesBuildPhase section */ 209 | 210 | /* Begin PBXShellScriptBuildPhase section */ 211 | 78C1EB172524AC6E000EEC2C /* ShellScript */ = { 212 | isa = PBXShellScriptBuildPhase; 213 | buildActionMask = 2147483647; 214 | files = ( 215 | ); 216 | inputFileListPaths = ( 217 | ); 218 | inputPaths = ( 219 | ); 220 | outputFileListPaths = ( 221 | ); 222 | outputPaths = ( 223 | ); 224 | runOnlyForDeploymentPostprocessing = 0; 225 | shellPath = /bin/sh; 226 | shellScript = "for framework in $(find $CODESIGNING_FOLDER_PATH -name '*.framework'); do\n codesign --force --deep --sign \"${EXPANDED_CODE_SIGN_IDENTITY}\" --preserve-metadata=identifier,entitlements --timestamp=none \"$framework\"\ndone\n"; 227 | }; 228 | /* End PBXShellScriptBuildPhase section */ 229 | 230 | /* Begin PBXSourcesBuildPhase section */ 231 | 78C1EAE62524A507000EEC2C /* Sources */ = { 232 | isa = PBXSourcesBuildPhase; 233 | buildActionMask = 2147483647; 234 | files = ( 235 | 78C1EB222524B5E6000EEC2C /* BarButtonWatcher.swift in Sources */, 236 | 78C1EB192524AE0D000EEC2C /* PageLabel.swift in Sources */, 237 | 78C1EAEE2524A507000EEC2C /* PDFViewerApp.swift in Sources */, 238 | 78C1EB1B2524AFB8000EEC2C /* PDFViewConfiguration.swift in Sources */, 239 | 78C1EB1D2524B2E6000EEC2C /* PDFViewActions.swift in Sources */, 240 | 78C1EB012524A6B0000EEC2C /* PDFView.swift in Sources */, 241 | 78C1EB122524AABE000EEC2C /* PDFViewCoordinator.swift in Sources */, 242 | 78C1EB092524A947000EEC2C /* PDFExtensions.swift in Sources */, 243 | 78C1EB262524B99B000EEC2C /* PDFViewDelegates.swift in Sources */, 244 | 78C1EAF02524A507000EEC2C /* PDFViewerDocument.swift in Sources */, 245 | 78C1EAF22524A507000EEC2C /* ContentView.swift in Sources */, 246 | 78C1EB242524B799000EEC2C /* AnchorButton.swift in Sources */, 247 | ); 248 | runOnlyForDeploymentPostprocessing = 0; 249 | }; 250 | /* End PBXSourcesBuildPhase section */ 251 | 252 | /* Begin XCBuildConfiguration section */ 253 | 78C1EAF92524A508000EEC2C /* Debug */ = { 254 | isa = XCBuildConfiguration; 255 | buildSettings = { 256 | ALWAYS_SEARCH_USER_PATHS = NO; 257 | CLANG_ANALYZER_NONNULL = YES; 258 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 259 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 260 | CLANG_CXX_LIBRARY = "libc++"; 261 | CLANG_ENABLE_MODULES = YES; 262 | CLANG_ENABLE_OBJC_ARC = YES; 263 | CLANG_ENABLE_OBJC_WEAK = YES; 264 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 265 | CLANG_WARN_BOOL_CONVERSION = YES; 266 | CLANG_WARN_COMMA = YES; 267 | CLANG_WARN_CONSTANT_CONVERSION = YES; 268 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 269 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 270 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 271 | CLANG_WARN_EMPTY_BODY = YES; 272 | CLANG_WARN_ENUM_CONVERSION = YES; 273 | CLANG_WARN_INFINITE_RECURSION = YES; 274 | CLANG_WARN_INT_CONVERSION = YES; 275 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 276 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 277 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 278 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 279 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 280 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 281 | CLANG_WARN_STRICT_PROTOTYPES = YES; 282 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 283 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 284 | CLANG_WARN_UNREACHABLE_CODE = YES; 285 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 286 | COPY_PHASE_STRIP = NO; 287 | DEBUG_INFORMATION_FORMAT = dwarf; 288 | ENABLE_STRICT_OBJC_MSGSEND = YES; 289 | ENABLE_TESTABILITY = YES; 290 | GCC_C_LANGUAGE_STANDARD = gnu11; 291 | GCC_DYNAMIC_NO_PIC = NO; 292 | GCC_NO_COMMON_BLOCKS = YES; 293 | GCC_OPTIMIZATION_LEVEL = 0; 294 | GCC_PREPROCESSOR_DEFINITIONS = ( 295 | "DEBUG=1", 296 | "$(inherited)", 297 | ); 298 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 299 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 300 | GCC_WARN_UNDECLARED_SELECTOR = YES; 301 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 302 | GCC_WARN_UNUSED_FUNCTION = YES; 303 | GCC_WARN_UNUSED_VARIABLE = YES; 304 | IPHONEOS_DEPLOYMENT_TARGET = 14.2; 305 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 306 | MTL_FAST_MATH = YES; 307 | ONLY_ACTIVE_ARCH = YES; 308 | SDKROOT = iphoneos; 309 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 310 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 311 | }; 312 | name = Debug; 313 | }; 314 | 78C1EAFA2524A508000EEC2C /* Release */ = { 315 | isa = XCBuildConfiguration; 316 | buildSettings = { 317 | ALWAYS_SEARCH_USER_PATHS = NO; 318 | CLANG_ANALYZER_NONNULL = YES; 319 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 320 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 321 | CLANG_CXX_LIBRARY = "libc++"; 322 | CLANG_ENABLE_MODULES = YES; 323 | CLANG_ENABLE_OBJC_ARC = YES; 324 | CLANG_ENABLE_OBJC_WEAK = YES; 325 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 326 | CLANG_WARN_BOOL_CONVERSION = YES; 327 | CLANG_WARN_COMMA = YES; 328 | CLANG_WARN_CONSTANT_CONVERSION = YES; 329 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 330 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 331 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 332 | CLANG_WARN_EMPTY_BODY = YES; 333 | CLANG_WARN_ENUM_CONVERSION = YES; 334 | CLANG_WARN_INFINITE_RECURSION = YES; 335 | CLANG_WARN_INT_CONVERSION = YES; 336 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 337 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 338 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 339 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 340 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 341 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 342 | CLANG_WARN_STRICT_PROTOTYPES = YES; 343 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 344 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 345 | CLANG_WARN_UNREACHABLE_CODE = YES; 346 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 347 | COPY_PHASE_STRIP = NO; 348 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 349 | ENABLE_NS_ASSERTIONS = NO; 350 | ENABLE_STRICT_OBJC_MSGSEND = YES; 351 | GCC_C_LANGUAGE_STANDARD = gnu11; 352 | GCC_NO_COMMON_BLOCKS = YES; 353 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 354 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 355 | GCC_WARN_UNDECLARED_SELECTOR = YES; 356 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 357 | GCC_WARN_UNUSED_FUNCTION = YES; 358 | GCC_WARN_UNUSED_VARIABLE = YES; 359 | IPHONEOS_DEPLOYMENT_TARGET = 14.2; 360 | MTL_ENABLE_DEBUG_INFO = NO; 361 | MTL_FAST_MATH = YES; 362 | SDKROOT = iphoneos; 363 | SWIFT_COMPILATION_MODE = wholemodule; 364 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 365 | VALIDATE_PRODUCT = YES; 366 | }; 367 | name = Release; 368 | }; 369 | 78C1EAFC2524A508000EEC2C /* Debug */ = { 370 | isa = XCBuildConfiguration; 371 | buildSettings = { 372 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 373 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 374 | CODE_SIGN_ENTITLEMENTS = PDFViewer/PDFViewer.entitlements; 375 | CODE_SIGN_STYLE = Automatic; 376 | DEVELOPMENT_ASSET_PATHS = "\"PDFViewer/Preview Content\""; 377 | DEVELOPMENT_TEAM = ""; 378 | ENABLE_PREVIEWS = YES; 379 | INFOPLIST_FILE = PDFViewer/Info.plist; 380 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 381 | LD_RUNPATH_SEARCH_PATHS = ( 382 | "$(inherited)", 383 | "@executable_path/Frameworks", 384 | ); 385 | PRODUCT_BUNDLE_IDENTIFIER = com.steipete.PDFViewer; 386 | PRODUCT_NAME = "$(TARGET_NAME)"; 387 | SUPPORTS_MACCATALYST = YES; 388 | SWIFT_VERSION = 5.0; 389 | TARGETED_DEVICE_FAMILY = "1,2,6"; 390 | }; 391 | name = Debug; 392 | }; 393 | 78C1EAFD2524A508000EEC2C /* Release */ = { 394 | isa = XCBuildConfiguration; 395 | buildSettings = { 396 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 397 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 398 | CODE_SIGN_ENTITLEMENTS = PDFViewer/PDFViewer.entitlements; 399 | CODE_SIGN_STYLE = Automatic; 400 | DEVELOPMENT_ASSET_PATHS = "\"PDFViewer/Preview Content\""; 401 | DEVELOPMENT_TEAM = ""; 402 | ENABLE_PREVIEWS = YES; 403 | INFOPLIST_FILE = PDFViewer/Info.plist; 404 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 405 | LD_RUNPATH_SEARCH_PATHS = ( 406 | "$(inherited)", 407 | "@executable_path/Frameworks", 408 | ); 409 | PRODUCT_BUNDLE_IDENTIFIER = com.steipete.PDFViewer; 410 | PRODUCT_NAME = "$(TARGET_NAME)"; 411 | SUPPORTS_MACCATALYST = YES; 412 | SWIFT_VERSION = 5.0; 413 | TARGETED_DEVICE_FAMILY = "1,2,6"; 414 | }; 415 | name = Release; 416 | }; 417 | /* End XCBuildConfiguration section */ 418 | 419 | /* Begin XCConfigurationList section */ 420 | 78C1EAE52524A507000EEC2C /* Build configuration list for PBXProject "PDFViewer" */ = { 421 | isa = XCConfigurationList; 422 | buildConfigurations = ( 423 | 78C1EAF92524A508000EEC2C /* Debug */, 424 | 78C1EAFA2524A508000EEC2C /* Release */, 425 | ); 426 | defaultConfigurationIsVisible = 0; 427 | defaultConfigurationName = Release; 428 | }; 429 | 78C1EAFB2524A508000EEC2C /* Build configuration list for PBXNativeTarget "PDFViewer" */ = { 430 | isa = XCConfigurationList; 431 | buildConfigurations = ( 432 | 78C1EAFC2524A508000EEC2C /* Debug */, 433 | 78C1EAFD2524A508000EEC2C /* Release */, 434 | ); 435 | defaultConfigurationIsVisible = 0; 436 | defaultConfigurationName = Release; 437 | }; 438 | /* End XCConfigurationList section */ 439 | 440 | /* Begin XCRemoteSwiftPackageReference section */ 441 | 78C1EB0C2524A961000EEC2C /* XCRemoteSwiftPackageReference "PSPDFKit-SP" */ = { 442 | isa = XCRemoteSwiftPackageReference; 443 | repositoryURL = "https://github.com/PSPDFKit/PSPDFKit-SP"; 444 | requirement = { 445 | kind = upToNextMajorVersion; 446 | minimumVersion = 10.0.0; 447 | }; 448 | }; 449 | 78C1EB1E2524B5D9000EEC2C /* XCRemoteSwiftPackageReference "InterposeKit" */ = { 450 | isa = XCRemoteSwiftPackageReference; 451 | repositoryURL = "https://github.com/steipete/InterposeKit.git"; 452 | requirement = { 453 | kind = upToNextMajorVersion; 454 | minimumVersion = 0.0.2; 455 | }; 456 | }; 457 | /* End XCRemoteSwiftPackageReference section */ 458 | 459 | /* Begin XCSwiftPackageProductDependency section */ 460 | 78C1EB0D2524A961000EEC2C /* PSPDFKit */ = { 461 | isa = XCSwiftPackageProductDependency; 462 | package = 78C1EB0C2524A961000EEC2C /* XCRemoteSwiftPackageReference "PSPDFKit-SP" */; 463 | productName = PSPDFKit; 464 | }; 465 | 78C1EB1F2524B5D9000EEC2C /* InterposeKit */ = { 466 | isa = XCSwiftPackageProductDependency; 467 | package = 78C1EB1E2524B5D9000EEC2C /* XCRemoteSwiftPackageReference "InterposeKit" */; 468 | productName = InterposeKit; 469 | }; 470 | /* End XCSwiftPackageProductDependency section */ 471 | }; 472 | rootObject = 78C1EAE22524A507000EEC2C /* Project object */; 473 | } 474 | -------------------------------------------------------------------------------- /PDFViewer.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /PDFViewer.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /PDFViewer.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "object": { 3 | "pins": [ 4 | { 5 | "package": "InterposeKit", 6 | "repositoryURL": "https://github.com/steipete/InterposeKit.git", 7 | "state": { 8 | "branch": null, 9 | "revision": "17853ad69961a5114e25c60c3ce7600feac0eabd", 10 | "version": "0.0.2" 11 | } 12 | }, 13 | { 14 | "package": "PSPDFKit", 15 | "repositoryURL": "https://github.com/PSPDFKit/PSPDFKit-SP", 16 | "state": { 17 | "branch": null, 18 | "revision": "f5e430da0017148c2455a8bdabc4856a8494334b", 19 | "version": "10.0.0" 20 | } 21 | } 22 | ] 23 | }, 24 | "version": 1 25 | } 26 | -------------------------------------------------------------------------------- /PDFViewer/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PSPDFKit-labs/PDFViewerSwiftUI/a8bd4dd4e60336ab6eca14e7263a6700898f8cb2/PDFViewer/.DS_Store -------------------------------------------------------------------------------- /PDFViewer/Assets.xcassets/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PSPDFKit-labs/PDFViewerSwiftUI/a8bd4dd4e60336ab6eca14e7263a6700898f8cb2/PDFViewer/Assets.xcassets/.DS_Store -------------------------------------------------------------------------------- /PDFViewer/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /PDFViewer/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /PDFViewer/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /PDFViewer/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // PDFViewer 4 | // 5 | // Created by Peter Steinberger on 30.09.20. 6 | // 7 | 8 | import SwiftUI 9 | import PSPDFKit 10 | import PSPDFKitUI 11 | import Combine 12 | 13 | struct ContentView: View { 14 | @Binding var document: PDFViewerDocument 15 | @State var pageIndex = PageIndex(0) 16 | @State var viewMode = ViewMode.document 17 | @State var actions = PassthroughSubject() 18 | 19 | var body: some View { 20 | ZStack { 21 | PDFView(document: $document, 22 | pageIndex: $pageIndex, 23 | viewMode: $viewMode, 24 | actions: actions) 25 | .pageTransition(.scrollContinuous) 26 | .scrollDirection(.vertical) 27 | .updateConfiguration { 28 | $0.userInterfaceViewMode = .always 29 | } 30 | PageLabel(pageIndex: $pageIndex) 31 | }.toolbar { 32 | ToolbarItem(placement: .navigationBarTrailing) { 33 | AnchorButton { 34 | actions.send(.showOutline(sender: $0)) 35 | } label: { 36 | Image(systemName: "book") 37 | } 38 | } 39 | ToolbarItem(placement: .navigationBarTrailing) { 40 | if viewMode == .document { 41 | Button { 42 | viewMode = .thumbnails 43 | } label: { 44 | Image(systemName: "square.grid.2x2") 45 | } 46 | } else { 47 | Button { 48 | viewMode = .document 49 | } label: { 50 | Image(systemName: "square.grid.2x2.fill") 51 | } 52 | } 53 | } 54 | } 55 | .edgesIgnoringSafeArea(.all) 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /PDFViewer/Helpers/AnchorButton.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AnchorButton.swift 3 | // PDFViewer 4 | // 5 | // Created by Peter Steinberger on 30.09.20. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct AnchorButton: View { 11 | typealias Action = (_ sender: AnyObject?) -> Void 12 | let callback: Action 13 | var content: Content 14 | @StateObject private var viewWrapper = ViewWrapper(view: UIView(frame: .zero)) 15 | 16 | init(action: @escaping Action, @ViewBuilder label: () -> Content) { 17 | self.callback = action 18 | self.content = label() 19 | } 20 | 21 | var body: some View { 22 | return 23 | ZStack { 24 | InternalAnchorView(view: viewWrapper.view) 25 | Button { 26 | self.callback(BarButtonWatcher.lastBarButtonItem ?? viewWrapper.view) 27 | } label: { 28 | content 29 | } 30 | }.onAppear { 31 | // Lazy global needs access to init 32 | _ = BarButtonWatcher.shared 33 | } 34 | } 35 | 36 | private struct InternalAnchorView: UIViewRepresentable { 37 | var view: UIView 38 | func makeUIView(context: Self.Context) -> UIView { view } 39 | func updateUIView(_ uiView: UIView, context: Self.Context) {} 40 | } 41 | 42 | // View can't be directly stored as StateObject (not an observable object) 43 | private class ViewWrapper: ObservableObject { 44 | @Published var view: UIView 45 | 46 | init(view: UIView) { 47 | self.view = view 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /PDFViewer/Helpers/BarButtonWatcher.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BarButtonWatcher.swift 3 | // PDFViewer 4 | // 5 | // Created by Peter Steinberger on 30.09.20. 6 | // 7 | 8 | import Foundation 9 | import UIKit 10 | import InterposeKit 11 | 12 | final class BarButtonWatcher { 13 | static let shared = BarButtonWatcher() 14 | 15 | static private(set) weak var lastBarButtonItem: UIBarButtonItem? { 16 | didSet { 17 | // reset in next runloop 18 | if lastBarButtonItem != nil { 19 | DispatchQueue.main.async { self.lastBarButtonItem = nil } 20 | } 21 | } 22 | } 23 | 24 | init() { 25 | _ = try? UIApplication.shared.hook(#selector(UIApplication.sendAction(_:to:from:for:)), 26 | methodSignature: (@convention(c) (AnyObject, Selector, Selector, Any?, Any?, UIEvent?) -> Bool).self, 27 | hookSignature: (@convention(block) (AnyObject, Selector, Any?, Any?, UIEvent?) -> Bool).self) { 28 | store in { _self, action, target, sender, event in 29 | if let barButtonItem = sender as? UIBarButtonItem { 30 | BarButtonWatcher.lastBarButtonItem = barButtonItem 31 | } 32 | return store.original(_self, store.selector, action, target, sender, event) 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /PDFViewer/Helpers/PDFExtensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PDFViewControllerExtensions.swift 3 | // PDFViewer 4 | // 5 | // Created by Peter Steinberger on 27.09.20. 6 | // 7 | 8 | import Foundation 9 | import Combine 10 | import PSPDFKit 11 | import PSPDFKitUI 12 | 13 | func setupLicense() { 14 | #if targetEnvironment(macCatalyst) 15 | // Activate PSPDFKit for com.steipete.PDFViewer 16 | SDK.setLicenseKey("Vz05RE5y41+ihwqw0b/CWOtuUewY36mK6/qM/Rn6e3to5ikog3f13k4KHWs16kPPhYQ+txWMejVQaO4UQ+eB31ubJGTuffLIlzmtBJcEUeJfR/i75KGlZflRz2TNVrgt58CdOMudmZJjiGAT/dVuComzq4vDdH9zRFCSLlI3e+QZz9fZjyyar12RnWnhwfs9uls3kLRONGW3KFHVZLBSp0V94lTTQhb9rTtGAWtvwtZkJ3O8SlZ+o+Bvl3MkHziX66r40OqBDrADs8Iqz68jr79SwICC0JxO3Num3GOlUaxtqwceM1NCP8sN1sllO29wRfMYLzU4bObqe5MtsOyjHvk9WJ4dFOla+D0ciT9mLPIqVCA94K1kRfCqAXWy+UPhvvPa4AdvcWw+FAk12+WoSRES/49zGSHz8zaq3OePmv+aHHsxg3xWB7AzH16TAEeygSlHoJOZnIlhREPAmC2Y7zsNcF+LV0hP3ks8Ca3aFrGvzwJ4SXHytHybgTuIUe8qgaBx2Dz/WkABCk1v8abGMVy+6V0jEmFhrDt/cr2sho5OXj/Or5lrOvaDHpjIXR2CQPzkodrVukS3DE/7xhhoTes0CszpnGJjxtL5t8tnP06eQw+zMEYCiQiu/umtUAEWHkOSGjKiPAffmViWD454K5nSaIRXdRO3d/sOIDSMvh2KytomscNSKDhzbG+HJnuwCbfky/SY4blCG3khY4zuY3ScZGZtVQwvCnMiPYYhTIEtF2LS+6dztB1sxEOFoLzZ7ewomS11ifxRCP2sc6rd9d6nhRXFY9GYZa6RGCL4vfg=") 17 | #else 18 | // Activate PSPDFKit for iOS demo license key for com.steipete.PDFViewer until 31 Dec 2020 19 | SDK.setLicenseKey( 20 | "GL+yFH4O3yz85Aj8+411B5GEfPNbq5ybCfCctVUUAylfvpKpWDozApBPMBIKpi/qTNgSs8NvmIJNNqXLv1xFPpl9RZKdhD0Md9CbRfxoHSrpKxFczFwXtNbVVk++dRRsi9rjT+MmzDFT62N9RO60htQsMSUT7CQf+3E0Lha8RVE4U2zuYeFesiJJ7ClnZ9UCijmztHvFZbkw2+zAl3BzabXFXcMl+uz/XYXqHa/IIYhzQoW1U6VWVp6PkON0toRarqtRxgPYTibJX3P/GV1hhFlWW2MZm9PVrlHeRosGM4vyMLHp/XleAEw9ajs1oryFZsyIL5al+wipQhJ9cW60UVB8fSkaHWMt/XWDKsAArLR78cOXWtPS5JA4TSGnbDrcfyn4FfThVGbKrKpzkXth4uI8rtcqGhQdyYOlLH72Cwb583vDbS9A8P0+b86iE1WCtjJRV8xrHr5cu1JuZ97EKP2IeeNMKTW9eEMVgk2RfMC21fz/E1zbv1SZREMggI30qnCcy9ictU5TFGEaUduTLxGC/TUQIV1zxkDNa38xctDYZmvbvaSYikniAUZzv6MytKPFtHVSDSUjIEb7lp4BOXXwOG+Q51XtGAWSjXHXJE4LWdR9E9X5djTa9zy3F2WHxcyQb5KPXYjO5ETV1QNKOuEsYyAk2djGiU6KRD9B4qP9ccOc1fXuS2sBKaZxvHg0zYQPwusVnQbAkc9jtJKGbwR2hpTh+6Df/eDU7TMxH9oWwWFaoeqxyVZk9CY/UO+mKtzYx87JVeZh9XbDc1VrCJlx58dfyobXXL8cIFwVVQfXOsUGaA+PUd2nd8pYNo6KIlWGqkT7IchdIrYN55xw1JWQhgKw9wanyhO+H/7eh7vjUk4LRiVmp2j8HrkVvdMvpCC51zgk0/PRLpSndIsQAhj2C7jyHyyedvhPmdPQbk0=") 21 | #endif 22 | } 23 | 24 | public extension PDFViewController { 25 | /// A publisher that fires whenever the `pageIndex` changes. (Simplified) 26 | var pageIndexPublisher: AnyPublisher { 27 | NotificationCenter.default.publisher(for: .PSPDFDocumentViewControllerSpreadIndexDidChange, 28 | object: documentViewController) 29 | .compactMap { notification in 30 | let documentViewController = notification.object as! PDFDocumentViewController 31 | guard documentViewController == self.documentViewController, 32 | let spreadIndex = notification.userInfo!["PSPDFDocumentViewControllerSpreadIndexKey"] as? Int 33 | else { return nil } 34 | 35 | return PageIndex(documentViewController.layout.pageRangeForSpread(at: spreadIndex).location) 36 | }.eraseToAnyPublisher() 37 | } 38 | } 39 | 40 | public extension Document { 41 | /// Convenience initializer that takes data and checks it for validity. 42 | convenience init(data: Data) { 43 | self.init(dataProviders: [DataContainerProvider(data: data)]) 44 | } 45 | 46 | /// Change event to indicate addition, removal or change events. 47 | enum AnnotationChangeEvent { 48 | case added(anntations: [Annotation]) 49 | case removed(anntations: [Annotation]) 50 | case changed(anntations: [Annotation]) 51 | } 52 | 53 | /// Fires with an `AnnotationChangeEvent` whenever an annotation is added, removed or changed. 54 | var annotationChangePublisher: AnyPublisher { 55 | let filtered = { [weak self] (annotations: [Annotation]) -> [Annotation] in 56 | guard let self = self else { return [] } 57 | return annotations.filter { $0.document === self } 58 | } 59 | let addedPublisher = NotificationCenter.default.publisher(for: .PSPDFAnnotationsAdded, object: nil) 60 | .map { filtered($0.object as! [Annotation]) } 61 | .filter { !$0.isEmpty } 62 | .map { AnnotationChangeEvent.added(anntations: $0) } 63 | let removedPublisher = NotificationCenter.default.publisher(for: .PSPDFAnnotationsRemoved, object: nil) 64 | .map { filtered($0.object as! [Annotation]) } 65 | .filter { !$0.isEmpty } 66 | .map { AnnotationChangeEvent.removed(anntations: $0) } 67 | let changedPublisher = NotificationCenter.default.publisher(for: .PSPDFAnnotationChanged, object: nil) 68 | .map { filtered([$0.object as! Annotation]) } 69 | .filter { !$0.isEmpty } 70 | .map { AnnotationChangeEvent.changed(anntations: $0) } 71 | 72 | return Publishers.MergeMany(addedPublisher, removedPublisher, changedPublisher).eraseToAnyPublisher() 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /PDFViewer/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDocumentTypes 8 | 9 | 10 | CFBundleTypeRole 11 | Viewer 12 | LSItemContentTypes 13 | 14 | com.adobe.pdf 15 | 16 | NSUbiquitousDocumentUserActivityType 17 | $(PRODUCT_BUNDLE_IDENTIFIER).example-document 18 | 19 | 20 | CFBundleExecutable 21 | $(EXECUTABLE_NAME) 22 | CFBundleIdentifier 23 | $(PRODUCT_BUNDLE_IDENTIFIER) 24 | CFBundleInfoDictionaryVersion 25 | 6.0 26 | CFBundleName 27 | $(PRODUCT_NAME) 28 | CFBundlePackageType 29 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 30 | CFBundleShortVersionString 31 | 1.0 32 | CFBundleVersion 33 | 1 34 | LSApplicationCategoryType 35 | public.app-category.productivity 36 | LSRequiresIPhoneOS 37 | 38 | UIApplicationSceneManifest 39 | 40 | UIApplicationSupportsMultipleScenes 41 | 42 | 43 | UIApplicationSupportsIndirectInputEvents 44 | 45 | UILaunchScreen 46 | 47 | UIRequiredDeviceCapabilities 48 | 49 | armv7 50 | 51 | UISupportedInterfaceOrientations 52 | 53 | UIInterfaceOrientationPortrait 54 | UIInterfaceOrientationLandscapeLeft 55 | UIInterfaceOrientationLandscapeRight 56 | 57 | UISupportedInterfaceOrientations~ipad 58 | 59 | UIInterfaceOrientationPortrait 60 | UIInterfaceOrientationPortraitUpsideDown 61 | UIInterfaceOrientationLandscapeLeft 62 | UIInterfaceOrientationLandscapeRight 63 | 64 | UISupportsDocumentBrowser 65 | 66 | UTImportedTypeDeclarations 67 | 68 | 69 | UTTypeConformsTo 70 | 71 | public.plain-text 72 | 73 | UTTypeDescription 74 | Example Text 75 | UTTypeIdentifier 76 | com.example.plain-text 77 | UTTypeTagSpecification 78 | 79 | public.filename-extension 80 | 81 | exampletext 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /PDFViewer/PDFView/PDFView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PDFView.swift 3 | // PDFViewer 4 | // 5 | // Created by Peter Steinberger on 30.09.20. 6 | // 7 | 8 | import SwiftUI 9 | import PSPDFKit 10 | import PSPDFKitUI 11 | import Combine 12 | 13 | struct PDFView: UIViewControllerRepresentable { 14 | @Binding var document: PDFViewerDocument 15 | var pageIndexBinding: Binding? 16 | var viewModeBinding: Binding? 17 | var actionEventPublisher: PassthroughSubject? 18 | 19 | let baseConfiguration: PDFConfiguration 20 | var configurationModifiers = [((PDFConfigurationBuilder) -> Void)]() 21 | 22 | init(document: Binding, 23 | pageIndex: Binding? = nil, 24 | viewMode: Binding? = nil, 25 | actions: PassthroughSubject? = nil, 26 | configuration: PDFConfiguration = PDFConfiguration.default()) { 27 | _document = document 28 | pageIndexBinding = pageIndex 29 | viewModeBinding = viewMode 30 | baseConfiguration = configuration 31 | actionEventPublisher = actions 32 | } 33 | 34 | func makeUIViewController(context: Context) -> PDFViewController { 35 | PDFViewController(document: document.referencedDocument, configuration: baseConfiguration) 36 | } 37 | 38 | func updateUIViewController(_ controller: PDFViewController, context: Context) { 39 | controller.document = document.referencedDocument 40 | controller.delegate = context.coordinator 41 | if context.coordinator.pdfController != controller { 42 | context.coordinator.pdfController = controller 43 | } 44 | 45 | let newConfiguration = baseConfiguration.configurationUpdated { builder in 46 | configurationModifiers.forEach { $0(builder) } 47 | } 48 | if newConfiguration != controller.configuration { 49 | controller.updateConfiguration { builder in 50 | configurationModifiers.forEach { $0(builder) } 51 | } 52 | } 53 | 54 | if let viewModeBinding = viewModeBinding, controller.viewMode != viewModeBinding.wrappedValue { 55 | controller.setViewMode(viewModeBinding.wrappedValue, animated: true) 56 | } 57 | 58 | if let pageIndexBinding = pageIndexBinding, 59 | controller.pageIndex != pageIndexBinding.wrappedValue { 60 | controller.pageIndex = pageIndexBinding.wrappedValue 61 | } 62 | 63 | 64 | } 65 | 66 | func makeCoordinator() -> Coordinator { 67 | Coordinator(document: $document, pdfView: self) 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /PDFViewer/PDFView/PDFViewActions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PDFViewActions.swift 3 | // PDFViewer 4 | // 5 | // Created by Peter Steinberger on 30.09.20. 6 | // 7 | 8 | import Foundation 9 | import SwiftUI 10 | import PSPDFKit 11 | import PSPDFKitUI 12 | 13 | extension PDFView { 14 | 15 | enum ActionEvent { 16 | case showOutline(sender: AnyObject?) 17 | } 18 | 19 | static func execute(actionEvent: ActionEvent, controller: PDFViewController) { 20 | switch actionEvent { 21 | case .showOutline(let sender): 22 | _ = controller.outlineButtonItem.target?.perform(controller.outlineButtonItem.action!, with: sender) 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /PDFViewer/PDFView/PDFViewConfiguration.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PDFViewConfiguration.swift 3 | // PDFViewer 4 | // 5 | // Created by Peter Steinberger on 30.09.20. 6 | // 7 | 8 | import UIKit 9 | import SwiftUI 10 | import PSPDFKitUI 11 | 12 | extension PDFView { 13 | private func config(_ config: @escaping ((PDFConfigurationBuilder) -> Void)) -> Self { 14 | then({ $0.configurationModifiers.append(config) }) 15 | } 16 | 17 | /// Update arbitrary configuration properties via a `PDFConfigurationBuilder` closure. 18 | public func updateConfiguration(builder builderBlock: @escaping (PDFConfigurationBuilder) -> Void) -> Self { 19 | config({ builderBlock($0) }) 20 | } 21 | 22 | /// Defines the page transition. Defaults to `.scrollPerSpread`. 23 | public func pageTransition(_ pageTransition: PageTransition) -> Self { 24 | config({ $0.pageTransition = pageTransition }) 25 | } 26 | 27 | /// Page scrolling direction. Defaults to `.horizontal`. Only relevant for scrolling page transitions. 28 | public func scrollDirection(_ scrollDirection: ScrollDirection) -> Self { 29 | config({ $0.scrollDirection = scrollDirection }) 30 | } 31 | 32 | /// Background color behind the page view. 33 | public func backgroundColor(_ backgroundColor: UIColor) -> Self { 34 | config({ $0.backgroundColor = backgroundColor }) 35 | } 36 | } 37 | 38 | 39 | extension View { 40 | /// Helper to simplify the copy, mutate and return pattern. 41 | public func then(_ body: (inout Self) -> Void) -> Self { 42 | var result = self 43 | body(&result) 44 | return result 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /PDFViewer/PDFView/PDFViewCoordinator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PDFViewCoordinator.swift 3 | // PDFViewer 4 | // 5 | // Created by Peter Steinberger on 30.09.20. 6 | // 7 | 8 | import SwiftUI 9 | import PSPDFKit 10 | import PSPDFKitUI 11 | import Combine 12 | 13 | extension PDFView { 14 | class Coordinator: NSObject { 15 | @Binding var document: PDFViewerDocument 16 | var cancelSet = Set() 17 | var pdfView: PDFView 18 | 19 | weak var pdfController: PDFViewController? { 20 | didSet { 21 | // Bind page index publisher -> page index binding 22 | guard let controller = pdfController, oldValue != pdfController else { return } 23 | 24 | if let binding = pdfView.pageIndexBinding { 25 | controller.pageIndexPublisher.sink { pageIndex in 26 | DispatchQueue.main.async { 27 | binding.wrappedValue = pageIndex 28 | } 29 | }.store(in: &cancelSet) 30 | } 31 | 32 | if let actions = pdfView.actionEventPublisher { 33 | actions.sink { [weak controller] actionEvent in 34 | guard let controller = controller else { return } 35 | PDFView.execute(actionEvent: actionEvent, controller: controller) 36 | }.store(in: &cancelSet) 37 | } 38 | } 39 | } 40 | 41 | init(document: Binding, pdfView: PDFView) { 42 | _document = document 43 | self.pdfView = pdfView 44 | 45 | let referencedDocument = document.wrappedValue.referencedDocument 46 | referencedDocument.annotationChangePublisher.sink { _ in 47 | document.wrappedValue.referencedDocument = referencedDocument 48 | }.store(in: &cancelSet) 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /PDFViewer/PDFView/PDFViewDelegates.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PDFViewDelegates.swift 3 | // PDFViewer 4 | // 5 | // Created by Peter Steinberger on 30.09.20. 6 | // 7 | 8 | import Foundation 9 | import PSPDFKit 10 | import PSPDFKitUI 11 | 12 | extension PDFView.Coordinator: PDFViewControllerDelegate { 13 | 14 | func pdfViewController(_ pdfController: PDFViewController, didChange viewMode: ViewMode) { 15 | guard let binding = pdfView.viewModeBinding else { return } 16 | if binding.wrappedValue != viewMode { 17 | DispatchQueue.main.async { 18 | binding.wrappedValue = viewMode 19 | } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /PDFViewer/PDFViewer.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.files.user-selected.read-write 8 | 9 | com.apple.security.network.client 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /PDFViewer/PDFViewerApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PDFViewerApp.swift 3 | // PDFViewer 4 | // 5 | // Created by Peter Steinberger on 30.09.20. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @main 11 | struct PDFViewerApp: App { 12 | var body: some Scene { 13 | DocumentGroup(newDocument: PDFViewerDocument()) { file in 14 | ContentView(document: file.$document) 15 | .onAppear { setupLicense() } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /PDFViewer/PDFViewerDocument.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PDFViewerDocument.swift 3 | // PDFViewer 4 | // 5 | // Created by Peter Steinberger on 30.09.20. 6 | // 7 | 8 | import SwiftUI 9 | import UniformTypeIdentifiers 10 | import PSPDFKit 11 | 12 | struct PDFViewerDocument: FileDocument { 13 | var referencedDocument: Document 14 | 15 | init(data: Data = blankPDFData()) { 16 | self.referencedDocument = Document(data: data) 17 | } 18 | 19 | static var readableContentTypes: [UTType] { [.pdf] } 20 | 21 | init(configuration: ReadConfiguration) throws { 22 | guard let data = configuration.file.regularFileContents 23 | else { 24 | throw CocoaError(.fileReadCorruptFile) 25 | } 26 | self.referencedDocument = Document(data: data) 27 | } 28 | 29 | func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper { 30 | return .init(regularFileWithContents: referencedDocument.data!) 31 | } 32 | } 33 | 34 | private func blankPDFData() -> Data { 35 | let renderer = UIGraphicsPDFRenderer(bounds: CGRect(x: 0, y: 0, width: 210, height: 297), 36 | format: UIGraphicsPDFRendererFormat()) 37 | return renderer.pdfData { 38 | $0.beginPage() 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /PDFViewer/PageLabel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PageLabel.swift 3 | // PDFViewer 4 | // 5 | // Created by Peter Steinberger on 30.09.20. 6 | // 7 | 8 | import SwiftUI 9 | import PSPDFKit 10 | 11 | struct PageLabel: View { 12 | @Binding var pageIndex: PageIndex 13 | 14 | @Environment(\.colorScheme) var colorScheme 15 | @State var showOverlayTime = 2 16 | let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect() 17 | 18 | var body: some View { 19 | Text("Page \(pageIndex + 1)") 20 | .font(.largeTitle) 21 | .padding() 22 | .background(colorScheme == .dark ? Color.black : Color.white) 23 | .cornerRadius(25) 24 | .opacity(showOverlayTime == 0 ? 0 : 1) 25 | .scaleEffect(showOverlayTime == 0 ? 0.9 : 1) 26 | .blur(radius: showOverlayTime == 0 ? 3 : 0) 27 | .onChange(of: pageIndex) { newValue in 28 | showOverlayTime = 2 29 | } 30 | .onReceive(timer) { _ in 31 | if self.showOverlayTime > 0 { 32 | withAnimation(.easeInOut(duration: 0.3)) { 33 | self.showOverlayTime -= 1 34 | } 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /PDFViewer/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PDFViewer in SwiftUI 2 | 3 | A PDF Viewer built in SwiftUI and PSPDFKit for iOS 14 and macOS Big Sur. 4 | 5 | Requires Xcode 12 GM for iOS 14, recommended Xcode 12.2b2 or higher for macOS Big Sur. 6 | 7 | ## Talk at Swift Heroes Digital 2020 - Building a PDF Viewer in 40 Minutes - Peter Steinberger, PSPDFKit 8 | 9 | [![Swift Heroes Digital 2020 - Building a PDF Viewer in 40 Minutes - Peter Steinberger, PSPDFKit](https://img.youtube.com/vi/-IOs1Fx5t-I/0.jpg)](https://www.youtube.com/watch?v=-IOs1Fx5t-I) 10 | 11 | ## License 12 | 13 | See [LICENSE.md](LICENSE.md) 14 | --------------------------------------------------------------------------------