UNPKG

@syncfusion/ej2-pdfviewer

Version:
919 lines 411 kB
import { PdfViewerBase, TextMarkupAnnotation, ShapeAnnotation, StampAnnotation, StickyNotesAnnotation, MeasureAnnotation, InkAnnotation, AllowedInteraction, DynamicStampItem, SignStampItem, StandardBusinessStampItem } from '../index'; import { createElement, Browser, isNullOrUndefined, isBlazor, SanitizeHtmlHelper } from '@syncfusion/ej2-base'; import { NumericTextBox, Slider, ColorPicker } from '@syncfusion/ej2-inputs'; import { Dialog } from '@syncfusion/ej2-popups'; import { DropDownButton } from '@syncfusion/ej2-splitbuttons'; import { processPathData, splitArrayCollection } from '@syncfusion/ej2-drawings'; import { isLineShapes, cloneObject } from '../drawing/drawing-util'; import { NodeDrawingTool, LineTool, MoveTool, ResizeTool, ConnectTool } from '../drawing/tools'; import { updateDistanceLabel, updateRadiusLabel, updatePerimeterLabel, updateCalibrateLabel } from '../drawing/connector-util'; import { FreeTextAnnotation } from './free-text-annotation'; import { InputElement } from './input-element'; import { InPlaceEditor } from '@syncfusion/ej2-inplace-editor'; /** * The `Annotation` module is used to handle annotation actions of PDF viewer. */ var Annotation = /** @class */ (function () { /** * @param {PdfViewer} pdfViewer - pdfViewer * @param {PdfViewerBase} viewerBase - viewerBase * @private */ function Annotation(pdfViewer, viewerBase) { /** * @private */ this.isUndoRedoAction = false; this.isFreeTextFontsizeChanged = false; this.isUndoAction = false; this.annotationSelected = true; this.isAnnotDeletionApiCall = false; this.removedDocumentAnnotationCollection = []; /** * @private * It is used to store the non render page selected annotation. */ this.nonRenderSelectedAnnotation = null; /** * @private */ this.isShapeCopied = false; /** * @private */ this.actionCollection = []; /** * @private */ this.redoCollection = []; /** * @private */ this.isPopupNoteVisible = false; /** * @private */ this.undoCommentsElement = []; /** * @private */ this.redoCommentsElement = []; /** * @private */ this.selectAnnotationId = null; /** * @private */ this.isAnnotationSelected = false; /** * @private */ this.annotationPageIndex = null; this.previousIndex = null; /** * @private */ this.annotationType = null; this.overlappedAnnotations = []; /** * @private */ this.overlappedCollections = []; /** * @private */ this.isFormFieldShape = false; /** * @private */ this.removedAnnotationCollection = []; this.isEdited = false; this.pdfViewer = pdfViewer; this.pdfViewerBase = viewerBase; if (this.pdfViewer.enableTextMarkupAnnotation) { this.textMarkupAnnotationModule = new TextMarkupAnnotation(this.pdfViewer, this.pdfViewerBase); } if (this.pdfViewer.enableShapeAnnotation) { this.shapeAnnotationModule = new ShapeAnnotation(this.pdfViewer, this.pdfViewerBase); } if (this.pdfViewer.enableMeasureAnnotation) { this.measureAnnotationModule = new MeasureAnnotation(this.pdfViewer, this.pdfViewerBase); } this.stampAnnotationModule = new StampAnnotation(this.pdfViewer, this.pdfViewerBase); this.stickyNotesAnnotationModule = new StickyNotesAnnotation(this.pdfViewer, this.pdfViewerBase); this.freeTextAnnotationModule = new FreeTextAnnotation(this.pdfViewer, this.pdfViewerBase); this.inputElementModule = new InputElement(this.pdfViewer, this.pdfViewerBase); this.inkAnnotationModule = new InkAnnotation(this.pdfViewer, this.pdfViewerBase); } /** * Set annotation type to be added in next user interaction in PDF Document. * * @param {AnnotationType} type - type * @param {DynamicStampItem} dynamicStampItem - dynamicStampItem * @param {SignStampItem} signStampItem - signStampItem * @param {StandardBusinessStampItem} standardBusinessStampItem - standardBusinessStampItem. * @returns {void} */ Annotation.prototype.setAnnotationMode = function (type, dynamicStampItem, signStampItem, standardBusinessStampItem) { var allowServerDataBind = this.pdfViewer.allowServerDataBinding; this.pdfViewer.enableServerDataBinding(false); if (this.pdfViewer.tool === 'Stamp' && this.pdfViewer.toolbarModule) { this.pdfViewer.toolbarModule.updateStampItems(); } if (this.pdfViewer.toolbarModule && this.pdfViewer.toolbarModule.annotationToolbarModule) { this.pdfViewer.toolbarModule.annotationToolbarModule.resetFreeTextAnnot(); } if (type !== 'None') { this.triggerAnnotationUnselectEvent(); } this.pdfViewer.tool = ''; if (this.pdfViewer.toolbarModule) { this.pdfViewer.toolbarModule.deSelectCommentAnnotation(); } if (type === 'None') { this.clearAnnotationMode(); } else if (type === 'Highlight' || type === 'Strikethrough' || type === 'Underline') { if (this.textMarkupAnnotationModule) { this.textMarkupAnnotationModule.isSelectionMaintained = false; this.textMarkupAnnotationModule.drawTextMarkupAnnotations(type.toString()); } } else if (type === 'Line' || type === 'Arrow' || type === 'Rectangle' || type === 'Circle' || type === 'Polygon') { if (this.shapeAnnotationModule) { this.shapeAnnotationModule.setAnnotationType(type); } } else if (type === 'Distance' || type === 'Perimeter' || type === 'Area' || type === 'Radius' || type === 'Volume') { if (this.measureAnnotationModule) { this.measureAnnotationModule.setAnnotationType(type); } } else if (type === 'FreeText' && this.freeTextAnnotationModule) { this.freeTextAnnotationModule.setAnnotationType('FreeText'); this.freeTextAnnotationModule.isNewFreeTextAnnot = true; this.freeTextAnnotationModule.isNewAddedAnnot = true; } else if (type === 'HandWrittenSignature') { this.pdfViewerBase.signatureModule.setAnnotationMode(); } else if (type === 'Initial') { this.pdfViewerBase.signatureModule.setInitialMode(); } else if (type === 'Ink') { this.inkAnnotationModule.setAnnotationMode(); } else if (type === 'StickyNotes') { this.pdfViewerBase.isCommentIconAdded = true; this.pdfViewerBase.isAddComment = true; var pageDiv = document.getElementById(this.pdfViewer.element.id + '_pageDiv_' + (this.pdfViewerBase.currentPageNumber - 1)); if (pageDiv) { pageDiv.addEventListener('mousedown', this.pdfViewer.annotationModule.stickyNotesAnnotationModule.drawIcons.bind(this)); } } else if (type === 'Stamp') { this.pdfViewer.annotation.stampAnnotationModule.isStampAddMode = true; this.pdfViewer.annotationModule.stampAnnotationModule.isStampAnnotSelected = true; this.pdfViewerBase.stampAdded = true; if (dynamicStampItem) { // eslint-disable-next-line var stampName = DynamicStampItem[dynamicStampItem]; this.pdfViewerBase.isDynamicStamp = true; this.stampAnnotationModule.retrieveDynamicStampAnnotation(stampName); } else if (signStampItem) { // eslint-disable-next-line var stampName = SignStampItem[signStampItem]; this.pdfViewerBase.isDynamicStamp = false; this.stampAnnotationModule.retrievestampAnnotation(stampName); } else if (standardBusinessStampItem) { // eslint-disable-next-line var stampName = StandardBusinessStampItem[standardBusinessStampItem]; this.pdfViewerBase.isDynamicStamp = false; this.stampAnnotationModule.retrievestampAnnotation(stampName); } } this.pdfViewer.enableServerDataBinding(allowServerDataBind, true); this.pdfViewerBase.initiateTextSelection(); }; Annotation.prototype.deleteAnnotationById = function (annotationId) { if (annotationId) { this.isAnnotDeletionApiCall = true; this.annotationSelected = false; this.selectAnnotation(annotationId); this.deleteAnnotation(); this.isAnnotDeletionApiCall = false; if (this.pdfViewer.textSelectionModule) { this.pdfViewer.textSelectionModule.clearTextSelection(); } } }; Annotation.prototype.clearAnnotationMode = function () { if (this.textMarkupAnnotationModule) { this.textMarkupAnnotationModule.isTextMarkupAnnotationMode = false; } if (this.freeTextAnnotationModule) { this.freeTextAnnotationModule.isNewFreeTextAnnot = false; this.freeTextAnnotationModule.isNewAddedAnnot = false; } if (this.pdfViewerBase.isTextMarkupAnnotationModule()) { this.pdfViewer.annotation.textMarkupAnnotationModule.currentTextMarkupAddMode = ''; } if (this.pdfViewerBase.isShapeAnnotationModule()) { this.pdfViewer.annotation.shapeAnnotationModule.currentAnnotationMode = ''; } if (this.pdfViewerBase.isCalibrateAnnotationModule()) { this.pdfViewer.annotation.measureAnnotationModule.currentAnnotationMode = ''; } if (this.pdfViewer.annotationModule.inkAnnotationModule) { var currentPageNumber = parseInt(this.pdfViewer.annotationModule.inkAnnotationModule.currentPageNumber, 10); this.pdfViewer.annotationModule.inkAnnotationModule.drawInkAnnotation(currentPageNumber); } }; Annotation.prototype.deleteAnnotation = function () { if (this.textMarkupAnnotationModule) { this.textMarkupAnnotationModule.deleteTextMarkupAnnotation(); } var selectedAnnotation = this.pdfViewer.selectedItems.annotations[0]; if (selectedAnnotation) { var data = PdfViewerBase.sessionStorageManager.getItem(this.pdfViewerBase.documentId + '_formfields'); var formFieldsData = JSON.parse(data); var newFormFieldsData = []; if (formFieldsData) { for (var x = 0; x < formFieldsData.length; x++) { // eslint-disable-next-line if (formFieldsData[parseInt(x.toString(), 10)].uniqueID == selectedAnnotation.id) { formFieldsData[parseInt(x.toString(), 10)].Value = ''; for (var y = 0; y < formFieldsData.length; y++) { if (formFieldsData[parseInt(y.toString(), 10)].Name === 'ink') { formFieldsData[parseInt(y.toString(), 10)].Value = ''; } if (formFieldsData[parseInt(x.toString(), 10)].FieldName === formFieldsData[parseInt(y.toString(), 10)].FieldName && formFieldsData[parseInt(y.toString(), 10)].Name === 'ink') { formFieldsData.splice(y, 1); } } newFormFieldsData.push(formFieldsData[parseInt(x.toString(), 10)]); } else { newFormFieldsData.push(formFieldsData[parseInt(x.toString(), 10)]); } } PdfViewerBase.sessionStorageManager.setItem(this.pdfViewerBase.documentId + '_formfields', JSON.stringify(newFormFieldsData)); } } var isLock = false; var isReadOnly = false; if (this.pdfViewer.selectedItems.annotations.length > 0) { var annotation_1 = this.pdfViewer.selectedItems.annotations[0]; var type = annotation_1.shapeAnnotationType; if (type === 'Path' || annotation_1.formFieldAnnotationType === 'SignatureField' || annotation_1.formFieldAnnotationType === 'InitialField' || type === 'HandWrittenSignature' || type === 'SignatureText' || type === 'SignatureImage') { var inputFields = document.getElementById(annotation_1.id); if (inputFields && inputFields.disabled) { isReadOnly = true; } } if (annotation_1.annotationSettings) { isLock = annotation_1.annotationSettings.isLock; if (isLock && this.checkAllowedInteractions('Delete', annotation_1)) { isLock = false; } } if (!isLock && !isReadOnly) { var pageNumber = annotation_1.pageIndex; var shapeType = annotation_1.shapeAnnotationType; var undoElement = void 0; if (shapeType === 'Line' || shapeType === 'LineWidthArrowHead' || shapeType === 'Polygon' || shapeType === 'Ellipse' || shapeType === 'Rectangle' || shapeType === 'Radius' || shapeType === 'Distance') { if (isNullOrUndefined(annotation_1.measureType) || annotation_1.measureType === '') { this.pdfViewer.annotation.stickyNotesAnnotationModule.findPosition(annotation_1, 'shape'); this.updateImportAnnotationCollection(annotation_1, pageNumber, 'shapeAnnotation'); } else { this.pdfViewer.annotation.stickyNotesAnnotationModule.findPosition(annotation_1, 'measure'); this.updateImportAnnotationCollection(annotation_1, pageNumber, 'measureShapeAnnotation'); } undoElement = this.modifyInCollections(annotation_1, 'delete'); } else if (shapeType === 'FreeText') { this.pdfViewer.annotation.stickyNotesAnnotationModule.findPosition(annotation_1, 'FreeText', 'delete'); undoElement = this.modifyInCollections(annotation_1, 'delete'); this.updateImportAnnotationCollection(annotation_1, pageNumber, 'freeTextAnnotation'); } else if (shapeType === 'HandWrittenSignature' || shapeType === 'SignatureImage' || shapeType === 'SignatureText') { undoElement = this.modifyInCollections(annotation_1, 'delete'); } else if (shapeType === 'Ink') { this.pdfViewer.annotation.stickyNotesAnnotationModule.findPosition(annotation_1, 'Ink', 'delete'); undoElement = this.modifyInCollections(annotation_1, 'delete'); this.updateImportAnnotationCollection(annotation_1, pageNumber, 'signatureInkAnnotation'); } else { undoElement = this.pdfViewer.selectedItems.annotations[0]; this.pdfViewer.annotation.stickyNotesAnnotationModule.findPosition(undoElement, undoElement.shapeAnnotationType, 'delete'); this.pdfViewer.annotation.stampAnnotationModule.updateSessionStorage(annotation_1, null, 'delete'); } if (shapeType === 'StickyNotes') { this.updateImportAnnotationCollection(annotation_1, pageNumber, 'stickyNotesAnnotation'); } if (shapeType === 'Stamp' || shapeType === 'Image') { this.updateImportAnnotationCollection(annotation_1, pageNumber, 'stampAnnotations'); } var formFieldObj = this.pdfViewer.nameTable[annotation_1.id.split('_')[0]]; if (isNullOrUndefined(formFieldObj) || !(formFieldObj.formFieldAnnotationType === 'SignatureField' || formFieldObj.formFieldAnnotationType === 'InitialField')) { this.pdfViewer.annotation.addAction(pageNumber, null, annotation_1, 'Delete', '', undoElement, annotation_1); } var removeDiv = void 0; if (annotation_1.annotName !== '') { removeDiv = document.getElementById(annotation_1.annotName); } else { if (undoElement) { if (undoElement.annotName !== '') { removeDiv = document.getElementById(undoElement.annotName); } } } this.removeCommentPanelDiv(removeDiv); var selectedAnnot = this.pdfViewer.selectedItems.annotations[0]; var annotationId = selectedAnnot.annotName; var annotType = this.getAnnotationType(selectedAnnot.shapeAnnotationType, selectedAnnot.measureType); if (shapeType === 'Path' || selectedAnnot.formFieldAnnotationType === 'SignatureField' || selectedAnnot.formFieldAnnotationType === 'InitialField' || shapeType === 'HandWrittenSignature' || shapeType === 'SignatureText' || shapeType === 'SignatureImage') { var formFieldCollection = this.pdfViewer.retrieveFormFields(); var index = formFieldCollection.findIndex(function (el) { return el.id === annotation_1.id; }); var formFieldName = void 0; if (index > -1) { formFieldName = formFieldCollection[parseInt(index.toString(), 10)].name; } for (var m = 0; m < formFieldCollection.length; m++) { if (selectedAnnot.id === formFieldCollection[parseInt(m.toString(), 10)].id || (isNullOrUndefined(formFieldName) && formFieldName === formFieldCollection[parseInt(m.toString(), 10)].name)) { formFieldCollection[parseInt(m.toString(), 10)].value = ''; formFieldCollection[parseInt(m.toString(), 10)].signatureType = ''; var annotation_2 = this.getAnnotationsFromCollections(formFieldCollection[parseInt(m.toString(), 10)].id); this.updateInputFieldDivElement(annotation_2); undoElement = this.modifyInCollections(annotation_2, 'delete'); this.pdfViewer.annotation.addAction(annotation_2.pageIndex, null, annotation_2, 'Delete', '', undoElement, annotation_2); if (this.pdfViewer.formDesignerModule && selectedAnnot.formFieldAnnotationType) { this.updateFormFieldCollection(annotation_2); } else { this.updateAnnotationCollection(annotation_2); } this.pdfViewer.remove(annotation_2); } } if (this.pdfViewer.formDesignerModule && selectedAnnot.formFieldAnnotationType) { this.updateFormFieldCollection(annotation_1); } else { this.updateAnnotationCollection(annotation_1); } } if (this.pdfViewer.formDesignerModule && selectedAnnot.formFieldAnnotationType) { this.updateFormFieldCollection(annotation_1); } else { this.updateAnnotationCollection(annotation_1); } if (formFieldObj != null && (formFieldObj.formFieldAnnotationType === 'SignatureField' || formFieldObj.formFieldAnnotationType === 'InitialField')) { var index = this.pdfViewer.formFieldCollections.findIndex(function (el) { return el.id === annotation_1.id.split('_')[0]; }); var formFieldName = void 0; if (index > -1) { formFieldName = this.pdfViewer.formFieldCollections[parseInt(index.toString(), 10)].name; } for (var i = 0; i < this.pdfViewer.formFieldCollections.length; i++) { if (formFieldName === this.pdfViewer.formFieldCollections[parseInt(i.toString(), 10)].name) { var formFieldsIndex = this.pdfViewer.formFieldCollections[parseInt(i.toString(), 10)]; this.pdfViewer.fireFormFieldPropertiesChangeEvent('formFieldPropertiesChange', formFieldsIndex, formFieldsIndex.pageIndex, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, formFieldsIndex.value, ''); formFieldsIndex.value = ''; formFieldsIndex.signatureType = ''; this.pdfViewer.formDesignerModule.updateFormFieldCollections(formFieldsIndex); var annotation_3 = this.getAnnotationsFromCollections(formFieldsIndex.id + '_content'); if (!isNullOrUndefined(annotation_3)) { undoElement = this.modifyInCollections(annotation_3, 'delete'); this.pdfViewer.annotation.addAction(annotation_3.pageIndex, null, annotation_3, 'Delete', '', undoElement, annotation_3); this.updateInputFieldDivElement(annotation_3); var formFieldObject = this.pdfViewer.nameTable[annotation_3.id.split('_')[0]]; formFieldObject.wrapper.children.splice(formFieldObject.wrapper.children. indexOf(annotation_3.wrapper.children[0]), 1); this.pdfViewer.remove(annotation_3); } } } } this.pdfViewer.remove(annotation_1); this.pdfViewer.renderDrawing(); this.pdfViewer.clearSelection(pageNumber); this.pdfViewerBase.setItemInSessionStorage(this.pdfViewerBase.formFieldCollection, '_formDesigner'); this.pdfViewerBase.updateDocumentEditedProperty(true); this.pdfViewerBase.tool = null; this.pdfViewer.tool = null; if (selectedAnnot.shapeAnnotationType === 'HandWrittenSignature' || selectedAnnot.shapeAnnotationType === 'SignatureText' || selectedAnnot.shapeAnnotationType === 'SignatureImage' || selectedAnnot.shapeAnnotationType === 'Path') { var bounds = { left: selectedAnnot.bounds.x, top: selectedAnnot.bounds.y, width: selectedAnnot.bounds.width, height: selectedAnnot.bounds.height }; this.pdfViewer.fireSignatureRemove(pageNumber, selectedAnnot.id, selectedAnnot.shapeAnnotationType, bounds); } else if (this.pdfViewer.annotationModule) { this.pdfViewer.fireAnnotationRemove(pageNumber, annotationId, annotType, selectedAnnot.bounds); } if (this.pdfViewer.textSelectionModule) { this.pdfViewer.textSelectionModule.enableTextSelectionMode(); } } } else if (this.nonRenderSelectedAnnotation && this.nonRenderSelectedAnnotation.annotationId && this.isAnnotDeletionApiCall) { var annotationId = this.nonRenderSelectedAnnotation.annotationId; var pageIndex = this.nonRenderSelectedAnnotation.pageNumber ? this.nonRenderSelectedAnnotation.pageNumber : this.nonRenderSelectedAnnotation.pageIndex; var collections = this.updateCollectionForNonRenderedPages(this.nonRenderSelectedAnnotation, annotationId, pageIndex); collections.pageIndex = pageIndex; this.pdfViewer.annotation.addAction(pageIndex, null, collections, 'Delete', '', collections, collections); this.undoCommentsElement.push(collections); var removeDiv = document.getElementById(annotationId); this.removeCommentPanelDiv(removeDiv); this.nonRenderSelectedAnnotation = null; } this.updateToolbar(true); if (this.pdfViewer.toolbarModule) { if (this.pdfViewer.toolbarModule.annotationToolbarModule && !isLock) { this.pdfViewer.toolbarModule.annotationToolbarModule.selectAnnotationDeleteItem(false, true); this.pdfViewer.toolbarModule.annotationToolbarModule.enableTextMarkupAnnotationPropertiesTools(false); } } }; /** * @param {string} annotationId - annotationId * @returns {void} */ Annotation.prototype.getAnnotationsFromCollections = function (annotationId) { var collections = this.pdfViewer.annotations; if (collections && annotationId) { for (var i = 0; i < collections.length; i++) { if (collections[parseInt(i.toString(), 10)].id === annotationId) { return collections[parseInt(i.toString(), 10)]; } } } return null; }; /** * @param {any} annotation - annotation * @returns {void} */ Annotation.prototype.updateInputFieldDivElement = function (annotation) { var inputFields = document.getElementById(annotation.id); var signatureFieldElement = document.getElementById(annotation.id + '_html_element'); if (inputFields === null && !isNullOrUndefined(signatureFieldElement)) { inputFields = signatureFieldElement.children[0].children[0]; } if (inputFields && inputFields.classList.contains('e-pdfviewer-signatureformfields-signature')) { inputFields.className = 'e-pdfviewer-signatureformfields'; inputFields.style.pointerEvents = ''; inputFields.parentElement.style.pointerEvents = ''; } if (this.pdfViewer.formDesignerModule) { this.pdfViewer.formDesignerModule.updateSignatureValue(annotation.id); } else { if (this.pdfViewer.formFieldsModule) { this.pdfViewer.formFieldsModule.updateDataInSession(inputFields, ''); } } }; /** * @param {any} annotation - annotation * @param {number} pageNumber - pageNumber * @param {boolean} isNeedToReorderCollection - Ensures whether need to reorder the collection or not * @param {number} orderNumber - Gets the order number * @private * @returns {void} */ Annotation.prototype.storeAnnotationCollections = function (annotation, pageNumber, isNeedToReorderCollection, orderNumber) { if (this.isFormFieldShape) { var collectionDetails = this.checkFormDesignCollection(annotation); var selectAnnotation = cloneObject(annotation); selectAnnotation.formFieldId = annotation.annotName; selectAnnotation.pageNumber = pageNumber; delete selectAnnotation.annotName; if (annotation.id) { selectAnnotation.uniqueKey = annotation.id; delete selectAnnotation.id; } if (collectionDetails.isExisting) { this.pdfViewer.formFieldCollection.splice(collectionDetails.position, 0, selectAnnotation); } else { this.pdfViewer.formFieldCollection.push(selectAnnotation); } } else { var collectionDetails = this.checkAnnotationCollection(annotation); var selectAnnotation = cloneObject(annotation); selectAnnotation.annotationId = annotation.annotName; selectAnnotation.pageNumber = pageNumber; delete selectAnnotation.annotName; if (annotation.shapeAnnotationType === 'stamp') { selectAnnotation.uniqueKey = annotation.randomId; delete selectAnnotation.randomId; } if (annotation.shapeAnnotationType === 'sticky') { selectAnnotation.uniqueKey = annotation.annotName; } if (annotation.id) { selectAnnotation.uniqueKey = annotation.id; delete selectAnnotation.id; } if (selectAnnotation.customData && annotation.customData && JSON.stringify(selectAnnotation.customData) !== JSON.stringify(annotation.customData)) { selectAnnotation.customData = annotation.customData; } if (collectionDetails.isExisting) { this.pdfViewer.annotationCollection.splice(collectionDetails.position, 0, selectAnnotation); } else if (!isNullOrUndefined(isNeedToReorderCollection) && isNeedToReorderCollection) { this.pdfViewer.annotationCollection.splice(orderNumber, 0, selectAnnotation); } else { this.pdfViewer.annotationCollection.push(selectAnnotation); } } }; Annotation.prototype.checkFormDesignCollection = function (annotation) { var collections = this.pdfViewer.formFieldCollection; if (collections && annotation) { for (var i = 0; i < collections.length; i++) { if (collections[parseInt(i.toString(), 10)].formFieldId === annotation.annotName) { this.pdfViewer.formFieldCollection.splice(i, 1); return { isExisting: true, position: i }; } } } return { isExisting: false, position: null }; }; Annotation.prototype.updateFormFieldCollection = function (annotation) { var collections = this.pdfViewer.formFieldCollection; if (collections && annotation) { for (var i = 0; i < collections.length; i++) { if (collections[parseInt(i.toString(), 10)].formFieldId === annotation.annotName) { this.removedAnnotationCollection.push(collections[parseInt(i.toString(), 10)]); this.pdfViewer.formFieldCollection.splice(i, 1); break; } } } }; /** * @param {any} annotation - annotation * @private * @returns {void} */ Annotation.prototype.getCustomData = function (annotation) { var customData; if (annotation.ExistingCustomData && !annotation.CustomData) { customData = JSON.parse(annotation.ExistingCustomData); } else if (annotation.CustomData === null) { if (annotation.shapeAnnotationType === 'sticky') { customData = this.pdfViewer.stickyNotesSettings.customData; } if (annotation.shapeAnnotationType === 'Stamp') { customData = this.pdfViewer.stampSettings.customData; } if (annotation.shapeAnnotationType === 'FreeText') { customData = this.pdfViewer.freeTextSettings.customData; } if (annotation.id === 'shape') { customData = this.getShapeData(annotation.ShapeAnnotationType, annotation.subject); } if (annotation.id === 'measure') { customData = this.getMeasureData(annotation.Subject); } if (annotation.shapeAnnotationType === 'textMarkup') { customData = this.getTextMarkupData(annotation.subject); } if (annotation.shapeAnnotationType === 'Ink') { customData = this.pdfViewer.inkAnnotationSettings.customData; } } else { var data = annotation.CustomData ? annotation.CustomData : annotation.customData; if (!isNullOrUndefined(data)) { customData = typeof data === 'string' ? JSON.parse(data) : data; } } return customData; }; /** * @param {string} type - type * @param {string} subject - subject * @private * @returns {void} */ Annotation.prototype.getShapeData = function (type, subject) { var customData; if (type === 'Line' && subject !== 'Arrow' && this.pdfViewer.lineSettings.customData) { customData = this.pdfViewer.lineSettings.customData; } else if ((type === 'LineWidthArrowHead' || subject === 'Arrow') && this.pdfViewer.arrowSettings.customData) { customData = this.pdfViewer.arrowSettings.customData; } else if ((type === 'Rectangle' || type === 'Square') && this.pdfViewer.rectangleSettings.customData) { customData = this.pdfViewer.rectangleSettings.customData; } else if ((type === 'Ellipse' || type === 'Circle') && this.pdfViewer.circleSettings.customData) { customData = this.pdfViewer.circleSettings.customData; } else if (type === 'Polygon' && this.pdfViewer.polygonSettings.customData) { customData = this.pdfViewer.polygonSettings.customData; } else if (this.pdfViewer.annotationSettings.customData) { customData = this.pdfViewer.annotationSettings.customData; } return customData; }; /** * @param {string} type - type * @private * @returns {void} */ Annotation.prototype.getMeasureData = function (type) { var customData; if ((type === 'Distance' || type === 'Distance calculation') && this.pdfViewer.distanceSettings.customData) { customData = this.pdfViewer.distanceSettings.customData; } else if ((type === 'Line' || type === 'Perimeter calculation') && this.pdfViewer.lineSettings.customData) { customData = this.pdfViewer.lineSettings.customData; } else if ((type === 'Polygon' || type === 'Area calculation' || type === 'Volume calculation') && this.pdfViewer.polygonSettings.customData) { customData = this.pdfViewer.polygonSettings.customData; } else if ((type === 'Radius' || type === 'Radius calculation') && this.pdfViewer.radiusSettings.customData) { customData = this.pdfViewer.radiusSettings.customData; } else if (this.pdfViewer.annotationSettings.customData) { customData = this.pdfViewer.annotationSettings.customData; } return customData; }; /** * @param {string} type - type * @private * @returns {void} */ Annotation.prototype.getTextMarkupData = function (type) { var customData; if (type === 'Highlight' && this.pdfViewer.highlightSettings.customData) { customData = this.pdfViewer.highlightSettings.customData; } else if (type === 'Underline' && this.pdfViewer.underlineSettings.customData) { customData = this.pdfViewer.underlineSettings.customData; } else if (type === 'Strikethrough' && this.pdfViewer.strikethroughSettings.customData) { customData = this.pdfViewer.strikethroughSettings.customData; } else if (this.pdfViewer.annotationSettings.customData) { customData = this.pdfViewer.annotationSettings.customData; } return customData; }; /** * @param {string} type - type * @private * @returns {void} */ Annotation.prototype.getData = function (type) { var customData; if (type === 'FreeText' && this.pdfViewer.freeTextSettings.customData) { customData = this.pdfViewer.freeTextSettings.customData; } else if ((type === 'image' || type === 'Stamp') && this.pdfViewer.stampSettings.customData) { customData = this.pdfViewer.stampSettings.customData; } else if (type === 'sticky' && this.pdfViewer.stickyNotesSettings.customData) { customData = this.pdfViewer.stickyNotesSettings.customData; } else if (this.pdfViewer.annotationSettings.customData) { customData = this.pdfViewer.annotationSettings.customData; } return customData; }; /** * @private * @returns {void} */ Annotation.prototype.clearAnnotationStorage = function () { var sessionSize = PdfViewerBase.sessionStorageManager.getWindowSessionStorageSize(); var maxSessionSize = 4500; if (this.pdfViewerBase.isDeviceiOS || this.pdfViewerBase.isMacSafari) { maxSessionSize = 2000; } if (sessionSize > maxSessionSize) { var storageLength = PdfViewerBase.sessionStorageManager.getSessionLength(); var annotationList = []; for (var i = 0; i < storageLength; i++) { if (PdfViewerBase.sessionStorageManager.getKey(i) && PdfViewerBase.sessionStorageManager.getKey(i).split('_')[3]) { if (PdfViewerBase.sessionStorageManager.getKey(i).split('_')[3] === 'annotations') { this.pdfViewerBase.annotationStorage[PdfViewerBase.sessionStorageManager.getKey(i)] = PdfViewerBase.sessionStorageManager.getItem(PdfViewerBase.sessionStorageManager.getKey(i)); annotationList.push(PdfViewerBase.sessionStorageManager.getKey(i)); } } } if (annotationList) { for (var i = 0; i < annotationList.length; i++) { PdfViewerBase.sessionStorageManager.removeItem(annotationList[parseInt(i.toString(), 10)]); } } } }; /** * @param {any} annotation - annotation * @private * @returns {Object} - Object */ Annotation.prototype.checkAnnotationCollection = function (annotation) { var collections = this.pdfViewer.annotationCollection; if (collections && annotation) { for (var i = 0; i < collections.length; i++) { if (collections[parseInt(i.toString(), 10)].annotationId === annotation.annotName) { this.pdfViewer.annotationCollection.splice(i, 1); return { isExisting: true, position: i }; } } } return { isExisting: false, position: null }; }; /** * @param {any} annotation - annotation * @private * @returns {void} */ Annotation.prototype.updateAnnotationCollection = function (annotation) { var collections = this.pdfViewer.annotationCollection; if (collections && annotation) { for (var i = 0; i < collections.length; i++) { if (collections[parseInt(i.toString(), 10)].annotationId === annotation.annotName || collections[parseInt(i.toString(), 10)].annotationId === annotation.annotationId) { this.removedAnnotationCollection.push(collections[parseInt(i.toString(), 10)]); this.pdfViewer.annotationCollection.splice(i, 1); break; } } } }; /** * @param {any} annotation - annotation * @param {number} pageNumber - pageNumber * @param {string} annotationType - annotationType * @private * @returns {void} */ Annotation.prototype.updateImportAnnotationCollection = function (annotation, pageNumber, annotationType) { if (this.pdfViewerBase.isImportAction) { if (this.pdfViewerBase.importedAnnotation && this.pdfViewerBase.importedAnnotation[parseInt(pageNumber.toString(), 10)]) { var currentPageAnnotations = this.pdfViewerBase.importedAnnotation[parseInt(pageNumber.toString(), 10)]; if (currentPageAnnotations["" + annotationType] && !isNullOrUndefined(this.pdfViewerBase.importedAnnotation[parseInt(pageNumber.toString(), 10)].annotationOrder)) { this.pdfViewerBase.importedAnnotation[parseInt(pageNumber.toString(), 10)].annotationOrder = this.pdfViewerBase.importedAnnotation[parseInt(pageNumber.toString(), 10)].annotationOrder.filter(function (currentAnnotation) { return !(annotation.annotName === currentAnnotation.AnnotName || annotation.annotName === currentAnnotation.annotName); }); } if (!isNullOrUndefined(this.pdfViewerBase.importedAnnotation) && !isNullOrUndefined(this.pdfViewerBase.importedAnnotation[parseInt(pageNumber.toString(), 10)]) && !isNullOrUndefined(this.pdfViewerBase.importedAnnotation[parseInt(pageNumber.toString(), 10)]["" + annotationType])) { this.pdfViewerBase.importedAnnotation[parseInt(pageNumber.toString(), 10)]["" + annotationType] = this.pdfViewerBase.importedAnnotation[parseInt(pageNumber.toString(), 10)]["" + annotationType].filter(function (currentAnnotation) { return annotation.annotName !== currentAnnotation.AnnotName; }); } } } var documentcollections = this.pdfViewerBase.documentAnnotationCollections; if (documentcollections && documentcollections[parseInt(pageNumber.toString(), 10)]) { var documentPageCollections = documentcollections[parseInt(pageNumber.toString(), 10)]; if (documentPageCollections && documentPageCollections["" + annotationType]) { for (var i = 0; i < documentPageCollections["" + annotationType].length; i++) { if (annotation.annotName === documentPageCollections["" + annotationType][parseInt(i.toString(), 10)].AnnotName) { this.pdfViewerBase.documentAnnotationCollections[parseInt(pageNumber.toString(), 10)]["" + annotationType].splice(i, 1); break; } } } } }; /** * Select the annotations using annotation object or annotation Id. * * @param {string | object} annotationId - annptationId * @returns {void} */ Annotation.prototype.selectAnnotation = function (annotationId) { var annotation; var id; if (typeof annotationId === 'object') { annotation = annotationId; id = annotation.annotationId; annotation = this.getAnnotationsFromAnnotationCollections(id); } if (typeof annotationId === 'string') { annotation = this.getAnnotationsFromAnnotationCollections(annotationId); id = annotationId; } if (annotation) { var pageIndex = isNullOrUndefined(annotation.pageNumber) ? annotation.pageIndex : annotation.pageNumber; var isRender = false; isRender = this.findRenderPageList(pageIndex); var currentSelector = this.pdfViewer.annotationSelectorSettings; //let pageIndex: number = this.getPageNumberFromAnnotationCollections(annotation); if (annotation && pageIndex >= 0) { if (annotation.shapeAnnotationType === 'textMarkup') { if (annotation.rect || annotation.bounds) { var scrollValue = this.pdfViewerBase.pageSize[parseInt(pageIndex.toString(), 10)].top * this.pdfViewerBase.getZoomFactor() + (this.getAnnotationTop(annotation)) * this.pdfViewerBase.getZoomFactor(); if (!this.isAnnotDeletionApiCall) { var scroll_1 = (scrollValue - 20).toString(); this.pdfViewerBase.viewerContainer.scrollTop = parseInt(scroll_1, 10); this.pdfViewerBase.viewerContainer.scrollLeft = this.getAnnotationLeft(annotation) * this.pdfViewerBase.getZoomFactor(); } } else { if (this.pdfViewer.navigation) { this.pdfViewer.navigation.goToPage(pageIndex + 1); } } } else { if (annotation.bounds) { var scrollValue = this.pdfViewerBase.pageSize[parseInt(pageIndex.toString(), 10)].top * this.pdfViewerBase.getZoomFactor() + (annotation.bounds.top) * this.pdfViewerBase.getZoomFactor(); var scrollLeft = annotation.bounds.left * this.pdfViewerBase.getZoomFactor(); if (annotation.shapeAnnotationType === 'Ink') { scrollValue = this.pdfViewerBase.pageSize[parseInt(pageIndex.toString(), 10)].top * this.pdfViewerBase.getZoomFactor() + (annotation.bounds.y) * this.pdfViewerBase.getZoomFactor(); scrollLeft = annotation.bounds.x * this.pdfViewerBase.getZoomFactor(); } if (!this.isAnnotDeletionApiCall) { var scroll_2 = (scrollValue - 20).toString(); this.pdfViewerBase.viewerContainer.scrollTop = parseInt(scroll_2, 10); this.pdfViewerBase.viewerContainer.scrollLeft = scrollLeft; } } else { if (this.pdfViewer.navigation) { this.pdfViewer.navigation.goToPage(pageIndex + 1); } } } if (isRender) { if (this.previousIndex) { this.pdfViewer.clearSelection(this.previousIndex); } this.pdfViewer.clearSelection(pageIndex); this.previousIndex = pageIndex; if (annotation.shapeAnnotationType === 'textMarkup') { this.pdfViewer.annotationModule.textMarkupAnnotationModule.clearCurrentAnnotationSelection(pageIndex, true); var canvasId = annotation.textMarkupAnnotationType === 'Highlight' ? '_blendAnnotationsIntoCanvas_' : '_annotationCanvas_'; var canvas = (canvasId === '_blendAnnotationsIntoCanvas_') ? this.pdfViewerBase.getElement(canvasId + pageIndex) : this.pdfViewerBase.getAnnotationCanvas(canvasId, pageIndex); var textMarkupAnnotation = this.getTextMarkupAnnotations(pageIndex, annotation); if (textMarkupAnnotation) { this.textMarkupAnnotationModule.currentTextMarkupAnnotation = null; this.textMarkupAnnotationModule.isSelectedAnnotation = true; this.textMarkupAnnotationModule.showHideDropletDiv(true); this.textMarkupAnnotationModule.annotationClickPosition = null; this.textMarkupAnnotationModule.selectAnnotation(textMarkupAnnotation, canvas, pageIndex, null, true); this.textMarkupAnnotationModule.currentTextMarkupAnnotation = textMarkupAnnotation; this.textMarkupAnnotationModule.selectTextMarkupCurrentPage = pageIndex; this.textMarkupAnnotationModule.enableAnnotationPropertiesTool(true); this.textMarkupAnnotationModule.isSelectedAnnotation = false; if (this.pdfViewer.toolbarModule && this.pdfViewer.enableAnnotationToolbar) { this.pdfViewer.toolbarModule.annotationToolbarModule.isToolbarHidden = true; this.pdfViewer.toolbarModule.annotationToolbarModule. showAnnotationToolbar(this.pdfViewer.toolbarModule.annotationItem); } } } else if (annotation.shapeAnnotationType === 'stamp' || annotation.ShapeAnnotationType === 'stamp') { this.pdfViewer.select([annotation.uniqueKey], currentSelector); this.pdfViewer.annotation.onAnnotationMouseDown(); } else if (annotation.shapeAnnotationType === 'sticky' || annotation.ShapeAnnotationType === 'sticky') { this.pdfViewer.select([annotation.annotationId], currentSelector); this.pdfViewer.annotation.onAnnotationMouseDown(); } else if (annotation.uniqueKey) { this.pdfViewer.select([annotation.uniqueKey], currentSelector); this.pdfViewer.annotation.onAnnotationMouseDown(); } else { this.selectAnnotationId = id; this.isAnnotationSelected = true; this.annotationPageIndex = pageIndex; this.annotationType = annotation.stampAnnotationType; } var commentElement = document.getElementById(this.pdf