@paperlet/react-native 0.0.0-stage → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/LICENSE +13 -0
  2. package/Paperlet.podspec +26 -0
  3. package/README.md +73 -2
  4. package/android/CMakeLists.txt +21 -0
  5. package/android/build.gradle +43 -0
  6. package/android/jniLibs/arm64-v8a/libpdfium.so +0 -0
  7. package/android/jniLibs/armeabi-v7a/libpdfium.so +0 -0
  8. package/android/jniLibs/x86_64/libpdfium.so +0 -0
  9. package/android/libs/arm64-v8a/libpaperlet_core.so +0 -0
  10. package/android/libs/armeabi-v7a/libpaperlet_core.so +0 -0
  11. package/android/libs/x86_64/libpaperlet_core.so +0 -0
  12. package/android/src/main/AndroidManifest.xml +1 -0
  13. package/android/src/main/cpp/cpp-adapter.cpp +8 -0
  14. package/android/src/main/java/com/paperlet/PaperletPackage.kt +20 -0
  15. package/cpp/Core.hpp +44 -0
  16. package/cpp/HybridPaperlet.cpp +63 -0
  17. package/cpp/HybridPaperlet.hpp +20 -0
  18. package/cpp/HybridPaperletDocument.cpp +98 -0
  19. package/cpp/HybridPaperletDocument.hpp +30 -0
  20. package/cpp/paperlet_core.h +29 -0
  21. package/ios/PaperletCore.xcframework/Info.plist +44 -0
  22. package/ios/PaperletCore.xcframework/ios-arm64/PaperletCore.framework/Info.plist +20 -0
  23. package/ios/PaperletCore.xcframework/ios-arm64/PaperletCore.framework/PaperletCore +0 -0
  24. package/ios/PaperletCore.xcframework/ios-arm64_x86_64-simulator/PaperletCore.framework/Info.plist +20 -0
  25. package/ios/PaperletCore.xcframework/ios-arm64_x86_64-simulator/PaperletCore.framework/PaperletCore +0 -0
  26. package/ios/pdfium.xcframework/Info.plist +44 -0
  27. package/ios/pdfium.xcframework/ios-arm64/pdfium.framework/Info.plist +28 -0
  28. package/ios/pdfium.xcframework/ios-arm64/pdfium.framework/pdfium +0 -0
  29. package/ios/pdfium.xcframework/ios-arm64_x86_64-simulator/pdfium.framework/Info.plist +28 -0
  30. package/ios/pdfium.xcframework/ios-arm64_x86_64-simulator/pdfium.framework/pdfium +0 -0
  31. package/nitro.json +8 -0
  32. package/nitrogen/generated/.gitattributes +1 -0
  33. package/nitrogen/generated/android/Paperlet+autolinking.cmake +82 -0
  34. package/nitrogen/generated/android/Paperlet+autolinking.gradle +27 -0
  35. package/nitrogen/generated/android/PaperletOnLoad.cpp +49 -0
  36. package/nitrogen/generated/android/PaperletOnLoad.hpp +34 -0
  37. package/nitrogen/generated/android/kotlin/com/margelo/nitro/paperlet/PaperletOnLoad.kt +35 -0
  38. package/nitrogen/generated/ios/Paperlet+autolinking.rb +62 -0
  39. package/nitrogen/generated/ios/Paperlet-Swift-Cxx-Bridge.cpp +17 -0
  40. package/nitrogen/generated/ios/Paperlet-Swift-Cxx-Bridge.hpp +27 -0
  41. package/nitrogen/generated/ios/Paperlet-Swift-Cxx-Umbrella.hpp +38 -0
  42. package/nitrogen/generated/ios/PaperletAutolinking.mm +35 -0
  43. package/nitrogen/generated/ios/PaperletAutolinking.swift +16 -0
  44. package/nitrogen/generated/shared/c++/HybridPaperletDocumentSpec.cpp +28 -0
  45. package/nitrogen/generated/shared/c++/HybridPaperletDocumentSpec.hpp +71 -0
  46. package/nitrogen/generated/shared/c++/HybridPaperletSpec.cpp +25 -0
  47. package/nitrogen/generated/shared/c++/HybridPaperletSpec.hpp +72 -0
  48. package/package.json +51 -4
  49. package/react-native.config.js +10 -0
  50. package/src/PaperletView.tsx +43 -0
  51. package/src/index.ts +85 -0
  52. package/src/specs/Paperlet.nitro.ts +31 -0
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Paperlet for React Native — Commercial Licence
2
+
3
+ Copyright (c) 2026 Ikolvi. All rights reserved.
4
+
5
+ This package is NOT open source. You may use it only under a valid Paperlet
6
+ licence purchased from Ikolvi, and only in the applications (Android
7
+ applicationId / iOS bundle ID) that licence lists. Without a valid licence key
8
+ the software runs in trial mode for evaluation only.
9
+
10
+ You may not copy, redistribute, sublicense, or modify this package, nor remove
11
+ or bypass its licence check or trial watermark.
12
+
13
+ Full terms: the Paperlet End User Licence Agreement supplied with your licence.
@@ -0,0 +1,26 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "Paperlet"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = { :type => "Commercial", :file => "LICENSE" }
11
+ s.authors = package["author"]
12
+ s.platforms = { :ios => "17.0" } # pdfium-binaries frameworks need iOS 17
13
+ s.source = { :git => "https://github.com/Ikolvi/paperlet-sdk.git", :tag => s.version.to_s }
14
+
15
+ s.source_files = ["cpp/**/*.{hpp,cpp,h}"]
16
+ # Prebuilt dynamic frameworks (tool/binaries.sh). Linked and embedded, so PDFium's symbols are
17
+ # in the process when the core looks them up.
18
+ s.vendored_frameworks = ["ios/PaperletCore.xcframework", "ios/pdfium.xcframework"]
19
+
20
+ load "nitrogen/generated/ios/Paperlet+autolinking.rb"
21
+ add_nitrogen_files(s)
22
+
23
+ s.dependency "React-jsi"
24
+ s.dependency "React-callinvoker"
25
+ install_modules_dependencies(s)
26
+ end
package/README.md CHANGED
@@ -1,3 +1,74 @@
1
- # Temporary Holding Version
1
+ <img src="https://paperlet.ikolvi.com/brand/paperlet-mark.png" alt="Paperlet" width="64">
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # @paperlet/react-native
4
+
5
+ Paperlet's PDF SDK for React Native (new architecture). The logic is the compiled Paperlet core (Rust),
6
+ shared with the Flutter packages; this package is a thin [Nitro](https://nitro.margelo.com) module over it.
7
+
8
+ - View pages (`<PaperletView>`), rendered by PDFium
9
+ - Redaction, text stamps, image compression (paid)
10
+ - AES-256 password protection, PAdES signing (paid)
11
+ - MRZ parsing of passports and ID cards
12
+
13
+ Without a licence key the paid features still work and add a "Paperlet Pro trial" watermark.
14
+
15
+ ## Install
16
+
17
+ ```sh
18
+ npm install @paperlet/react-native react-native-nitro-modules
19
+ cd ios && pod install
20
+ ```
21
+
22
+ Needs iOS 17+ (the PDFium build) and Android 7+ (API 24).
23
+
24
+ ## Use
25
+
26
+ ```tsx
27
+ import { PaperletView, initializePaperlet, openDocument, encryptPdf } from '@paperlet/react-native'
28
+
29
+ initializePaperlet(LICENSE_KEY, 'com.example.app') // your bundle id / application id
30
+
31
+ const doc = openDocument(pdfBytes) // ArrayBuffer
32
+ doc.redact(1, [60, 680, 300, 720], 0x000000) // page 1, [left, bottom, right, top] in points
33
+ const locked = encryptPdf(doc.save(), 'secret')
34
+
35
+ <PaperletView document={doc} revision={revision} />
36
+ ```
37
+
38
+ Page numbers start at 1; rectangles are in PDF points from the bottom-left corner. Close documents
39
+ with `doc.close()`.
40
+
41
+ ## Set up with an AI assistant
42
+
43
+ Paste this into Claude Code, Cursor, Copilot or any coding assistant:
44
+
45
+ ```text
46
+ Add Paperlet to this React Native app (new architecture): PDF viewer, redaction, stamps, password protection and signing.
47
+
48
+ 1. Run: npm install @paperlet/react-native react-native-nitro-modules, then cd ios && pod install
49
+ 2. Set the iOS deployment target to 17.0 or higher and Android minSdkVersion to 24 or higher.
50
+ 3. At startup call initializePaperlet(licenseKey, appId), where appId is the bundle ID / application ID. An empty key works and adds a "Paperlet Pro trial" watermark to paid features.
51
+ 4. Load a PDF into an ArrayBuffer, open it with openDocument(bytes) and show it with <PaperletView document={doc} revision={revision} />; bump revision after changing the document and call doc.close() when done.
52
+ 5. API reference: https://www.npmjs.com/package/@paperlet/react-native
53
+ 6. Build for iOS and Android and fix any errors.
54
+ ```
55
+
56
+ ## Licence
57
+
58
+ Commercial ([LICENSE](LICENSE)). Buy a key at [paperlet.ikolvi.com](https://paperlet.ikolvi.com/#pricing); keys are checked offline and bound to your app ID. Without a key the paid features work and adds a "Paperlet Pro trial" watermark, so you can build and test before buying.
59
+
60
+ ## Links
61
+
62
+ [Website and pricing](https://paperlet.ikolvi.com) · [Licence key](https://paperlet.ikolvi.com/license) · [Issues](https://github.com/Ikolvi/paperlet-sdk/issues)
63
+
64
+ ## Develop
65
+
66
+ `npm run binaries` copies the prebuilt core from `../paperlet_core/prebuilt` (run its
67
+ `tool/build.sh` first) and downloads PDFium (pdfium-binaries). `npx nitrogen` regenerates the bindings
68
+ after changing `src/specs`. The example (`example/`) runs every feature at launch and logs
69
+ `PAPERLET_DEMO OK`:
70
+
71
+ ```sh
72
+ cd example && npm install && cd ios && pod install && cd ..
73
+ npx react-native run-ios --mode Release # or run-android --mode release
74
+ ```
@@ -0,0 +1,21 @@
1
+ cmake_minimum_required(VERSION 3.9.0)
2
+ project(Paperlet)
3
+ set(PACKAGE_NAME Paperlet)
4
+ set(CMAKE_CXX_STANDARD 20)
5
+
6
+ add_library(${PACKAGE_NAME} SHARED
7
+ src/main/cpp/cpp-adapter.cpp
8
+ ../cpp/HybridPaperlet.cpp
9
+ ../cpp/HybridPaperletDocument.cpp
10
+ )
11
+ include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/Paperlet+autolinking.cmake)
12
+ include_directories("src/main/cpp" "../cpp")
13
+
14
+ # The prebuilt Paperlet core (Rust); the Android Gradle plugin packages imported libraries. PDFium is
15
+ # not linked: it exports its own unwinder (_Unwind_*), which would take over C++ exceptions here.
16
+ # It is packaged from jniLibs/ and the core loads it with dlopen.
17
+ add_library(paperlet_core SHARED IMPORTED)
18
+ set_target_properties(paperlet_core PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}/libpaperlet_core.so)
19
+
20
+ find_library(LOG_LIB log)
21
+ target_link_libraries(${PACKAGE_NAME} ${LOG_LIB} android paperlet_core)
@@ -0,0 +1,43 @@
1
+ // React Native's Gradle setup (compileSdk etc.) comes from the app's root project.
2
+ apply plugin: "com.android.library"
3
+ apply plugin: "org.jetbrains.kotlin.android"
4
+ apply from: "../nitrogen/generated/android/Paperlet+autolinking.gradle"
5
+
6
+ def ext(name) { rootProject.ext.get(name) }
7
+
8
+ android {
9
+ namespace "com.paperlet"
10
+ ndkVersion ext("ndkVersion")
11
+ compileSdk ext("compileSdkVersion")
12
+
13
+ defaultConfig {
14
+ minSdk ext("minSdkVersion")
15
+ externalNativeBuild {
16
+ cmake {
17
+ cppFlags "-frtti -fexceptions -Wall -fstack-protector-all"
18
+ arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
19
+ // The prebuilt core and PDFium exist for these ABIs.
20
+ abiFilters "arm64-v8a", "armeabi-v7a", "x86_64"
21
+ }
22
+ }
23
+ }
24
+
25
+ externalNativeBuild {
26
+ cmake { path "CMakeLists.txt" }
27
+ }
28
+
29
+ buildFeatures { prefab true }
30
+
31
+ sourceSets { main { jniLibs.srcDirs += ["jniLibs"] } } // PDFium (tool/binaries.sh)
32
+
33
+ packagingOptions {
34
+ // Provided by React Native and Nitro.
35
+ excludes = ["META-INF", "META-INF/**", "**/libc++_shared.so", "**/libfbjni.so", "**/libjsi.so", "**/libreactnative.so",
36
+ "**/libNitroModules.so"]
37
+ }
38
+ }
39
+
40
+ dependencies {
41
+ implementation "com.facebook.react:react-native:+" // replaced with react-android by the RN Gradle plugin
42
+ implementation project(":react-native-nitro-modules")
43
+ }
@@ -0,0 +1 @@
1
+ <manifest />
@@ -0,0 +1,8 @@
1
+ #include <fbjni/fbjni.h>
2
+ #include <jni.h>
3
+
4
+ #include "PaperletOnLoad.hpp"
5
+
6
+ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
7
+ return facebook::jni::initialize(vm, [] { margelo::nitro::paperlet::registerAllNatives(); });
8
+ }
@@ -0,0 +1,20 @@
1
+ package com.paperlet
2
+
3
+ import com.facebook.react.BaseReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.module.model.ReactModuleInfoProvider
7
+ import com.margelo.nitro.paperlet.PaperletOnLoad
8
+
9
+ /** Loads the native library; the module itself is a Nitro hybrid object, created from JS. */
10
+ class PaperletPackage : BaseReactPackage() {
11
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? = null
12
+
13
+ override fun getReactModuleInfoProvider() = ReactModuleInfoProvider { emptyMap() }
14
+
15
+ companion object {
16
+ init {
17
+ PaperletOnLoad.initializeNative()
18
+ }
19
+ }
20
+ }
package/cpp/Core.hpp ADDED
@@ -0,0 +1,44 @@
1
+ // Small helpers around the core's C ABI: errors become C++ exceptions (JS errors), byte results
2
+ // become ArrayBuffers that free themselves.
3
+ #pragma once
4
+ #include <NitroModules/ArrayBuffer.hpp>
5
+ #include <mutex>
6
+ #include <stdexcept>
7
+ #include <string>
8
+
9
+ #include "paperlet_core.h"
10
+
11
+ namespace margelo::nitro::paperlet {
12
+
13
+ /// PDFium is not thread-safe: every call that reaches it holds this lock.
14
+ inline std::mutex& pdfiumLock() {
15
+ static std::mutex m;
16
+ return m;
17
+ }
18
+
19
+ inline void check(char* err) {
20
+ if (err == nullptr) return;
21
+ std::string message(err);
22
+ pl_string_free(err);
23
+ throw std::runtime_error(message);
24
+ }
25
+
26
+ inline int32_t checked(int32_t status, char* err) {
27
+ check(err);
28
+ return status;
29
+ }
30
+
31
+ inline std::shared_ptr<ArrayBuffer> buffer(uint8_t* data, size_t len, char* err) {
32
+ check(err);
33
+ if (data == nullptr) throw std::runtime_error("Paperlet: no result");
34
+ return ArrayBuffer::wrap(data, len, [data, len] { pl_bytes_free(data, len); });
35
+ }
36
+
37
+ inline std::string takeString(char* s) {
38
+ if (s == nullptr) return "null";
39
+ std::string out(s);
40
+ pl_string_free(s);
41
+ return out;
42
+ }
43
+
44
+ } // namespace margelo::nitro::paperlet
@@ -0,0 +1,63 @@
1
+ #include "HybridPaperlet.hpp"
2
+ #include "Core.hpp"
3
+ #include "HybridPaperletDocument.hpp"
4
+
5
+ namespace margelo::nitro::paperlet {
6
+
7
+ static const char* opt(const std::optional<std::string>& s) {
8
+ return s ? s->c_str() : nullptr;
9
+ }
10
+
11
+ static std::string json(const std::vector<std::string>& lines) {
12
+ std::string out = "[";
13
+ for (size_t i = 0; i < lines.size(); i++) {
14
+ if (i) out += ',';
15
+ out += '"';
16
+ for (char c : lines[i]) {
17
+ if (c == '"' || c == '\\') out += '\\';
18
+ if ((unsigned char)c >= 0x20) out += c; // control characters never occur in OCR lines that matter
19
+ }
20
+ out += '"';
21
+ }
22
+ return out + "]";
23
+ }
24
+
25
+ std::string HybridPaperlet::initLicense(const std::string& key, const std::string& appId) {
26
+ return takeString(pl_license_init(key.c_str(), appId.c_str()));
27
+ }
28
+
29
+ std::shared_ptr<HybridPaperletDocumentSpec> HybridPaperlet::open(const std::shared_ptr<ArrayBuffer>& data, const std::optional<std::string>& password) {
30
+ std::lock_guard lock(pdfiumLock());
31
+ char* err = nullptr;
32
+ void* doc = pl_doc_open(data->data(), data->size(), opt(password), &err); // copies the bytes
33
+ check(err);
34
+ return std::make_shared<HybridPaperletDocument>(doc);
35
+ }
36
+
37
+ std::shared_ptr<ArrayBuffer> HybridPaperlet::encrypt(const std::shared_ptr<ArrayBuffer>& pdf, const std::string& userPassword,
38
+ const std::optional<std::string>& ownerPassword, double permissions) {
39
+ std::lock_guard lock(pdfiumLock()); // unlicensed, the core watermarks the pages with PDFium first
40
+ size_t len = 0;
41
+ char* err = nullptr;
42
+ uint8_t* out = pl_encrypt(pdf->data(), pdf->size(), userPassword.c_str(), opt(ownerPassword), (int32_t)permissions, &len, &err);
43
+ return buffer(out, len, err);
44
+ }
45
+
46
+ std::shared_ptr<ArrayBuffer> HybridPaperlet::signPem(const std::shared_ptr<ArrayBuffer>& pdf, const std::string& keyPem,
47
+ const std::string& certificatesPem, double page, const std::vector<double>& rect,
48
+ const std::optional<std::string>& reason, const std::string& time) {
49
+ if (rect.size() != 4) throw std::runtime_error("A rectangle is [left, bottom, right, top]");
50
+ size_t len = 0;
51
+ char* err = nullptr;
52
+ uint8_t* out = pl_sign_pem(pdf->data(), pdf->size(), (uint32_t)page, rect.data(), nullptr, opt(reason), nullptr, time.c_str(),
53
+ keyPem.c_str(), certificatesPem.c_str(), &len, &err);
54
+ return buffer(out, len, err);
55
+ }
56
+
57
+ std::optional<std::string> HybridPaperlet::parseMrz(const std::vector<std::string>& lines, double year) {
58
+ std::string r = takeString(pl_mrz_parse(json(lines).c_str(), (int32_t)year));
59
+ if (r == "null") return std::nullopt;
60
+ return r;
61
+ }
62
+
63
+ } // namespace margelo::nitro::paperlet
@@ -0,0 +1,20 @@
1
+ #pragma once
2
+ #include "HybridPaperletSpec.hpp"
3
+
4
+ namespace margelo::nitro::paperlet {
5
+
6
+ class HybridPaperlet : public HybridPaperletSpec {
7
+ public:
8
+ HybridPaperlet() : HybridObject(TAG) {}
9
+
10
+ std::string initLicense(const std::string& key, const std::string& appId) override;
11
+ std::shared_ptr<HybridPaperletDocumentSpec> open(const std::shared_ptr<ArrayBuffer>& data, const std::optional<std::string>& password) override;
12
+ std::shared_ptr<ArrayBuffer> encrypt(const std::shared_ptr<ArrayBuffer>& pdf, const std::string& userPassword,
13
+ const std::optional<std::string>& ownerPassword, double permissions) override;
14
+ std::shared_ptr<ArrayBuffer> signPem(const std::shared_ptr<ArrayBuffer>& pdf, const std::string& keyPem, const std::string& certificatesPem,
15
+ double page, const std::vector<double>& rect, const std::optional<std::string>& reason,
16
+ const std::string& time) override;
17
+ std::optional<std::string> parseMrz(const std::vector<std::string>& lines, double year) override;
18
+ };
19
+
20
+ } // namespace margelo::nitro::paperlet
@@ -0,0 +1,98 @@
1
+ #include "HybridPaperletDocument.hpp"
2
+ #include "Core.hpp"
3
+
4
+ #include <array>
5
+
6
+ namespace margelo::nitro::paperlet {
7
+
8
+ void* HybridPaperletDocument::open(const State& s) {
9
+ if (s.doc == nullptr) throw std::runtime_error("Document is closed");
10
+ return s.doc;
11
+ }
12
+
13
+ static std::string base64(const uint8_t* d, size_t n) {
14
+ static const char* t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
15
+ std::string out;
16
+ out.reserve((n + 2) / 3 * 4);
17
+ for (size_t i = 0; i < n; i += 3) {
18
+ uint32_t v = d[i] << 16 | (i + 1 < n ? d[i + 1] << 8 : 0) | (i + 2 < n ? d[i + 2] : 0);
19
+ out += t[v >> 18 & 63];
20
+ out += t[v >> 12 & 63];
21
+ out += i + 1 < n ? t[v >> 6 & 63] : '=';
22
+ out += i + 2 < n ? t[v & 63] : '=';
23
+ }
24
+ return out;
25
+ }
26
+
27
+ static std::array<double, 4> rect4(const std::vector<double>& r) {
28
+ if (r.size() != 4) throw std::runtime_error("A rectangle is [left, bottom, right, top]");
29
+ return {r[0], r[1], r[2], r[3]};
30
+ }
31
+
32
+ double HybridPaperletDocument::getPageCount() {
33
+ std::lock_guard lock(pdfiumLock());
34
+ char* err = nullptr;
35
+ return checked(pl_page_count(open(*_state), &err), err);
36
+ }
37
+
38
+ std::vector<double> HybridPaperletDocument::pageSize(double page) {
39
+ std::lock_guard lock(pdfiumLock());
40
+ float w = 0, h = 0;
41
+ char* err = nullptr;
42
+ checked(pl_page_size(open(*_state), (int32_t)page, &w, &h, &err), err);
43
+ return {w, h};
44
+ }
45
+
46
+ std::shared_ptr<Promise<std::string>> HybridPaperletDocument::renderPage(double page, double width) {
47
+ auto state = _state;
48
+ return Promise<std::string>::async([state, page, width]() {
49
+ std::lock_guard lock(pdfiumLock());
50
+ size_t len = 0;
51
+ char* err = nullptr;
52
+ uint8_t* jpeg = pl_render(open(*state), (int32_t)page, (int32_t)width, 85, &len, &err);
53
+ check(err);
54
+ std::string uri = "data:image/jpeg;base64," + base64(jpeg, len);
55
+ pl_bytes_free(jpeg, len);
56
+ return uri;
57
+ });
58
+ }
59
+
60
+ void HybridPaperletDocument::redact(double page, const std::vector<double>& rects, double color) {
61
+ if (rects.size() % 4 != 0) throw std::runtime_error("rects holds 4 numbers per area");
62
+ std::lock_guard lock(pdfiumLock());
63
+ auto rgb = (uint32_t)color;
64
+ char* err = nullptr;
65
+ checked(pl_redact(open(*_state), (int32_t)page, rects.data(), rects.size() / 4, rgb >> 16 & 255, rgb >> 8 & 255, rgb & 255, &err), err);
66
+ }
67
+
68
+ void HybridPaperletDocument::stampText(double page, const std::vector<double>& rect, const std::string& text, double color) {
69
+ auto r = rect4(rect);
70
+ std::lock_guard lock(pdfiumLock());
71
+ char* err = nullptr;
72
+ checked(pl_stamp_text(open(*_state), (int32_t)page, r[0], r[1], r[2], r[3], text.c_str(), (uint32_t)color, &err), err);
73
+ }
74
+
75
+ double HybridPaperletDocument::compressImages(double page, double maxDpi, double quality) {
76
+ std::lock_guard lock(pdfiumLock());
77
+ char* err = nullptr;
78
+ return checked(pl_compress(open(*_state), (int32_t)page, maxDpi, (uint8_t)quality, &err), err);
79
+ }
80
+
81
+ std::shared_ptr<ArrayBuffer> HybridPaperletDocument::save() {
82
+ std::lock_guard lock(pdfiumLock());
83
+ size_t len = 0;
84
+ char* err = nullptr;
85
+ uint8_t* pdf = pl_doc_save(open(*_state), &len, &err);
86
+ return buffer(pdf, len, err);
87
+ }
88
+
89
+ void HybridPaperletDocument::close() {
90
+ std::lock_guard lock(pdfiumLock());
91
+ if (_state->doc == nullptr) return;
92
+ char* err = nullptr;
93
+ pl_doc_close(_state->doc, &err);
94
+ _state->doc = nullptr;
95
+ if (err) pl_string_free(err);
96
+ }
97
+
98
+ } // namespace margelo::nitro::paperlet
@@ -0,0 +1,30 @@
1
+ #pragma once
2
+ #include "HybridPaperletDocumentSpec.hpp"
3
+
4
+ namespace margelo::nitro::paperlet {
5
+
6
+ class HybridPaperletDocument : public HybridPaperletDocumentSpec {
7
+ public:
8
+ explicit HybridPaperletDocument(void* doc) : HybridObject(TAG), _state(std::make_shared<State>(State{doc})) {}
9
+ ~HybridPaperletDocument() override { close(); }
10
+
11
+ double getPageCount() override;
12
+ std::vector<double> pageSize(double page) override;
13
+ std::shared_ptr<Promise<std::string>> renderPage(double page, double width) override;
14
+ void redact(double page, const std::vector<double>& rects, double color) override;
15
+ void stampText(double page, const std::vector<double>& rect, const std::string& text, double color) override;
16
+ double compressImages(double page, double maxDpi, double quality) override;
17
+ std::shared_ptr<ArrayBuffer> save() override;
18
+ void close() override;
19
+
20
+ private:
21
+ // Shared with background renders, so closing while one runs is safe.
22
+ struct State {
23
+ void* doc;
24
+ };
25
+ std::shared_ptr<State> _state;
26
+ /// The open document; call with pdfiumLock() held.
27
+ static void* open(const State& s);
28
+ };
29
+
30
+ } // namespace margelo::nitro::paperlet
@@ -0,0 +1,29 @@
1
+ // C ABI of the Paperlet core (Rust, prebuilt). See paperlet_core/rust/src/lib.rs.
2
+ #pragma once
3
+ #include <stddef.h>
4
+ #include <stdint.h>
5
+
6
+ #ifdef __cplusplus
7
+ extern "C" {
8
+ #endif
9
+
10
+ char* pl_license_init(const char* key, const char* app_id);
11
+ void pl_string_free(char* s);
12
+ void pl_bytes_free(uint8_t* p, size_t len);
13
+ char* pl_mrz_parse(const char* lines_json, int32_t year);
14
+ uint8_t* pl_encrypt(const uint8_t* pdf, size_t pdf_len, const char* user, const char* owner, int32_t p, size_t* out_len, char** err);
15
+ uint8_t* pl_sign_pem(const uint8_t* pdf, size_t pdf_len, uint32_t page, const double* rect, const char* name, const char* reason,
16
+ const char* location, const char* time, const char* key_pem, const char* certs_pem, size_t* out_len, char** err);
17
+ void* pl_doc_open(const uint8_t* data, size_t len, const char* password, char** err);
18
+ int32_t pl_doc_close(void* doc, char** err);
19
+ int32_t pl_page_count(void* doc, char** err);
20
+ int32_t pl_page_size(void* doc, int32_t page, float* w, float* h, char** err);
21
+ uint8_t* pl_render(void* doc, int32_t page, int32_t width, uint8_t quality, size_t* out_len, char** err);
22
+ uint8_t* pl_doc_save(void* doc, size_t* out_len, char** err);
23
+ int32_t pl_redact(void* doc, int32_t page, const double* rects, size_t n, uint8_t r, uint8_t g, uint8_t b, char** err);
24
+ int32_t pl_stamp_text(void* doc, int32_t page, double l, double b, double r, double t, const char* label, uint32_t argb, char** err);
25
+ int32_t pl_compress(void* doc, int32_t page, double max_dpi, uint8_t quality, char** err);
26
+
27
+ #ifdef __cplusplus
28
+ }
29
+ #endif
@@ -0,0 +1,44 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>AvailableLibraries</key>
6
+ <array>
7
+ <dict>
8
+ <key>BinaryPath</key>
9
+ <string>PaperletCore.framework/PaperletCore</string>
10
+ <key>LibraryIdentifier</key>
11
+ <string>ios-arm64</string>
12
+ <key>LibraryPath</key>
13
+ <string>PaperletCore.framework</string>
14
+ <key>SupportedArchitectures</key>
15
+ <array>
16
+ <string>arm64</string>
17
+ </array>
18
+ <key>SupportedPlatform</key>
19
+ <string>ios</string>
20
+ </dict>
21
+ <dict>
22
+ <key>BinaryPath</key>
23
+ <string>PaperletCore.framework/PaperletCore</string>
24
+ <key>LibraryIdentifier</key>
25
+ <string>ios-arm64_x86_64-simulator</string>
26
+ <key>LibraryPath</key>
27
+ <string>PaperletCore.framework</string>
28
+ <key>SupportedArchitectures</key>
29
+ <array>
30
+ <string>arm64</string>
31
+ <string>x86_64</string>
32
+ </array>
33
+ <key>SupportedPlatform</key>
34
+ <string>ios</string>
35
+ <key>SupportedPlatformVariant</key>
36
+ <string>simulator</string>
37
+ </dict>
38
+ </array>
39
+ <key>CFBundlePackageType</key>
40
+ <string>XFWK</string>
41
+ <key>XCFrameworkFormatVersion</key>
42
+ <string>1.0</string>
43
+ </dict>
44
+ </plist>
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleExecutable</key>
6
+ <string>PaperletCore</string>
7
+ <key>CFBundleIdentifier</key>
8
+ <string>com.ikolvi.PaperletCore</string>
9
+ <key>CFBundleName</key>
10
+ <string>PaperletCore</string>
11
+ <key>CFBundlePackageType</key>
12
+ <string>FMWK</string>
13
+ <key>CFBundleShortVersionString</key>
14
+ <string>1.0</string>
15
+ <key>CFBundleVersion</key>
16
+ <string>1</string>
17
+ <key>MinimumOSVersion</key>
18
+ <string>17.0</string>
19
+ </dict>
20
+ </plist>
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleExecutable</key>
6
+ <string>PaperletCore</string>
7
+ <key>CFBundleIdentifier</key>
8
+ <string>com.ikolvi.PaperletCore</string>
9
+ <key>CFBundleName</key>
10
+ <string>PaperletCore</string>
11
+ <key>CFBundlePackageType</key>
12
+ <string>FMWK</string>
13
+ <key>CFBundleShortVersionString</key>
14
+ <string>1.0</string>
15
+ <key>CFBundleVersion</key>
16
+ <string>1</string>
17
+ <key>MinimumOSVersion</key>
18
+ <string>17.0</string>
19
+ </dict>
20
+ </plist>
@@ -0,0 +1,44 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>AvailableLibraries</key>
6
+ <array>
7
+ <dict>
8
+ <key>BinaryPath</key>
9
+ <string>pdfium.framework/pdfium</string>
10
+ <key>LibraryIdentifier</key>
11
+ <string>ios-arm64</string>
12
+ <key>LibraryPath</key>
13
+ <string>pdfium.framework</string>
14
+ <key>SupportedArchitectures</key>
15
+ <array>
16
+ <string>arm64</string>
17
+ </array>
18
+ <key>SupportedPlatform</key>
19
+ <string>ios</string>
20
+ </dict>
21
+ <dict>
22
+ <key>BinaryPath</key>
23
+ <string>pdfium.framework/pdfium</string>
24
+ <key>LibraryIdentifier</key>
25
+ <string>ios-arm64_x86_64-simulator</string>
26
+ <key>LibraryPath</key>
27
+ <string>pdfium.framework</string>
28
+ <key>SupportedArchitectures</key>
29
+ <array>
30
+ <string>arm64</string>
31
+ <string>x86_64</string>
32
+ </array>
33
+ <key>SupportedPlatform</key>
34
+ <string>ios</string>
35
+ <key>SupportedPlatformVariant</key>
36
+ <string>simulator</string>
37
+ </dict>
38
+ </array>
39
+ <key>CFBundlePackageType</key>
40
+ <string>XFWK</string>
41
+ <key>XCFrameworkFormatVersion</key>
42
+ <string>1.0</string>
43
+ </dict>
44
+ </plist>