@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.
90 lines (83 loc) • 2.63 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.CPDFWidget = void 0;
var _CPDFOptions = require("../../configuration/CPDFOptions");
var _reactNative = require("react-native");
/**
* Copyright © 2014-2025 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.
*/
const {
CPDFViewManager
} = _reactNative.NativeModules;
/**
* Base class for form widgets, storing essential form information.
*
* This class represents a form widget in a PDF document, containing basic attributes
* such as type, title, and the page it appears on.
* The `fromJson` method allows converting JSON data into form widget objects.
*
* @class CPDFWidget
* @memberof CPDFWidget
*
* @property {CPDFWidgetType} type - The type of the form widget.
* @property {string} title - The title of the form widget (default: empty string).
* @property {number} page - The page number where the form widget appears (default: 0).
*/
class CPDFWidget {
/**
* The type of the form widget.
*/
/**
* The title of the form widget (default: empty string).
*/
/**
* The page number where the form widget appears (default: 0).
*/
constructor(viewerRef, params) {
this.type = CPDFWidget.parseType(params.type);
this.title = params.title ?? "";
this.page = params.page ?? 0;
this.uuid = params.uuid ?? "";
this._viewerRef = viewerRef;
}
static fromJson(json, viewerRef) {
return new this(viewerRef, json);
}
static fromJsonArray(jsonArray, viewerRef) {
return jsonArray.map(item => new this(viewerRef, item));
}
static parseType(type) {
return Object.values(_CPDFOptions.CPDFWidgetType).includes(type) ? type : _CPDFOptions.CPDFWidgetType.UNKNOWN;
}
toJSON() {
const {
_viewerRef,
...data
} = this;
return data;
}
/**
* Update the appearance of a form widget.
* @returns
*/
updateAp = () => {
const tag = (0, _reactNative.findNodeHandle)(this._viewerRef);
if (tag) {
try {
return CPDFViewManager.updateAp(tag, this.page, this.uuid);
} catch (error) {
console.log(error);
}
}
return Promise.reject(new Error('Unable to find the native view reference'));
};
}
exports.CPDFWidget = CPDFWidget;
//# sourceMappingURL=CPDFWidget.js.map
;