diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 8f9ff82..98cb3f5 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -1,6 +1,11 @@ name: Android -on: [push] +on: + push: + paths-ignore: + - '**.md' + - 'docs/**' + - 'extras/images/**' jobs: build: diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index 004d060..a4f7976 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -1,6 +1,11 @@ name: iOS -on: [push] +on: + push: + paths-ignore: + - '**.md' + - 'docs/**' + - 'extras/images/**' env: CMAKE_VERSION: "3.24.0" diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 475d711..d19d9a8 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -1,6 +1,11 @@ name: macOS -on: [push] +on: + push: + paths-ignore: + - '**.md' + - 'docs/**' + - 'extras/images/**' env: CMAKE_VERSION: "3.24.0" diff --git a/.github/workflows/wasm.yml b/.github/workflows/wasm.yml index 0ac47cb..a753a19 100644 --- a/.github/workflows/wasm.yml +++ b/.github/workflows/wasm.yml @@ -1,6 +1,11 @@ name: WASM -on: [push] +on: + push: + paths-ignore: + - '**.md' + - 'docs/**' + - 'extras/images/**' jobs: build: diff --git a/docs/BUILD_IOS.md b/docs/BUILD_IOS.md index d8b53c2..caf8054 100644 --- a/docs/BUILD_IOS.md +++ b/docs/BUILD_IOS.md @@ -2,20 +2,26 @@ 1. Execute all **general** steps -2. Get PDFium: -```python3 make.py build-pdfium-ios``` +2. Get PDFium: +```python3 make.py build-pdfium-ios``` -3. Patch: -```python3 make.py patch-ios``` +3. Patch: +```python3 make.py patch-ios``` -4. Compile: -```python3 make.py build-ios``` - -5. Install libraries: -```python3 make.py install-ios``` +4. Compile: +```python3 make.py build-ios``` -6. Test: -```python3 make.py test-ios``` +5. Install libraries: +```python3 make.py install-ios``` + +6. Test: +```python3 make.py test-ios``` Obs: -- The file **make.py** need be executed with python version 3. +- The file **make.py** need be executed with python version 3. + +# Sample + +The sample project is here: `sample-apple/Sample.xcodeproj`. + +Copy the `pdfium.xcframework` to folder `sample-apple/Sample/Vendor`. diff --git a/docs/BUILD_MACOS.md b/docs/BUILD_MACOS.md index 332ee3b..c13d7ab 100644 --- a/docs/BUILD_MACOS.md +++ b/docs/BUILD_MACOS.md @@ -2,20 +2,26 @@ 1. Execute all **general** steps -2. Get PDFium: -```python3 make.py build-pdfium-macos``` +2. Get PDFium: +```python3 make.py build-pdfium-macos``` -3. Patch: -```python3 make.py patch-macos``` +3. Patch: +```python3 make.py patch-macos``` -4. Compile: -```python3 make.py build-macos``` - -5. Install libraries: -```python3 make.py install-macos``` +4. Compile: +```python3 make.py build-macos``` -6. Test: -```python3 make.py test-macos``` +5. Install libraries: +```python3 make.py install-macos``` + +6. Test: +```python3 make.py test-macos``` Obs: -- The file **make.py** need be executed with python version 3. +- The file **make.py** need be executed with python version 3. + +# Sample + +The sample project is here: `sample-apple/Sample.xcodeproj`. + +Copy the `include` and `lib` dirs to folder `sample-apple/SampleMac/Vendor`. diff --git a/extras/wasm/template/index.html b/extras/wasm/template/index.html index 7dcc1c6..dc8f036 100644 --- a/extras/wasm/template/index.html +++ b/extras/wasm/template/index.html @@ -25,6 +25,7 @@ let autoOpenMode = true; let doc; let FPDF = {}; + let Module = null; // pdfium initialization Object.assign(FPDF, { @@ -279,7 +280,9 @@ } // runtime initialized - Module.onRuntimeInitialized = async _ => { + PDFiumModule().then(function (pdfiumModule) { + Module = pdfiumModule; + moduleLoaded = true; if (pageLoaded) { @@ -287,7 +290,7 @@ } checkIfEverythingWasLoaded(); - }; + }); // functions async function loadFile() { diff --git a/modules/config.py b/modules/config.py index 0ca9f8c..b63ba13 100644 --- a/modules/config.py +++ b/modules/config.py @@ -75,5 +75,5 @@ # wasm configurations_wasm = ["release"] targets_wasm = [ - {"target_os": "wasm", "target_cpu": "wasm", "pdfium_os": "wasm"}, + {"target_os": "wasm32", "target_cpu": "wasm", "pdfium_os": "wasm"}, ] diff --git a/modules/ios.py b/modules/ios.py index a2c08d2..343e91a 100644 --- a/modules/ios.py +++ b/modules/ios.py @@ -157,6 +157,7 @@ def run_task_build(): args.append("use_xcode_clang=true") args.append("pdf_is_complete_lib=true") args.append("use_custom_libcxx=false") + args.append("pdf_use_partition_alloc=false") if target["target_cpu"] == "arm64": args.append("enable_ios_bitcode=true") diff --git a/modules/wasm.py b/modules/wasm.py index c3d4ae4..9d6b9ee 100644 --- a/modules/wasm.py +++ b/modules/wasm.py @@ -11,14 +11,14 @@ # ----------------------------------------------------------------------------- def run_task_build_pdfium(): - p.get_pdfium_by_target("wasm") + p.get_pdfium_by_target("wasm32") # ----------------------------------------------------------------------------- def run_task_patch(): l.colored("Patching files...", l.YELLOW) - source_dir = os.path.join("build", "wasm", "pdfium") + source_dir = os.path.join("build", "wasm32", "pdfium") # build target source_file = os.path.join( @@ -450,7 +450,7 @@ def run_task_install(): # headers l.colored("Copying header files...", l.YELLOW) - include_dir = os.path.join("build", "wasm", "pdfium", "public") + include_dir = os.path.join("build", "wasm32", "pdfium", "public") include_cpp_dir = os.path.join(include_dir, "cpp") target_include_dir = os.path.join( "build", target["target_os"], target["target_cpu"], config, "include" @@ -620,16 +620,16 @@ def run_task_generate(): f.recreate_dir(gen_out_dir) - html_file = os.path.join( + output_file = os.path.join( gen_out_dir, - "pdfium.html", + "pdfium.js", ) command = [ "em++", "{0}".format("-g" if config == "debug" else "-O3"), "-o", - html_file, + output_file, "-s", 'EXPORTED_FUNCTIONS="$(node function-names ../xml/index.xml)"', "-s", @@ -649,6 +649,8 @@ def run_task_generate(): "ASSERTIONS=1", "-s", "ALLOW_MEMORY_GROWTH=1", + "-sMODULARIZE", + "-sEXPORT_NAME=PDFiumModule", "-std=c++11", "-Wall", "--no-entry", @@ -700,8 +702,8 @@ def run_task_publish(): l.colored("Publishing...", l.YELLOW) current_dir = f.current_dir() - publish_dir = os.path.join(current_dir, "build", "wasm", "publish") - node_dir = os.path.join(current_dir, "build", "wasm", "wasm", "release", "node") + publish_dir = os.path.join(current_dir, "build", "wasm32", "publish") + node_dir = os.path.join(current_dir, "build", "wasm32", "wasm", "release", "node") template_dir = os.path.join(current_dir, "extras", "wasm", "template") # copy generated files @@ -723,8 +725,8 @@ def run_task_publish_to_web(): l.colored("Publishing...", l.YELLOW) current_dir = os.getcwd() - publish_dir = os.path.join(current_dir, "build", "wasm", "publish") - node_dir = os.path.join(current_dir, "build", "wasm", "wasm", "release", "node") + publish_dir = os.path.join(current_dir, "build", "wasm32", "publish") + node_dir = os.path.join(current_dir, "build", "wasm32", "wasm", "release", "node") template_dir = os.path.join(current_dir, "extras", "wasm", "template") # copy generated files diff --git a/sample-apple/.gitignore b/sample-apple/.gitignore new file mode 100644 index 0000000..119be1d --- /dev/null +++ b/sample-apple/.gitignore @@ -0,0 +1,33 @@ +# trash +.DS_Store +Thumbs.db + +# xcode +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate + +# intelliJ +.idea +*.iml + +# misc +/Fastlane/*.xml +/Fastlane/*.md +/Carthage +/Pods +Podfile.lock +Gemfile.lock diff --git a/sample-apple/Sample.xcodeproj/project.pbxproj b/sample-apple/Sample.xcodeproj/project.pbxproj new file mode 100644 index 0000000..de095f8 --- /dev/null +++ b/sample-apple/Sample.xcodeproj/project.pbxproj @@ -0,0 +1,599 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 52; + objects = { + +/* Begin PBXBuildFile section */ + 3A402E96291AF30B00CF761C /* pdfium.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A8617A5291AEE3B008937AF /* pdfium.xcframework */; }; + 3A402E97291AF30B00CF761C /* pdfium.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3A8617A5291AEE3B008937AF /* pdfium.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 3A8617AB291AEEA2008937AF /* sample-file.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 3A8617AA291AEEA2008937AF /* sample-file.pdf */; }; + 3A8617AC291AEEA2008937AF /* sample-file.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 3A8617AA291AEEA2008937AF /* sample-file.pdf */; }; + 3A8617AD291AEFB7008937AF /* libpdfium.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A8617A4291AEE23008937AF /* libpdfium.a */; }; + 4444765222F301EE0039F1D9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4444765122F301EE0039F1D9 /* AppDelegate.swift */; }; + 4444765422F301EE0039F1D9 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4444765322F301EE0039F1D9 /* ViewController.swift */; }; + 4444765722F301EE0039F1D9 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4444765522F301EE0039F1D9 /* Main.storyboard */; }; + 4444765922F301EF0039F1D9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4444765822F301EF0039F1D9 /* Assets.xcassets */; }; + 4444765C22F301EF0039F1D9 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4444765A22F301EF0039F1D9 /* LaunchScreen.storyboard */; }; + 4444768722F30EE50039F1D9 /* libc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 4444768622F30EE50039F1D9 /* libc++.tbd */; }; + 447E227125B7934900C10BDA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 447E227025B7934900C10BDA /* AppDelegate.swift */; }; + 447E227325B7934900C10BDA /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 447E227225B7934900C10BDA /* ViewController.swift */; }; + 447E227525B7934A00C10BDA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 447E227425B7934A00C10BDA /* Assets.xcassets */; }; + 447E227825B7934A00C10BDA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 447E227625B7934A00C10BDA /* Main.storyboard */; }; + 4485B46E233977A8004FBE11 /* VDPDFDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4485B46D233977A8004FBE11 /* VDPDFDocument.swift */; }; + 4485B470233977B7004FBE11 /* VDPDFPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4485B46F233977B7004FBE11 /* VDPDFPage.swift */; }; + 4487EF2B233BC6BB0025E3AE /* PDFiumPage.m in Sources */ = {isa = PBXBuildFile; fileRef = 4485B36023391C28004FBE11 /* PDFiumPage.m */; }; + 4487EF45233BC6C90025E3AE /* PDFiumDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 4487EF2C233BC6C80025E3AE /* PDFiumDocument.m */; }; + 44A8967025B794940055A34F /* PDFiumDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 4487EF2C233BC6C80025E3AE /* PDFiumDocument.m */; }; + 44A8967325B794970055A34F /* PDFiumPage.m in Sources */ = {isa = PBXBuildFile; fileRef = 4485B36023391C28004FBE11 /* PDFiumPage.m */; }; + 44A8967625B794990055A34F /* VDPDFPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4485B46F233977B7004FBE11 /* VDPDFPage.swift */; }; + 44A8967925B7949C0055A34F /* VDPDFDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4485B46D233977A8004FBE11 /* VDPDFDocument.swift */; }; + 44C30471233521B500067743 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 4444768422F30E3C0039F1D9 /* libz.tbd */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 3A402E98291AF30B00CF761C /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 3A402E97291AF30B00CF761C /* pdfium.xcframework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 3A402E92291AF2F600CF761C /* libpdfium.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libpdfium.dylib; path = "../../../../../Downloads/pdfium-ios-arm64/lib/libpdfium.dylib"; sourceTree = ""; }; + 3A8617A4291AEE23008937AF /* libpdfium.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libpdfium.a; path = SampleMac/Vendor/lib/libpdfium.a; sourceTree = ""; }; + 3A8617A5291AEE3B008937AF /* pdfium.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = pdfium.xcframework; path = Sample/Vendor/pdfium.xcframework; sourceTree = ""; }; + 3A8617A9291AEE82008937AF /* Sample-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Sample-Bridging-Header.h"; sourceTree = ""; }; + 3A8617AA291AEEA2008937AF /* sample-file.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = "sample-file.pdf"; sourceTree = ""; }; + 4444764E22F301EE0039F1D9 /* Sample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Sample.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 4444765122F301EE0039F1D9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 4444765322F301EE0039F1D9 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 4444765622F301EE0039F1D9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 4444765822F301EF0039F1D9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 4444765B22F301EF0039F1D9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 4444765D22F301EF0039F1D9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 4444768422F30E3C0039F1D9 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; + 4444768622F30EE50039F1D9 /* libc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libc++.tbd"; path = "usr/lib/libc++.tbd"; sourceTree = SDKROOT; }; + 447E226E25B7934900C10BDA /* SampleMac.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SampleMac.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 447E227025B7934900C10BDA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 447E227225B7934900C10BDA /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 447E227425B7934A00C10BDA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 447E227725B7934A00C10BDA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 447E227925B7934A00C10BDA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 4485B35F23391C28004FBE11 /* PDFiumPage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PDFiumPage.h; sourceTree = ""; }; + 4485B36023391C28004FBE11 /* PDFiumPage.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PDFiumPage.m; sourceTree = ""; }; + 4485B46D233977A8004FBE11 /* VDPDFDocument.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VDPDFDocument.swift; sourceTree = ""; }; + 4485B46F233977B7004FBE11 /* VDPDFPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VDPDFPage.swift; sourceTree = ""; }; + 4487EF2C233BC6C80025E3AE /* PDFiumDocument.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PDFiumDocument.m; sourceTree = ""; }; + 4487EF44233BC6C90025E3AE /* PDFiumDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PDFiumDocument.h; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 4444764B22F301EE0039F1D9 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 44C30471233521B500067743 /* libz.tbd in Frameworks */, + 3A402E96291AF30B00CF761C /* pdfium.xcframework in Frameworks */, + 4444768722F30EE50039F1D9 /* libc++.tbd in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 447E226B25B7934900C10BDA /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 3A8617AD291AEFB7008937AF /* libpdfium.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 4444764522F301EE0039F1D9 = { + isa = PBXGroup; + children = ( + 4444765022F301EE0039F1D9 /* Sample */, + 447E226F25B7934900C10BDA /* SampleMac */, + 4444764F22F301EE0039F1D9 /* Products */, + 4444768322F30E3C0039F1D9 /* Frameworks */, + ); + sourceTree = ""; + }; + 4444764F22F301EE0039F1D9 /* Products */ = { + isa = PBXGroup; + children = ( + 4444764E22F301EE0039F1D9 /* Sample.app */, + 447E226E25B7934900C10BDA /* SampleMac.app */, + ); + name = Products; + sourceTree = ""; + }; + 4444765022F301EE0039F1D9 /* Sample */ = { + isa = PBXGroup; + children = ( + 4444765122F301EE0039F1D9 /* AppDelegate.swift */, + 4444765822F301EF0039F1D9 /* Assets.xcassets */, + 4444765D22F301EF0039F1D9 /* Info.plist */, + 4444765A22F301EF0039F1D9 /* LaunchScreen.storyboard */, + 4444765522F301EE0039F1D9 /* Main.storyboard */, + 4487EF47233BD5B40025E3AE /* PDFium */, + 3A8617A9291AEE82008937AF /* Sample-Bridging-Header.h */, + 3A8617AA291AEEA2008937AF /* sample-file.pdf */, + 4444765322F301EE0039F1D9 /* ViewController.swift */, + ); + path = Sample; + sourceTree = ""; + }; + 4444768322F30E3C0039F1D9 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 3A402E92291AF2F600CF761C /* libpdfium.dylib */, + 3A8617A5291AEE3B008937AF /* pdfium.xcframework */, + 3A8617A4291AEE23008937AF /* libpdfium.a */, + 4444768622F30EE50039F1D9 /* libc++.tbd */, + 4444768422F30E3C0039F1D9 /* libz.tbd */, + ); + name = Frameworks; + sourceTree = ""; + }; + 447E226F25B7934900C10BDA /* SampleMac */ = { + isa = PBXGroup; + children = ( + 447E227025B7934900C10BDA /* AppDelegate.swift */, + 447E227425B7934A00C10BDA /* Assets.xcassets */, + 447E227925B7934A00C10BDA /* Info.plist */, + 447E227625B7934A00C10BDA /* Main.storyboard */, + 447E227225B7934900C10BDA /* ViewController.swift */, + ); + path = SampleMac; + sourceTree = ""; + }; + 4487EF47233BD5B40025E3AE /* PDFium */ = { + isa = PBXGroup; + children = ( + 4487EF44233BC6C90025E3AE /* PDFiumDocument.h */, + 4487EF2C233BC6C80025E3AE /* PDFiumDocument.m */, + 4485B35F23391C28004FBE11 /* PDFiumPage.h */, + 4485B36023391C28004FBE11 /* PDFiumPage.m */, + 4485B46D233977A8004FBE11 /* VDPDFDocument.swift */, + 4485B46F233977B7004FBE11 /* VDPDFPage.swift */, + ); + path = PDFium; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 4444764D22F301EE0039F1D9 /* Sample */ = { + isa = PBXNativeTarget; + buildConfigurationList = 4444766022F301EF0039F1D9 /* Build configuration list for PBXNativeTarget "Sample" */; + buildPhases = ( + 4444764A22F301EE0039F1D9 /* Sources */, + 4444764B22F301EE0039F1D9 /* Frameworks */, + 4444764C22F301EE0039F1D9 /* Resources */, + 3A402E98291AF30B00CF761C /* Embed Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Sample; + productName = Sample; + productReference = 4444764E22F301EE0039F1D9 /* Sample.app */; + productType = "com.apple.product-type.application"; + }; + 447E226D25B7934900C10BDA /* SampleMac */ = { + isa = PBXNativeTarget; + buildConfigurationList = 447E227D25B7934A00C10BDA /* Build configuration list for PBXNativeTarget "SampleMac" */; + buildPhases = ( + 447E226A25B7934900C10BDA /* Sources */, + 447E226B25B7934900C10BDA /* Frameworks */, + 447E226C25B7934900C10BDA /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = SampleMac; + productName = SampleMac; + productReference = 447E226E25B7934900C10BDA /* SampleMac.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 4444764622F301EE0039F1D9 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1230; + LastUpgradeCheck = 1020; + ORGANIZATIONNAME = ""; + TargetAttributes = { + 4444764D22F301EE0039F1D9 = { + CreatedOnToolsVersion = 10.2.1; + LastSwiftMigration = 1020; + }; + 447E226D25B7934900C10BDA = { + CreatedOnToolsVersion = 12.3; + }; + }; + }; + buildConfigurationList = 4444764922F301EE0039F1D9 /* Build configuration list for PBXProject "Sample" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 4444764522F301EE0039F1D9; + productRefGroup = 4444764F22F301EE0039F1D9 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 4444764D22F301EE0039F1D9 /* Sample */, + 447E226D25B7934900C10BDA /* SampleMac */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 4444764C22F301EE0039F1D9 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4444765C22F301EF0039F1D9 /* LaunchScreen.storyboard in Resources */, + 3A8617AB291AEEA2008937AF /* sample-file.pdf in Resources */, + 4444765922F301EF0039F1D9 /* Assets.xcassets in Resources */, + 4444765722F301EE0039F1D9 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 447E226C25B7934900C10BDA /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 447E227525B7934A00C10BDA /* Assets.xcassets in Resources */, + 3A8617AC291AEEA2008937AF /* sample-file.pdf in Resources */, + 447E227825B7934A00C10BDA /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 4444764A22F301EE0039F1D9 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4444765422F301EE0039F1D9 /* ViewController.swift in Sources */, + 4487EF2B233BC6BB0025E3AE /* PDFiumPage.m in Sources */, + 4444765222F301EE0039F1D9 /* AppDelegate.swift in Sources */, + 4487EF45233BC6C90025E3AE /* PDFiumDocument.m in Sources */, + 4485B46E233977A8004FBE11 /* VDPDFDocument.swift in Sources */, + 4485B470233977B7004FBE11 /* VDPDFPage.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 447E226A25B7934900C10BDA /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 44A8967025B794940055A34F /* PDFiumDocument.m in Sources */, + 44A8967325B794970055A34F /* PDFiumPage.m in Sources */, + 447E227325B7934900C10BDA /* ViewController.swift in Sources */, + 447E227125B7934900C10BDA /* AppDelegate.swift in Sources */, + 44A8967625B794990055A34F /* VDPDFPage.swift in Sources */, + 44A8967925B7949C0055A34F /* VDPDFDocument.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 4444765522F301EE0039F1D9 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 4444765622F301EE0039F1D9 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 4444765A22F301EF0039F1D9 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 4444765B22F301EF0039F1D9 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; + 447E227625B7934A00C10BDA /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 447E227725B7934A00C10BDA /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 4444765E22F301EF0039F1D9 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 12.3; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 4444765F22F301EF0039F1D9 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 12.3; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 4444766122F301EF0039F1D9 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 99AHAA343Q; + ENABLE_BITCODE = NO; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Sample/Vendor", + ); + HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/Sample/Vendor/pdfium.xcframework/ios-arm64/Headers"; + INFOPLIST_FILE = Sample/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + OTHER_CFLAGS = ""; + PRODUCT_BUNDLE_IDENTIFIER = com.paulocoutinho.pdfium; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG PDFIUM"; + SWIFT_OBJC_BRIDGING_HEADER = "Sample/Sample-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 4444766222F301EF0039F1D9 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 99AHAA343Q; + ENABLE_BITCODE = NO; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Sample/Vendor", + ); + HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/Sample/Vendor/pdfium.xcframework/ios-arm64/Headers"; + INFOPLIST_FILE = Sample/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + OTHER_CFLAGS = ""; + PRODUCT_BUNDLE_IDENTIFIER = com.paulocoutinho.pdfium; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Sample/Sample-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; + 447E227B25B7934A00C10BDA /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CODE_SIGN_ENTITLEMENTS = SampleMac/SampleMac.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_ASSET_PATHS = ""; + DEVELOPMENT_TEAM = 99AHAA343Q; + ENABLE_HARDENED_RUNTIME = YES; + HEADER_SEARCH_PATHS = SampleMac/Vendor/include; + INFOPLIST_FILE = SampleMac/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/SampleMac/Vendor/lib", + ); + MACOSX_DEPLOYMENT_TARGET = 11.1; + PRODUCT_BUNDLE_IDENTIFIER = com.paulocoutinho.pdfium; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_OBJC_BRIDGING_HEADER = "Sample/Sample-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 447E227C25B7934A00C10BDA /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CODE_SIGN_ENTITLEMENTS = SampleMac/SampleMac.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_ASSET_PATHS = ""; + DEVELOPMENT_TEAM = 99AHAA343Q; + ENABLE_HARDENED_RUNTIME = YES; + HEADER_SEARCH_PATHS = SampleMac/Vendor/include; + INFOPLIST_FILE = SampleMac/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/SampleMac/Vendor/lib", + ); + MACOSX_DEPLOYMENT_TARGET = 11.1; + PRODUCT_BUNDLE_IDENTIFIER = com.paulocoutinho.pdfium; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_OBJC_BRIDGING_HEADER = "Sample/Sample-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 4444764922F301EE0039F1D9 /* Build configuration list for PBXProject "Sample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4444765E22F301EF0039F1D9 /* Debug */, + 4444765F22F301EF0039F1D9 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 4444766022F301EF0039F1D9 /* Build configuration list for PBXNativeTarget "Sample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4444766122F301EF0039F1D9 /* Debug */, + 4444766222F301EF0039F1D9 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 447E227D25B7934A00C10BDA /* Build configuration list for PBXNativeTarget "SampleMac" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 447E227B25B7934A00C10BDA /* Debug */, + 447E227C25B7934A00C10BDA /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 4444764622F301EE0039F1D9 /* Project object */; +} diff --git a/sample-apple/Sample.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/sample-apple/Sample.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..6aed140 --- /dev/null +++ b/sample-apple/Sample.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/sample-apple/Sample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/sample-apple/Sample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/sample-apple/Sample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/sample-apple/Sample.xcodeproj/xcshareddata/xcschemes/Sample.xcscheme b/sample-apple/Sample.xcodeproj/xcshareddata/xcschemes/Sample.xcscheme new file mode 100644 index 0000000..18afab6 --- /dev/null +++ b/sample-apple/Sample.xcodeproj/xcshareddata/xcschemes/Sample.xcscheme @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sample-apple/Sample/AppDelegate.swift b/sample-apple/Sample/AppDelegate.swift new file mode 100644 index 0000000..e7b46dd --- /dev/null +++ b/sample-apple/Sample/AppDelegate.swift @@ -0,0 +1,37 @@ +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + var window: UIWindow? + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + func applicationWillResignActive(_ application: UIApplication) { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. + } + + func applicationDidEnterBackground(_ application: UIApplication) { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. + } + + func applicationWillEnterForeground(_ application: UIApplication) { + // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. + } + + func applicationDidBecomeActive(_ application: UIApplication) { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + } + + func applicationWillTerminate(_ application: UIApplication) { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. + } + + +} + diff --git a/sample-apple/Sample/Assets.xcassets/AppIcon.appiconset/Contents.json b/sample-apple/Sample/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..d8db8d6 --- /dev/null +++ b/sample-apple/Sample/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/sample-apple/Sample/Assets.xcassets/Contents.json b/sample-apple/Sample/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/sample-apple/Sample/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/sample-apple/Sample/Base.lproj/LaunchScreen.storyboard b/sample-apple/Sample/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..bfa3612 --- /dev/null +++ b/sample-apple/Sample/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sample-apple/Sample/Base.lproj/Main.storyboard b/sample-apple/Sample/Base.lproj/Main.storyboard new file mode 100644 index 0000000..f1bcf38 --- /dev/null +++ b/sample-apple/Sample/Base.lproj/Main.storyboard @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sample-apple/Sample/Info.plist b/sample-apple/Sample/Info.plist new file mode 100644 index 0000000..16be3b6 --- /dev/null +++ b/sample-apple/Sample/Info.plist @@ -0,0 +1,45 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/sample-apple/Sample/PDFium/PDFiumDocument.h b/sample-apple/Sample/PDFium/PDFiumDocument.h new file mode 100644 index 0000000..00e999e --- /dev/null +++ b/sample-apple/Sample/PDFium/PDFiumDocument.h @@ -0,0 +1,16 @@ +@import Foundation; + +#import "fpdf_doc.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface PDFiumDocument : NSObject + +@property (nullable, nonatomic) FPDF_DOCUMENT pdfiumDocumentRef; +@property (nonatomic) int pageCount; + +- (instancetype _Nullable) initWithURL:(NSURL * _Nonnull)url password:(NSString* _Nullable) password; + +@end + +NS_ASSUME_NONNULL_END diff --git a/sample-apple/Sample/PDFium/PDFiumDocument.m b/sample-apple/Sample/PDFium/PDFiumDocument.m new file mode 100644 index 0000000..59e40eb --- /dev/null +++ b/sample-apple/Sample/PDFium/PDFiumDocument.m @@ -0,0 +1,34 @@ +#import "PDFiumDocument.h" +#import "fpdf_doc.h" + +@implementation PDFiumDocument { +} + ++ (void)initialize { + static dispatch_once_t onceToken = 0; + dispatch_once(&onceToken, ^{ + FPDF_LIBRARY_CONFIG config; + config.version = 2; + config.m_pUserFontPaths = NULL; + config.m_pIsolate = NULL; + config.m_v8EmbedderSlot = 0; + FPDF_InitLibraryWithConfig(&config); + }); +} + +- (instancetype _Nullable) initWithURL:(NSURL * _Nonnull)url password:(NSString* _Nullable) password { + FPDF_STRING cpath = (char*) url.path.UTF8String; + FPDF_STRING cpassword = (char*) password.UTF8String; + _pdfiumDocumentRef = FPDF_LoadDocument(cpath, cpassword); + if (_pdfiumDocumentRef == nil) { + return nil; + } + _pageCount = FPDF_GetPageCount(_pdfiumDocumentRef); + return self; +} + +- (void)dealloc { + FPDF_CloseDocument(_pdfiumDocumentRef); +} + +@end diff --git a/sample-apple/Sample/PDFium/PDFiumPage.h b/sample-apple/Sample/PDFium/PDFiumPage.h new file mode 100644 index 0000000..6e02d3b --- /dev/null +++ b/sample-apple/Sample/PDFium/PDFiumPage.h @@ -0,0 +1,27 @@ +@import Foundation; +@import CoreGraphics; + +NS_ASSUME_NONNULL_BEGIN + +@class PDFiumDocument; + +@interface PDFiumPage: NSObject + +@property (nonatomic) NSInteger index; +@property (nonatomic) NSInteger charCount; +@property (nonatomic, readonly) CGRect boundingBox; +@property (nonatomic, readonly) CGRect cropBox; +@property (nonatomic, readonly) CGRect mediaBox; +@property (nonatomic, readonly, nonnull) NSString* text; +@property (nonatomic, readonly, nonnull) NSString* rawText; + +- (instancetype _Nullable) initWithDocument:(PDFiumDocument* _Nonnull) document pageIndex:(NSInteger) pageIndex; +- (NSString* _Nonnull) textInRect:(CGRect) rect; +- (NSUInteger) textLocationFromPoint:(CGPoint) pagePoint tolerance: (double) tolerance; +- (CGRect) rectForCharacterIndex: (NSInteger) textIndex; +- (CGFloat) fontSizeForCharacterIndex: (NSInteger) textIndex; +- (NSArray* _Nonnull) rectsForTextRange: (NSRange) range; + +@end + +NS_ASSUME_NONNULL_END diff --git a/sample-apple/Sample/PDFium/PDFiumPage.m b/sample-apple/Sample/PDFium/PDFiumPage.m new file mode 100644 index 0000000..90fa1ed --- /dev/null +++ b/sample-apple/Sample/PDFium/PDFiumPage.m @@ -0,0 +1,159 @@ +#import "PDFiumPage.h" +#import "PDFiumDocument.h" +#import "fpdf_text.h" +#import "fpdf_transformpage.h" + +@interface PDFiumPage() + +@end + + +@implementation PDFiumPage { + PDFiumDocument* _document; + FPDF_PAGE _pdfiumPageRef; + FPDF_TEXTPAGE _pdfiumTextPageRef; + NSString* _rawText; + NSMutableString* _correctedText; +} + +- (instancetype _Nullable) initWithDocument:(PDFiumDocument* _Nonnull) document pageIndex:(NSInteger) pageIndex { + _document = document; + _index = pageIndex; + _pdfiumPageRef = FPDF_LoadPage(_document.pdfiumDocumentRef, (int) self.index); + if (_pdfiumPageRef == nil) { + return nil; + } + _pdfiumTextPageRef = FPDFText_LoadPage(_pdfiumPageRef); + if (_pdfiumTextPageRef == nil) { + return nil; + } + _charCount = FPDFText_CountChars(_pdfiumTextPageRef); + return self; +} + +- (void)dealloc { + if (_pdfiumPageRef) { + FPDF_ClosePage(_pdfiumPageRef); + } +} + +- (CGRect) boundingBox { + FS_RECTF fsRect; + if (FPDF_GetPageBoundingBox(_pdfiumPageRef, &fsRect)) { + CGRect rect = CGRectMake(fsRect.left, + fsRect.bottom, + fsRect.right - fsRect.left, + fsRect.top - fsRect.bottom); + return rect; + } + return CGRectNull; +} + +- (CGRect) cropbox { + float left, top, right, bottom; + if (FPDFPage_GetMediaBox(_pdfiumPageRef, &left, &bottom, &right, &top)) { + CGRect rect = CGRectMake(left, bottom, right-left, top-bottom); + return rect; + } + return CGRectNull; +} + +- (CGRect) mediabox { + float left, top, right, bottom; + if (FPDFPage_GetCropBox(_pdfiumPageRef, &left, &bottom, &right, &top)) { + CGRect rect = CGRectMake(left, bottom, right-left, top-bottom); + return rect; + } + return CGRectNull; +} + +- (NSString* _Nonnull) text { + if (_correctedText == nil) { + _correctedText = [self correctedStringFromOriginalString:self.rawText]; + } + return _correctedText; +} + +- (NSString* _Nonnull) rawText { + if (_rawText == nil) { + int charCount = FPDFText_CountChars(_pdfiumTextPageRef); + unsigned int bufferSize = (charCount+1)*2; + unsigned short* buffer = malloc(bufferSize); + FPDFText_GetText(_pdfiumTextPageRef, 0, charCount, buffer); + NSData* data = [NSData dataWithBytes:buffer length:bufferSize-1]; + _rawText = [[NSString alloc] initWithData:data encoding:NSUTF16LittleEndianStringEncoding]; + free(buffer); + if (_rawText == nil) + _rawText = @""; + } + return _rawText; +} + + +- (NSString* _Nonnull) textInRect:(CGRect) rect { + int charCount = FPDFText_GetBoundedText(_pdfiumTextPageRef, + rect.origin.x, + rect.origin.y + rect.size.height, + rect.origin.x + rect.size.width, + rect.origin.y, + NULL, 0); + unsigned int bufferSize = (charCount+1)*2; + unsigned short* buffer = malloc(bufferSize); + FPDFText_GetBoundedText(_pdfiumTextPageRef, + rect.origin.x, + rect.origin.y + rect.size.height, + rect.origin.x + rect.size.width, + rect.origin.y, + buffer, charCount); + NSData* data = [NSData dataWithBytes:buffer length:bufferSize-1]; + NSMutableString* text = [[NSMutableString alloc] initWithData:data encoding:NSUTF16LittleEndianStringEncoding]; + free(buffer); + return [self correctedStringFromOriginalString:text]; +} + +- (NSUInteger) textLocationFromPoint:(CGPoint) pagePoint tolerance: (double) tolerance { + int locationOnPage = FPDFText_GetCharIndexAtPos(_pdfiumTextPageRef, pagePoint.x, pagePoint.y, tolerance, tolerance); + if (locationOnPage == -1) + return NSNotFound; + return locationOnPage; +} + +- (CGRect) rectForCharacterIndex: (NSInteger) textIndex { + int originalIndex = (int) textIndex; + double left, top, right, bottom; + FPDFText_GetCharBox(_pdfiumTextPageRef, originalIndex, &left, &right, &bottom, &top); + CGRect rect = CGRectMake(left, bottom, right-left, top-bottom); + unichar ch = [_correctedText characterAtIndex:textIndex]; + if (ch == ' ' || ch == '\n') { + rect.size = CGSizeZero; + } + return rect; +} + +- (CGFloat) fontSizeForCharacterIndex: (NSInteger) textIndex { + double fontSize = FPDFText_GetFontSize(_pdfiumTextPageRef, (int) textIndex); + return fontSize; +} + +- (NSArray* _Nonnull) rectsForTextRange: (NSRange) range { + NSRange correctedRange =range; + int rectCount = FPDFText_CountRects(_pdfiumTextPageRef, (int) correctedRange.location, (int) correctedRange.length); + NSMutableArray* rects = [[NSMutableArray alloc] init]; + for (int rectIndex = 0; rectIndex < rectCount; rectIndex++) { + double left, top, right, bottom; + FPDFText_GetRect(_pdfiumTextPageRef, rectIndex, &left, &top, &right, &bottom); + CGRect rect = CGRectMake(left, bottom, right-left, top-bottom); + //[rects addObject:[NSValue valueWithCGRect:rect]]; + } + return rects; +} + +- (NSMutableString*) correctedStringFromOriginalString: (NSString*) originalString { + NSMutableString* correctedString = [NSMutableString stringWithString: originalString]; + [correctedString replaceOccurrencesOfString:@"\u00A0" withString:@" " options:NSLiteralSearch range:NSMakeRange(0, correctedString.length)]; + [correctedString replaceOccurrencesOfString:@"\uFFFE" withString:@"-" options:NSLiteralSearch range:NSMakeRange(0, correctedString.length)]; + [correctedString replaceOccurrencesOfString:@"\r\n" withString:@" \n" options:NSLiteralSearch range:NSMakeRange(0, correctedString.length)]; + return correctedString; +} + +@end diff --git a/sample-apple/Sample/PDFium/VDPDFDocument.swift b/sample-apple/Sample/PDFium/VDPDFDocument.swift new file mode 100644 index 0000000..0f1644f --- /dev/null +++ b/sample-apple/Sample/PDFium/VDPDFDocument.swift @@ -0,0 +1,44 @@ +import Foundation +import PDFKit + +class VDPDFDocument { + + var pkPDFDocument: PDFDocument + + var pdfiumDocument: PDFiumDocument + + var pages: [VDPDFPage] = [] + + var text: String { + var text: String = "" + for page in pages { + if let pageText = page.text { + text += pageText + text += "\n" + } + } + return text; + } + + var pageCount: Int { + return pkPDFDocument.pageCount + } + + init?(url: URL, password: String!) { + guard let pdfiumDocument = PDFiumDocument(url: url, password: password) else { + return nil + } + + guard let pkPDFDocument = PDFDocument(url: url) else { + return nil + } + + self.pdfiumDocument = pdfiumDocument + self.pkPDFDocument = pkPDFDocument + + for pageIndex in 0.. String { + let s1 = replacingOccurrences(of: "\n", with: "") + let s2 = s1.replacingOccurrences(of: " ", with: "") + //let s3 = s2.replacingOccurrences(of: "\u{FFFE}", with: "- \n") + return s2 + } + +} diff --git a/sample-apple/Sample/Sample-Bridging-Header.h b/sample-apple/Sample/Sample-Bridging-Header.h new file mode 100644 index 0000000..4f87a99 --- /dev/null +++ b/sample-apple/Sample/Sample-Bridging-Header.h @@ -0,0 +1,6 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + +#import "PDFiumPage.h" +#import "PDFiumDocument.h" diff --git a/sample-apple/Sample/Vendor/.gitignore b/sample-apple/Sample/Vendor/.gitignore new file mode 100644 index 0000000..bf27f31 --- /dev/null +++ b/sample-apple/Sample/Vendor/.gitignore @@ -0,0 +1,3 @@ +* +!.gitignore +!.gitkeep diff --git a/sample-apple/Sample/Vendor/.gitkeep b/sample-apple/Sample/Vendor/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/sample-apple/Sample/ViewController.swift b/sample-apple/Sample/ViewController.swift new file mode 100644 index 0000000..151e5ab --- /dev/null +++ b/sample-apple/Sample/ViewController.swift @@ -0,0 +1,49 @@ +import UIKit +import PDFKit + +class ViewController: UIViewController { + + var testFiles: [URL] = { + return [Bundle.main.url(forResource: "sample-file", withExtension: "pdf")!] + }() + + override func viewDidLoad() { + super.viewDidLoad() + runTest() + } + + func runTest() { + let start = DispatchTime.now() + let urls = testFiles + for url in urls { + autoreleasepool { + runPDFium(url) + } + } + let end = DispatchTime.now() + let nanoTime = end.uptimeNanoseconds - start.uptimeNanoseconds + let timeInterval = Double(nanoTime) / 1_000_000_000 + print("Total time: \(timeInterval)") + } + + func runPDFium(_ url: URL) { + if let pdfiumDoc = VDPDFDocument(url: url, password: nil) { + var text: String = "" + for page in pdfiumDoc.pages { + if let pageText = page.text { + text += "PAGE \(page.index)\n" + text += "TEXT START ----------------\n" + text += pageText + text += "\n" + text += "TEXT END ----------------\n" + text += "LAYOUT START ----------------\n" + text += "LAYOUT END ----------------\n" + page.cleanUp() + } + } + print(text) + } + } + +} + diff --git a/sample-apple/Sample/sample-file.pdf b/sample-apple/Sample/sample-file.pdf new file mode 100644 index 0000000..db7f50c Binary files /dev/null and b/sample-apple/Sample/sample-file.pdf differ diff --git a/sample-apple/SampleMac/AppDelegate.swift b/sample-apple/SampleMac/AppDelegate.swift new file mode 100644 index 0000000..f3c4171 --- /dev/null +++ b/sample-apple/SampleMac/AppDelegate.swift @@ -0,0 +1,15 @@ +import Cocoa + +@main +class AppDelegate: NSObject, NSApplicationDelegate { + + func applicationDidFinishLaunching(_ aNotification: Notification) { + // Insert code here to initialize your application + } + + func applicationWillTerminate(_ aNotification: Notification) { + // Insert code here to tear down your application + } + +} + diff --git a/sample-apple/SampleMac/Assets.xcassets/AccentColor.colorset/Contents.json b/sample-apple/SampleMac/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 0000000..eb87897 --- /dev/null +++ b/sample-apple/SampleMac/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/sample-apple/SampleMac/Assets.xcassets/AppIcon.appiconset/Contents.json b/sample-apple/SampleMac/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..3f00db4 --- /dev/null +++ b/sample-apple/SampleMac/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,58 @@ +{ + "images" : [ + { + "idiom" : "mac", + "scale" : "1x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "512x512" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "512x512" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/sample-apple/SampleMac/Assets.xcassets/Contents.json b/sample-apple/SampleMac/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/sample-apple/SampleMac/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/sample-apple/SampleMac/Base.lproj/Main.storyboard b/sample-apple/SampleMac/Base.lproj/Main.storyboard new file mode 100644 index 0000000..006dbe0 --- /dev/null +++ b/sample-apple/SampleMac/Base.lproj/Main.storyboard @@ -0,0 +1,718 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Default + + + + + + + Left to Right + + + + + + + Right to Left + + + + + + + + + + + Default + + + + + + + Left to Right + + + + + + + Right to Left + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sample-apple/SampleMac/Info.plist b/sample-apple/SampleMac/Info.plist new file mode 100644 index 0000000..076a442 --- /dev/null +++ b/sample-apple/SampleMac/Info.plist @@ -0,0 +1,32 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSHumanReadableCopyright + Copyright © 2022 Paulo Coutinho. All rights reserved. + NSMainStoryboardFile + Main + NSPrincipalClass + NSApplication + + diff --git a/sample-apple/SampleMac/SampleMac.entitlements b/sample-apple/SampleMac/SampleMac.entitlements new file mode 100644 index 0000000..f2ef3ae --- /dev/null +++ b/sample-apple/SampleMac/SampleMac.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + + + diff --git a/sample-apple/SampleMac/Vendor/.gitignore b/sample-apple/SampleMac/Vendor/.gitignore new file mode 100644 index 0000000..bf27f31 --- /dev/null +++ b/sample-apple/SampleMac/Vendor/.gitignore @@ -0,0 +1,3 @@ +* +!.gitignore +!.gitkeep diff --git a/sample-apple/SampleMac/Vendor/.gitkeep b/sample-apple/SampleMac/Vendor/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/sample-apple/SampleMac/ViewController.swift b/sample-apple/SampleMac/ViewController.swift new file mode 100644 index 0000000..5b06309 --- /dev/null +++ b/sample-apple/SampleMac/ViewController.swift @@ -0,0 +1,54 @@ +import Cocoa + +class ViewController: NSViewController { + + var testFiles: [URL] = { + return [Bundle.main.url(forResource: "sample-file", withExtension: "pdf")!] + }() + + override func viewDidLoad() { + super.viewDidLoad() + runTest() + } + + override var representedObject: Any? { + didSet { + // Update the view, if already loaded. + } + } + + func runTest() { + let start = DispatchTime.now() + let urls = testFiles + for url in urls { + autoreleasepool { + runPDFium(url) + } + } + let end = DispatchTime.now() + let nanoTime = end.uptimeNanoseconds - start.uptimeNanoseconds + let timeInterval = Double(nanoTime) / 1_000_000_000 + print("Total time: \(timeInterval)") + } + + func runPDFium(_ url: URL) { + if let pdfiumDoc = VDPDFDocument(url: url, password: nil) { + var text: String = "" + for page in pdfiumDoc.pages { + if let pageText = page.text { + text += "PAGE \(page.index)\n" + text += "TEXT START ----------------\n" + text += pageText + text += "\n" + text += "TEXT END ----------------\n" + text += "LAYOUT START ----------------\n" + text += "LAYOUT END ----------------\n" + page.cleanUp() + } + } + print(text) + } + } + +} +