@compdfkit_pdf_sdk/react_native
Version:
ComPDFKit for React Native is a comprehensive SDK that allows you to quickly add PDF functionality to Android, iOS, and React Native applications.
97 lines • 3.68 kB
JavaScript
;
/**
* Copyright © 2014-2026 PDF Technologies, Inc. All Rights Reserved.
*
* THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
* AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
* UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
* This notice may not be removed from this file.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ComPDFKit = void 0;
const react_native_1 = require("react-native");
const CPDFFontName_1 = __importDefault(require("../document/CPDFFontName"));
const DefaultConfig_1 = require("./DefaultConfig");
const nativeMethodNames = [
"getVersionCode",
"getSDKBuildTag",
"init_",
"initialize",
"initWithPath",
"openDocument",
"removeSignFileList",
"pickFile",
"setImportFontDir",
"updateImportFontDir",
"getFonts",
];
const nativeComPDFKit = react_native_1.NativeModules.ComPDFKit;
function getAvailableNativeMethodNames() {
if (!nativeComPDFKit) {
return [];
}
return Object.keys(nativeComPDFKit)
.filter((key) => typeof nativeComPDFKit[key] === "function")
.sort();
}
function createMissingNativeMethodError(methodName) {
const availableMethods = getAvailableNativeMethodNames();
const moduleState = nativeComPDFKit ? "loaded" : "missing";
const availableMethodsText = availableMethods.length
? availableMethods.join(", ")
: "none";
return new Error([
`ComPDFKit native method '${methodName}' is unavailable.`,
`NativeModules.ComPDFKit is ${moduleState}.`,
`Available native methods: ${availableMethodsText}.`,
"This usually means the JavaScript sources are newer than the installed native app.",
"Rebuild and reinstall the host app after changing Android/iOS native module APIs.",
].join(" "));
}
function getRequiredNativeMethod(methodName) {
const method = nativeComPDFKit?.[methodName];
if (typeof method !== "function") {
throw createMissingNativeMethodError(methodName);
}
return method;
}
const comPDFKitBase = {
...(nativeComPDFKit ?? {}),
getDefaultConfig: DefaultConfig_1.getDefaultConfig,
async createUri(fileName, childDirectoryName, mimeType) {
const createUri = nativeComPDFKit?.createUri;
if (typeof createUri !== "function") {
return Promise.reject(new Error("createUri() is only supported on Android."));
}
return createUri(fileName, childDirectoryName, mimeType);
},
async getFonts() {
const getFonts = nativeComPDFKit?.getFonts;
if (typeof getFonts !== "function") {
throw createMissingNativeMethodError("getFonts");
}
const fonts = await getFonts();
return Array.isArray(fonts)
? fonts.map((font) => CPDFFontName_1.default.fromJson(font))
: [];
},
};
const ComPDFKit = new Proxy(comPDFKitBase, {
get(target, property, receiver) {
const value = Reflect.get(target, property, receiver);
if (typeof property === "string" &&
nativeMethodNames.includes(property) &&
typeof value === "undefined") {
return (...args) => {
const method = getRequiredNativeMethod(property);
return method(...args);
};
}
return value;
},
});
exports.ComPDFKit = ComPDFKit;
//# sourceMappingURL=ComPDFKitModule.js.map