@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.
77 lines (72 loc) • 2.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.CPDFTextWidget = void 0;
var _CPDFOptions = require("../../configuration/CPDFOptions");
var _CPDFEnumUtils = require("../../util/CPDFEnumUtils");
var _CPDFWidget = require("./CPDFWidget");
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;
/**
* Class representing a text field form widget, storing basic information about the text field form.
* It includes general form attributes as well as the text content of the text field.
*
* @class CPDFTextWidget
* @memberof CPDFTextWidget
* @property {string} [text] - The text content of the text field.
* @property {boolean} [isMultiline] - Indicates if the text field is multiline (default: false).
* @property {string} [fontColor] - The font color of the text field (default: '#000000').
* @property {string} [fontName] - The font name of the text field (default: 'Helvetica').
* @property {number} [fontSize] - The font size of the text field (default: 0).
* @property {CPDFAlignment} [alignment] - The alignment of the text field (default: CPDFAlignment.LEFT).
*/
class CPDFTextWidget extends _CPDFWidget.CPDFWidget {
/**
* The text content of the text field.
*/
constructor(viewerRef, params) {
super(viewerRef, params);
this.text = params.text ?? '';
this.isMultiline = params.isMultiline ?? false;
this.fontColor = params.fontColor ?? '#000000';
this.familyName = params.familyName ?? '';
this.styleName = params.styleName ?? '';
this.fontSize = params.fontSize ?? 0;
this.alignment = (0, _CPDFEnumUtils.safeParseEnumValue)(params.alignment, Object.values(_CPDFOptions.CPDFAlignment), _CPDFOptions.CPDFAlignment.LEFT);
}
/**
* Set the text content of this text field form widget.
* @param text The text content to set.
* @example
* await textWidget.setText('Hello World');
* // Update the appearance of this text field form widget.
* await textWidget.updateAp();
* @returns
*/
setText = async text => {
const tag = (0, _reactNative.findNodeHandle)(this._viewerRef);
if (tag) {
try {
await CPDFViewManager.setTextWidgetText(tag, this.page, this.uuid, text);
this.text = text;
return;
} catch (e) {
return Promise.reject(e);
}
}
return Promise.reject(new Error('Unable to find the native view reference'));
};
}
exports.CPDFTextWidget = CPDFTextWidget;
//# sourceMappingURL=CPDFTextWidget.js.map