@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.
62 lines (61 loc) • 2.45 kB
JavaScript
/**
* 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.
*/
import { CPDFAnnotationType } from "../configuration/CPDFOptions";
import { safeParseEnumValue } from "../util/CPDFEnumUtils";
/**
* @class CPDFAnnotation
* @property { CPDFAnnotationType } [type] Annotation type identifier
* @property { title } [title] Annotation title
* @property { number } [page] The page number where the note is located
* @property { string } [content] annotation content.
* @property { string } [uuid] annotation uuid.
* @property { Date } [modifyDate] annotation modify date.
* @property { Date } [createDate] annotation create date.
* @property { CPDFRectF } [rect] annotation rect.
*/
export class CPDFAnnotation {
modifyDate = null;
createDate = null;
rect = null;
constructor(viewerRef, params) {
this._viewerRef = viewerRef;
this.type = safeParseEnumValue(params.type, Object.values(CPDFAnnotationType), CPDFAnnotationType.UNKNOWN);
this.title = params.title ?? '';
this.page = params.page ?? 0;
this.content = params.content ?? "";
this.uuid = params.uuid ?? "";
this.modifyDate = params.modifyDate != null ? new Date(params.modifyDate) : null;
this.createDate = params.createDate != null ? new Date(params.createDate) : null;
this.rect = params.rect ?? null;
}
static fromJson(json, viewerRef) {
return new this(viewerRef, json);
}
static fromJsonArray(jsonArray, viewerRef) {
return jsonArray.map(item => new this(viewerRef, item));
}
static formatDate(date) {
const pad = n => n.toString().padStart(2, '0');
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` + `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
}
toJSON() {
const {
_viewerRef,
modifyDate,
createDate,
...data
} = this;
return {
...data,
modifyDate: modifyDate ? CPDFAnnotation.formatDate(modifyDate) : null,
createDate: createDate ? CPDFAnnotation.formatDate(createDate) : null
};
}
}
//# sourceMappingURL=CPDFAnnotation.js.map