UNPKG

@syncfusion/ej2-pdfviewer

Version:
735 lines 210 kB
import { PdfViewerBase, DynamicStampItem, SignStampItem, StandardBusinessStampItem } from '../../index'; import { splitArrayCollection, processPathData } from '@syncfusion/ej2-drawings'; import { Browser } from '@syncfusion/ej2-base'; import { isNullOrUndefined } from '@syncfusion/ej2-base'; /** * The `StampAnnotation` module is used to handle annotation actions of PDF viewer. * * @hidden */ var StampAnnotation = /** @class */ (function () { function StampAnnotation(pdfviewer, pdfViewerBase) { /** * @private */ this.isStampAddMode = false; /** * @private */ this.stampPageNumber = []; /** * @private */ this.isAddAnnotationProgramatically = false; /** * @private */ this.customStampName = null; this.dynamicText = ''; this.pdfViewer = pdfviewer; this.pdfViewerBase = pdfViewerBase; } /** * @param {any} stampAnnotations - It describes about the stamp annotations * @param {number} pageNumber - It describes about the page number * @param {any} canvass - It describes about the canvas * @param {boolean} isImport - It describes about the isImport * @param {boolean} isAnnotOrderAction - It describes about the isAnnotOrderAction * @private * @returns {Promise<void>} - any */ StampAnnotation.prototype.renderStampAnnotations = function (stampAnnotations, pageNumber, canvass, isImport, isAnnotOrderAction) { var _this = this; return new Promise(function (resolve) { var isStampAdded = false; if (!isImport) { for (var p = 0; p < _this.stampPageNumber.length; p++) { if (_this.stampPageNumber[parseInt(p.toString(), 10)] === pageNumber) { isStampAdded = true; break; } } } if (isImport) { isStampAdded = false; } if (stampAnnotations && (!isStampAdded || isAnnotOrderAction)) { _this.stampPageNumber.push(pageNumber); var _loop_1 = function (s) { var annotation = stampAnnotations[parseInt(s.toString(), 10)]; annotation.annotationAddMode = _this.pdfViewer.annotationModule.findAnnotationMode(annotation, pageNumber, annotation.AnnotType); var Apperance = annotation['Apperarance']; var position = annotation['Rect']; var opacity = annotation['Opacity']; var pageIndex = parseFloat(stampAnnotations[parseInt(s.toString(), 10)]['pageNumber']); if (isNaN(pageIndex)) { pageIndex = stampAnnotations[parseInt(s.toString(), 10)]['PageNumber']; } var stampName = annotation['IsDynamic']; annotation.AnnotationSettings = annotation.AnnotationSettings ? annotation.AnnotationSettings : _this.pdfViewer.annotationModule.updateSettings(_this.pdfViewer.stampSettings); if (annotation.IsLocked) { annotation.AnnotationSettings.isLock = annotation.IsLocked; } var isImageStamp = _this.stampImageData(annotation); if (stampName && annotation['IconName'] && annotation['IconName'] !== 'Draft' && !isImageStamp && (isNullOrUndefined(annotation.template) || annotation.template === '')) { _this.retrieveDynamicStampAnnotation(annotation['IconName']); _this.isExistingStamp = true; var currentLocation = _this.calculateImagePosition(position, true); var rotation = annotation['RotateAngle']; for (var d = 0; d < Apperance.length; d++) { var stampShapes = Apperance[parseInt(d.toString(), 10)]; var stampType = stampShapes['type']; if (stampType === 'string' && stampShapes['text'] !== undefined) { var text = void 0; if (!isImport && stampShapes['text'].split('(').length > 1) { text = stampShapes['text'].split('(')[1].split(')')[0]; } else { text = stampShapes['text']; } if (text.split('(').length === 2) { if (text.split('(')[1].split(')')[0].toLowerCase() !== annotation['IconName'].toLowerCase()) { _this.dynamicText += text.split('(')[1].split(')')[0]; } } else if (text.toLowerCase() !== annotation['IconName'].toLowerCase()) { _this.dynamicText += text; } } } _this.renderStamp(currentLocation.left, currentLocation.top, currentLocation.width, currentLocation.height, pageIndex, opacity, rotation, canvass, annotation, true); resolve(); } else if (annotation['IconName'] && !isImageStamp && (isNullOrUndefined(annotation.template) || annotation.template === '')) { _this.retrievestampAnnotation(annotation['IconName']); _this.isExistingStamp = true; var currentLocation = _this.calculateImagePosition(position, true); var rotation = annotation['RotateAngle']; _this.renderStamp(currentLocation.left, currentLocation.top, currentLocation.width, currentLocation.height, pageIndex, opacity, rotation, canvass, annotation); _this.isExistingStamp = false; resolve(); } else { if (Apperance) { var _loop_2 = function (j) { var stampShapes = Apperance[parseInt(j.toString(), 10)]; var imageData = stampShapes['imagedata']; var currentDate = stampShapes['CreationDate']; var modifiedDate = stampShapes['ModifiedDate']; var rotationAngle = stampShapes['RotateAngle']; if (imageData) { var image_1 = new Image(); // eslint-disable-next-line var proxy_1 = _this; image_1.onload = function () { // This code is no more required.Since this issue have neen fixed in server side itself. // refer https://syncfusion.atlassian.net/browse/EJ2-54035 // if (position) { // let y: number = parseFloat(position.y ? position.y : position.Y); // if (y < 0) { // position.Y = (proxy.pdfViewerBase.pageSize[pageIndex].height + y) * (72/96); // } // } var currentLocation = proxy_1.calculateImagePosition(position, true); annotation.AnnotationSettings = annotation.AnnotationSettings ? annotation.AnnotationSettings : proxy_1.pdfViewer.customStampSettings.annotationSettings; proxy_1.renderCustomImage(currentLocation, pageIndex, image_1, currentDate, modifiedDate, rotationAngle, opacity, canvass, true, annotation); if (proxy_1.pdfViewer.annotationModule.annotationType === 'image') { proxy_1.pdfViewer.annotation.selectAnnotationFromCodeBehind(); proxy_1.pdfViewer.annotationModule.annotationType = null; } resolve(); }; image_1.src = imageData; } }; for (var j = 0; j < Apperance.length; j++) { _loop_2(j); } if (Apperance.length === 0) { resolve(); } } } }; for (var s = 0; s < stampAnnotations.length; s++) { _loop_1(s); } if (stampAnnotations.length === 0) { resolve(); } } }); }; /** * @param {any} stampAnnotations - It describes about the stamp annotations * @param {number} pageNumber - It describes about the page number * @param {any} canvass - It describes about the canvas * @param {boolean} isImport - It describes about the isImport * @param {boolean} isAnnotOrderAction - It describes about the isAnnotOrderAction * @param {boolean} isNeedToReorderCollection - It ensures whether the need to reorder the collection or not * @param {number} orderNumber - It gets the order number * @private * @returns {void} */ StampAnnotation.prototype.renderStampAnnotImage = function (stampAnnotations, pageNumber, canvass, isImport, isAnnotOrderAction, isNeedToReorderCollection, orderNumber) { var Appearance = stampAnnotations['Apperarance']; var position = stampAnnotations['Rect']; var opacity = stampAnnotations['Opacity']; var annotationSelectorSettings = stampAnnotations['AnnotationSelectorSettings']; var pageIndex = parseFloat(stampAnnotations['pageNumber']); if (Appearance) { var _loop_3 = function (j) { var stampShapes = Appearance[parseInt(j.toString(), 10)]; var imageData = stampShapes['imagedata']; var currentDate = stampShapes['CreationDate']; var modifiedDate = stampShapes['ModifiedDate']; var rotationAngle = stampShapes['RotateAngle']; if (imageData) { var image_2 = new Image(); // eslint-disable-next-line var proxy_2 = this_1; image_2.onload = function () { var currentLocation = proxy_2.calculateImagePosition(position, true); stampAnnotations.AnnotationSettings = stampAnnotations.AnnotationSettings ? stampAnnotations.AnnotationSettings : proxy_2.pdfViewer.customStampSettings.annotationSettings; proxy_2.renderCustomImage(currentLocation, pageIndex, image_2, currentDate, modifiedDate, rotationAngle, opacity, canvass, true, stampAnnotations, null, isNeedToReorderCollection, orderNumber); }; image_2.src = imageData; } }; var this_1 = this; for (var j = 0; j < Appearance.length; j++) { _loop_3(j); } } }; /** * @param {number} X - It describes about the X * @param {number} Y - It describes about the Y * @param {number} pageIndex - It describes about the page index * @private * @returns {PdfAnnotationBase} - pdf annotation base */ StampAnnotation.prototype.moveStampElement = function (X, Y, pageIndex) { var zoomFactor = this.pdfViewerBase.getZoomFactor(); X = X / zoomFactor; Y = Y / zoomFactor; var author = (!isNullOrUndefined(this.pdfViewer.annotationSettings.author) && this.pdfViewer.annotationSettings.author !== 'Guest') ? this.pdfViewer.annotationSettings.author : this.pdfViewer.stampSettings.author ? this.pdfViewer.stampSettings.author : 'Guest'; if (this.pdfViewerBase.isDynamicStamp) { if (this.pdfViewer.dateTimeFormat) { var dateTime = this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTimeFormat(); this.dynamicText = 'By ' + author + ' at ' + dateTime + ' '; } else { var today = (new Date()).toString().split(' ').splice(1, 3).join(' '); var time = (new Date()).toLocaleTimeString(); this.dynamicText = 'By ' + author + ' at ' + time + ' , ' + today + ' '; } } var annot; var annotation = this.currentStampAnnotation; var subject = (this.pdfViewer.annotationSettings.subject !== '' && !isNullOrUndefined(this.pdfViewer.annotationSettings.subject)) ? this.pdfViewer.annotationSettings.subject : this.pdfViewer.stampSettings.subject ? this.pdfViewer.stampSettings.subject : !isNullOrUndefined(annotation) ? annotation.iconName : ''; var annotationSelectorSettings = this.pdfViewer.stampSettings.annotationSelectorSettings; this.pdfViewerBase.updateSelectorSettings(annotationSelectorSettings); if (annotation && annotation.shapeAnnotationType === 'Image') { annot = { id: 'stamp' + this.pdfViewerBase.customStampCount, bounds: { x: X, y: Y, width: annotation.bounds.width, height: annotation.bounds.height }, pageIndex: pageIndex, data: annotation.data, modifiedDate: annotation.modifiedDate, shapeAnnotationType: 'Image', opacity: annotation.opacity, rotateAngle: annotation.RotationAngle, annotName: annotation.annotationName, comments: [], review: { state: '', stateModel: '', modifiedDate: '', author: annotation.author } }; } else if (annotation) { annot = { id: 'stamp' + this.pdfViewerBase.customStampCount, bounds: { x: X, y: Y, width: annotation.width, height: annotation.height }, pageIndex: pageIndex, data: annotation.pathdata, shapeAnnotationType: 'Stamp', strokeColor: annotation.strokeColor, fillColor: annotation.fillColor, opacity: 0.5, stampFillColor: annotation.stampFillColor, stampStrokeColor: annotation.stampStrokeColor, rotateAngle: annotation.RotateAngle, isDynamicStamp: this.pdfViewerBase.isDynamicStamp, dynamicText: this.dynamicText, subject: subject, annotationSelectorSettings: annotationSelectorSettings, icon: annotation.iconName }; } if (this.pdfViewerBase.currentSignatureAnnot) { annotation = this.pdfViewerBase.currentSignatureAnnot; if (annotation.shapeAnnotationType === 'SignatureText') { annot = { id: 'sign' + this.pdfViewerBase.signatureCount, bounds: { x: X, y: Y, width: annotation.bounds.width, height: annotation.bounds.height }, pageIndex: pageIndex, data: annotation.data, modifiedDate: '', shapeAnnotationType: 'SignatureText', thickness: annotation.thickness, strokeColor: annotation.strokeColor, opacity: annotation.opacity, signatureName: annotation.signatureName, fontFamily: annotation.fontFamily, fontSize: Math.floor((annotation.bounds.height / 2)) }; } else if (annotation.shapeAnnotationType === 'SignatureImage') { annot = { id: 'sign' + this.pdfViewerBase.signatureCount, bounds: { x: X, y: Y, width: annotation.bounds.width, height: annotation.bounds.height }, pageIndex: pageIndex, data: annotation.data, modifiedDate: '', shapeAnnotationType: 'SignatureImage', thickness: annotation.thickness, strokeColor: annotation.strokeColor, opacity: annotation.opacity, signatureName: annotation.signatureName }; } else { annot = { id: 'sign' + this.pdfViewerBase.signatureCount, bounds: { x: X, y: Y, width: annotation.bounds.width, height: annotation.bounds.height }, pageIndex: pageIndex, data: annotation.data, shapeAnnotationType: 'HandWrittenSignature', thickness: annotation.thickness, strokeColor: annotation.strokeColor, opacity: annotation.opacity, signatureName: annotation.signatureName }; } } return annot; }; StampAnnotation.prototype.ConvertPointToPixel = function (number) { return (number * (96 / 72)); }; StampAnnotation.prototype.calculateImagePosition = function (position, flags) { var positions = { width: 0, height: 0, left: 0, top: 0 }; var x = parseFloat(!isNullOrUndefined(position.x) ? position.x : position.X); var y = parseFloat(!isNullOrUndefined(position.y) ? position.y : position.Y); var newWidth = parseFloat(position.width ? position.width : position.Width); var newHeight = parseFloat(position.height ? position.height : position.Height); if (flags) { var width = this.ConvertPointToPixel(newWidth); var height = this.ConvertPointToPixel(newHeight); var left = this.ConvertPointToPixel(x); var top_1 = this.ConvertPointToPixel(y); positions = { width: width, height: height, left: left, top: top_1 }; } else { positions = { width: newWidth, height: newHeight, left: x, top: y }; } return positions; }; /** * @param {any} imageSource - It describes about the image source * @param {string} annotName - It describes about the annotation name * @private * @returns {void} */ StampAnnotation.prototype.createCustomStampAnnotation = function (imageSource, annotName) { var _this = this; var pageIndex = this.pdfViewerBase.currentPageNumber - 1; var image = new Image(); // eslint-disable-next-line var proxy = this; image.onload = function () { var stampSettings = _this.pdfViewer.customStampSettings; var customStampWidth = stampSettings.width > 0 ? stampSettings.width : 0; var customStampHeight = stampSettings.height > 0 ? stampSettings.height : 0; var standardImageRatio = 100; if (!(customStampWidth > 0 || customStampHeight > 0)) { if (image.naturalHeight >= image.naturalWidth) { customStampHeight = ((image.naturalHeight / image.naturalHeight) * standardImageRatio); customStampWidth = ((image.naturalWidth / image.naturalHeight) * standardImageRatio); } else { customStampHeight = ((image.naturalHeight / image.naturalWidth) * standardImageRatio); customStampWidth = ((image.naturalWidth / image.naturalWidth) * standardImageRatio); } } var customStampleft = 0; var customStamptop = 0; customStampleft = _this.pdfViewer.customStampSettings.left; customStamptop = _this.pdfViewer.customStampSettings.top; var positions = { width: customStampWidth, height: customStampHeight, left: customStampleft, top: customStamptop }; var currentDate = new Date().toLocaleDateString(); var modifiedDate = _this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime(); var rotationAngle = 0; proxy.renderCustomImage(positions, pageIndex, image, currentDate, modifiedDate, rotationAngle, 1, null, null, null, annotName); }; image.src = imageSource; }; /** * @param {number} X - It describes about the X * @param {number} Y - It describes about the Y * @param {number} width - It describes about the width * @param {number} height - It describes about the height * @param {number} pageIndex - It describes about the page index * @param {number} opacity - It describes about the opacity * @param {any} rotation - It describes about the rotation * @param {any} canvass - It describes about the canvas * @param {any} existingAnnotation - It describes about the existing annatation * @param {any} isDynamic - It describes about the isDynamic * @private * @returns {void} */ StampAnnotation.prototype.renderStamp = function (X, Y, width, height, pageIndex, opacity, rotation, canvass, existingAnnotation, isDynamic) { if (Browser.isDevice) { this.pdfViewerBase.customStampCount += 1; } var author = (this.pdfViewer.annotationSettings.author !== 'Guest') ? this.pdfViewer.annotationSettings.author : this.pdfViewer.stampSettings.author ? this.pdfViewer.stampSettings.author : 'Guest'; if (this.pdfViewerBase.isDynamicStamp) { var today = (new Date()).toString().split(' ').splice(1, 3).join(' '); var time = (new Date()).toLocaleTimeString(); this.dynamicText = 'By ' + author + ' at ' + time + ' , ' + today + ' '; } if (isDynamic) { this.dynamicText += ' '; this.pdfViewerBase.isDynamicStamp = true; } var annot; var annotationObject = null; var annotation = this.currentStampAnnotation; if (annotation) { if (width !== null && height !== null) { annotation.width = width; annotation.height = height; annotation.Opacity = opacity; annotation.RotateAngle = rotation; var annotationName = existingAnnotation['AnnotName']; annotation.AnnotName = annotationName; var state = existingAnnotation['State']; annotation.State = state; var annotationSettings = existingAnnotation['AnnotationSettings']; annotation.AnnotationSettings = annotationSettings ? annotationSettings : this.pdfViewer.annotationModule.updateAnnotationSettings(annotation); var annotationSelectorSettings = typeof (existingAnnotation['AnnotationSelectorSettings']) === 'string' ? JSON.parse(existingAnnotation['AnnotationSelectorSettings']) : existingAnnotation['AnnotationSelectorSettings']; annotation.AnnotationSelectorSettings = annotationSelectorSettings ? annotationSelectorSettings : this.pdfViewer.annotationSelectorSettings; var modifiedDate = existingAnnotation['ModifiedDate']; annotation.ModifiedDate = modifiedDate; var stateModel = existingAnnotation['StateNodel']; annotation.StateModel = stateModel; var lock = existingAnnotation['IsCommentLock']; annotation.IsCommentLock = lock; var text = existingAnnotation['Note']; annotation.Note = text; var author_1 = existingAnnotation['Author']; annotation.Author = author_1; var subject = existingAnnotation['Subject']; annotation.Subject = subject; var customData = this.pdfViewer.annotation.getCustomData(existingAnnotation); annotation.allowedInteractions = existingAnnotation['AllowedInteractions'] ? existingAnnotation['AllowedInteractions'] : existingAnnotation['allowedInteractions'] ? existingAnnotation['allowedInteractions'] : ['None']; annotation.CustomData = customData; var isPrint = true; if (!isNullOrUndefined(existingAnnotation.IsPrint)) { isPrint = existingAnnotation.IsPrint; } else { isPrint = !isNullOrUndefined(existingAnnotation.IsPrint) ? existingAnnotation.IsPrint : existingAnnotation.AnnotationSettings.isPrint; } annotation.isPrint = isPrint; if (annotation.Author === null) { annotation.Author = (this.pdfViewer.annotationSettings.author !== 'Guest') ? this.pdfViewer.annotationSettings.author : this.pdfViewer.stampSettings.author ? this.pdfViewer.stampSettings.author : 'Guest'; } var annotationComments = existingAnnotation['Comments']; annotation.Comments = this.pdfViewer.annotationModule.getAnnotationComments(annotationComments, existingAnnotation, author_1); } else { var annotationName = this.pdfViewer.annotation.createGUID(); var commentsDivid = this.pdfViewer.annotation.stickyNotesAnnotationModule.addComments('stamp', pageIndex + 1); if (commentsDivid) { document.getElementById(commentsDivid).id = annotationName; } annotation.AnnotationSettings = this.pdfViewer.annotationModule.updateSettings(this.pdfViewer.stampSettings); annotation.AnnotName = annotationName; annotation.Comments = []; annotation.State = ''; annotation.StateModel = ''; annotation.Note = ''; annotation.Opacity = 1; annotation.RotateAngle = 0; annotation.ModifiedDate = this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime(); annotation.Author = (this.pdfViewer.annotationSettings.author !== 'Guest') ? this.pdfViewer.annotationSettings.author : this.pdfViewer.stampSettings.author ? this.pdfViewer.stampSettings.author : 'Guest'; annotation.Subject = (this.pdfViewer.annotationSettings.subject !== '' && !isNullOrUndefined(this.pdfViewer.annotationSettings.subject)) ? this.pdfViewer.annotationSettings.subject : this.pdfViewer.stampSettings.subject ? this.pdfViewer.stampSettings.subject : annotation.iconName; } var collectionData = processPathData(annotation.pathdata); var csData = splitArrayCollection(collectionData); var annotationAddMode = existingAnnotation ? existingAnnotation.annotationAddMode : 'UI Drawn Annotation'; annotation.AnnotationSelectorSettings = annotation.AnnotationSelectorSettings ? annotation.AnnotationSelectorSettings : this.pdfViewer.annotationSelectorSettings; annot = { id: 'stamp' + this.pdfViewerBase.customStampCount, bounds: { x: X, y: Y, width: annotation.width, height: annotation.height }, pageIndex: pageIndex, data: annotation.pathdata, modifiedDate: annotation.ModifiedDate, shapeAnnotationType: 'Stamp', strokeColor: annotation.strokeColor, fillColor: annotation.fillColor, opacity: annotation.Opacity, stampFillColor: annotation.stampFillColor, stampStrokeColor: annotation.stampStrokeColor, rotateAngle: annotation.RotateAngle, isDynamicStamp: this.pdfViewerBase.isDynamicStamp, dynamicText: this.dynamicText, annotName: annotation.AnnotName, notes: annotation.Note, comments: annotation.Comments, review: { state: annotation.State, stateModel: annotation.StateModel, modifiedDate: annotation.ModifiedDate, author: annotation.Author }, subject: annotation.Subject, annotationSelectorSettings: annotation.AnnotationSelectorSettings, annotationSettings: annotation.AnnotationSettings, allowedInteractions: annotation.allowedInteractions, annotationAddMode: annotationAddMode, isPrint: annotation.isPrint, isCommentLock: annotation.IsCommentLock }; annotationObject = { stampAnnotationType: 'path', author: annotation.Author, modifiedDate: annotation.ModifiedDate, subject: annotation.Subject, note: annotation.Note, strokeColor: annotation.strokeColor, fillColor: annotation.fillColor, opacity: annotation.Opacity, stampFillcolor: annotation.stampFillColor, rotateAngle: annotation.RotateAngle, creationDate: annotation.creationDate, pageNumber: pageIndex, icon: annotation.iconName, stampAnnotationPath: csData, randomId: 'stamp' + this.pdfViewerBase.customStampCount, isDynamicStamp: this.pdfViewerBase.isDynamicStamp, dynamicText: this.dynamicText, bounds: { left: X, top: Y, width: annotation.width, height: annotation.height }, annotName: annotation.AnnotName, comments: annotation.Comments, review: { state: annotation.State, stateModel: annotation.StateModel, author: annotation.Author, modifiedDate: annotation.ModifiedDate }, shapeAnnotationType: 'stamp', annotationSelectorSettings: this.getSettings(annotation), annotationSettings: annotation.AnnotationSettings, customData: this.pdfViewer.annotation.getCustomData(annotation), allowedInteractions: annotation.allowedInteractions, isPrint: annotation.isPrint, isCommentLock: annotation.IsCommentLock, isMaskedImage: annotation.IsMaskedImage, customStampName: '', template: annotation ? annotation.template : null, templateSize: annotation ? annotation.templateSize : 0 }; this.storeStampInSession(pageIndex, annotationObject); this.pdfViewer.add(annot); if (this.isAddAnnotationProgramatically) { this.triggerAnnotationAdd(annot, annotation); } if (isNullOrUndefined(canvass)) { canvass = this.pdfViewerBase.getAnnotationCanvas('_annotationCanvas_', pageIndex); } this.pdfViewer.renderDrawing(canvass, pageIndex); if (this.pdfViewerBase.stampAdded) { this.triggerAnnotationAdd(annot, annotation); this.pdfViewerBase.isNewStamp = true; this.pdfViewer.annotation.addAction(pageIndex, null, annot, 'Addition', '', annot, annot); } this.pdfViewerBase.stampAdded = false; if (!this.isExistingStamp) { annotation.creationDate = new Date().toLocaleDateString(); annotation.modifiedDate = this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime(); } } this.resetAnnotation(); }; /** * @param {any} annotation - It describes about the annotation * @private * @returns {any} - any */ StampAnnotation.prototype.getSettings = function (annotation) { var selector = this.pdfViewer.annotationSelectorSettings; if (annotation.AnnotationSelectorSettings) { selector = annotation.AnnotationSelectorSettings; } else if (this.pdfViewer.stampSettings.annotationSelectorSettings) { selector = this.pdfViewer.stampSettings.annotationSelectorSettings; } return selector; }; /** * @private * @returns {void} */ StampAnnotation.prototype.resetAnnotation = function () { this.pdfViewerBase.isDynamicStamp = false; this.dynamicText = ''; this.currentStampAnnotation = null; if (!Browser.isDevice) { this.pdfViewerBase.customStampCount += 1; } }; /** * @param {number} pageNumber - It describes about the page number * @param {any} annotation - It describes about the annotation * @param {number} opacity - It describes about the opacity * @private * @returns {void} */ StampAnnotation.prototype.updateDeleteItems = function (pageNumber, annotation, opacity) { this.pdfViewerBase.updateDocumentEditedProperty(true); var annotationObject = null; var isStampSaved = false; annotation.modifiedDate = this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime(); annotation.author = (this.pdfViewer.annotationSettings.author !== 'Guest') ? this.pdfViewer.annotationSettings.author : this.pdfViewer.stampSettings.author ? this.pdfViewer.stampSettings.author : 'Guest'; if (opacity) { var annotationName = this.pdfViewer.annotation.createGUID(); var commentsDivid = this.pdfViewer.annotation.stickyNotesAnnotationModule.addComments('stamp', pageNumber + 1); if (commentsDivid) { document.getElementById(commentsDivid).id = annotationName; } annotation.annotName = annotationName; annotation.Comments = []; annotation.State = ''; annotation.StateModel = ''; annotation.Note = ''; annotation.Opacity = 1; annotation.RotateAngle = 0; } if (annotation.shapeAnnotationType === 'Stamp') { annotation.isPrint = this.pdfViewer.stampSettings.isPrint; } var annotationSelectorSettings = this.pdfViewer.stampSettings.annotationSelectorSettings ? this.pdfViewer.stampSettings.annotationSelectorSettings : this.pdfViewer.annotationSelectorSettings; var allowedInteractions = this.pdfViewer.stampSettings.allowedInteractions ? this.pdfViewer.stampSettings.allowedInteractions : this.pdfViewer.annotationSettings.allowedInteractions; if (annotation.shapeAnnotationType === 'Image') { annotation.Author = (this.pdfViewer.annotationSettings.author !== 'Guest') ? this.pdfViewer.annotationSettings.author : this.pdfViewer.customStampSettings.author ? this.pdfViewer.customStampSettings.author : 'Guest'; annotation.Subject = (this.pdfViewer.annotationSettings.subject !== '' && !isNullOrUndefined(this.pdfViewer.annotationSettings.subject)) ? this.pdfViewer.annotationSettings.subject : this.pdfViewer.customStampSettings.subject ? this.pdfViewer.customStampSettings.subject : ''; annotation.isPrint = this.pdfViewer.customStampSettings.isPrint; this.customStampName = this.customStampName ? this.customStampName : (this.currentStampAnnotation && this.currentStampAnnotation.signatureName) ? this.currentStampAnnotation.signatureName : annotation.id; annotationObject = { stampAnnotationType: 'image', author: annotation.author, modifiedDate: annotation.modifiedDate, subject: annotation.Subject, note: '', strokeColor: '', fillColor: '', opacity: opacity, rotateAngle: '0', creationDate: annotation.currentDate, pageNumber: pageNumber, icon: '', stampAnnotationPath: annotation.data, randomId: annotation.id, bounds: { left: annotation.bounds.x, top: annotation.bounds.y, width: annotation.bounds.width, height: annotation.bounds.height }, stampFillcolor: '', isDynamicStamp: false, annotName: annotation.annotName, comments: [], review: { state: '', stateModel: '', author: annotation.author, modifiedDate: annotation.modifiedDate }, shapeAnnotationType: 'stamp', annotationSelectorSettings: annotationSelectorSettings, annotationSettings: this.pdfViewer.annotationModule.updateSettings(this.pdfViewer.customStampSettings), customData: this.pdfViewer.annotationModule.getData('image'), isPrint: annotation.isPrint, allowedInteractions: allowedInteractions, isCommentLock: false, isMaskedImage: annotation.isMaskedImage, customStampName: this.customStampName, template: annotation ? annotation.template : null, templateSize: annotation ? annotation.templateSize : 0 }; } else if (annotation.stampAnnotationType) { annotationObject = { stampAnnotationType: annotation.stampAnnotationType, author: annotation.author, modifiedDate: annotation.modifiedDate, subject: annotation.Subject, note: annotation.Note, strokeColor: annotation.strokeColor, fillColor: annotation.fillColor, opacity: annotation.opacity, stampFillcolor: annotation.stampFillcolor, rotateAngle: annotation.rotateAngle, creationDate: annotation.creationDate, pageNumber: annotation.pageNumber, icon: annotation.icon, stampAnnotationPath: annotation.stampAnnotationPath, randomId: annotation.randomId, isDynamicStamp: annotation.isDynamicStamp, dynamicText: annotation.dynamicText, bounds: { left: annotation.bounds.left, top: annotation.bounds.top, width: annotation.bounds.width, height: annotation.bounds.height }, annotName: annotation.annotName, comments: annotation.Comments, review: { state: annotation.State, stateModel: annotation.StateModel, author: annotation.author, modifiedDate: annotation.ModifiedDate }, shapeAnnotationType: 'stamp', annotationSelectorSettings: annotationSelectorSettings, annotationSettings: this.pdfViewer.annotationModule.updateSettings(this.pdfViewer.stampSettings), customData: this.pdfViewer.annotationModule.getData(annotation.stampAnnotationType), isPrint: annotation.isPrint, allowedInteractions: allowedInteractions, isCommentLock: annotation.isCommentLock, isMaskedImage: annotation.isMaskedImage, customStampName: '', template: annotation ? annotation.template : null, templateSize: annotation ? annotation.templateSize : 0 }; } else { annotationObject = { stampAnnotationType: annotation.shapeAnnotationType, author: annotation.author, modifiedDate: annotation.modifiedDate, subject: annotation.subject, note: annotation.notes, strokeColor: annotation.strokeColor, fillColor: annotation.fillColor, opacity: annotation.opacity, stampFillcolor: annotation.stampFillColor, rotateAngle: annotation.rotateAngle, creationDate: annotation.creationDate, pageNumber: annotation.pageIndex, icon: annotation.icon, stampAnnotationPath: annotation.data, randomId: annotation.id, isDynamicStamp: annotation.isDynamicStamp, dynamicText: annotation.dynamicText, shapeAnnotationType: 'stamp', bounds: { left: annotation.bounds.x, top: annotation.bounds.y, width: annotation.bounds.width, height: annotation.bounds.height }, annotName: annotation.annotName, comments: annotation.Comments, review: { state: annotation.State, stateModel: annotation.StateModel, author: annotation.author, modifiedDate: annotation.ModifiedDate }, annotationSelectorSettings: annotationSelectorSettings, annotationSettings: this.pdfViewer.annotationModule.updateSettings(this.pdfViewer.stampSettings), customData: this.pdfViewer.annotationModule.getData(annotation.shapeAnnotationType), isPrint: annotation.isPrint, allowedInteractions: allowedInteractions, isCommentLock: annotation.isCommentLock, isMaskedImage: annotation.isMaskedImage, customStampName: '', template: annotation ? annotation.template : null, templateSize: annotation ? annotation.templateSize : 0 }; } if (opacity) { if (annotation.shapeAnnotationType !== 'Image') { var collectionData = processPathData(annotation.data); var csData = splitArrayCollection(collectionData); annotationObject.stampAnnotationPath = csData; } annotation.creationDate = new Date().toLocaleDateString(); if (!Browser.isDevice && annotation.wrapper) { annotationObject.bounds.width = annotation.wrapper.actualSize.width; annotationObject.bounds.height = annotation.wrapper.actualSize.height; annotationObject.bounds.left = annotation.wrapper.bounds.x; annotationObject.bounds.top = annotation.wrapper.bounds.y; } annotationObject.opacity = opacity; if (this.pdfViewerBase.stampAdded) { this.storeStampInSession(pageNumber, annotationObject); isStampSaved = true; var bounds = { left: annotationObject.bounds.left, top: annotationObject.bounds.top, width: annotationObject.bounds.width, height: annotationObject.bounds.height }; this.pdfViewerBase.updateDocumentEditedProperty(true); var settings = { opacity: annotationObject.opacity, author: annotationObject.author, modifiedDate: annotationObject.modifiedDate }; if (annotation.shapeAnnotationType === 'Image') { this.pdfViewerBase.stampAdded = false; this.pdfViewer.fireAnnotationAdd(annotationObject.pageNumber, annotationObject.annotName, 'Image', bounds, settings, null, null, null, null, null, this.customStampName); this.customStampName = null; } else { this.pdfViewer.fireAnnotationAdd(annotationObject.pageNumber, annotationObject.annotName, 'Stamp', bounds, settings); } this.pdfViewer.annotation.addAction(pageNumber, null, annotation, 'Addition', '', annotation, annotationObject); } } if (!isStampSaved) { this.storeStampInSession(pageNumber, annotationObject); } }; /** * @param {any} position - It describes about the position * @param {any} pageIndex - It describes about the page index * @param {any} image - It describes about the image * @param {any} currentDate - It describes about the current date * @param {any} modifiedDate - It describes about the modified date * @param {any} RotationAngle - It describes about the rotation angle * @param {any} opacity - It describes about the opacity * @param {any} canvas - It describes about the canvas * @param {boolean} isExistingStamp - It describes about the whether isExistingStamp is true or not * @param {any} annotation - It describes about the annotation * @param {string} annotName - It describes about the annotation name * @param {boolean} isNeedToReorderCollection - It ensures whether the need to reorder the collection or not * @param {number} orderNumber - It gets the order number * @private * @returns {void} */ StampAnnotation.prototype.renderCustomImage = function (position, pageIndex, image, currentDate, modifiedDate, RotationAngle, opacity, canvas, isExistingStamp, annotation, annotName, isNeedToReorderCollection, orderNumber) { var annotationObject = null; var annotationName; var author; var subject; var isCommentsLock; var isCustomStamp = this.pdfViewer.customStampSettings.left > 0 && this.pdfViewer.customStampSettings.top > 0 ? true : false; var annotationSettings = this.pdfViewer.annotationModule.updateSettings(this.pdfViewer.customStampSettings); var allowedInteractions = this.pdfViewer.stampSettings.allowedInteractions ? this.pdfViewer.stampSettings.allowedInteractions : this.pdfViewer.annotationSettings.allowedInteractions; var isTemplate = !isNullOrUndefined(annotation) && annotation.template ? true : false; if (Browser.isDevice) { this.pdfViewerBase.customStampCount += 1; } if (isExistingStamp) { annotationName = annotation.AnnotName; author = annotation.Author; subject = annotation.Subject; isCommentsLock = annotation.IsCommentLock; annotationSettings = annotation.AnnotationSettings ? annotation.AnnotationSettings : this.pdfViewer.annotationModule.updateSettings(this.pdfViewer.customStampSettings); allowedInteractions = annotation.AllowedInteractions ? annotation.AllowedInteractions : this.pdfViewer.annotationModule.updateAnnotationAllowedInteractions(annotation); if (author === null) { author = (this.pdfViewer.annotationSettings.author !== 'Guest') ? this.pdfViewer.annotationSettings.author : this.pdfViewer.customStampSettings.author ? this.pdfViewer.customStampSettings.author : 'Guest'; } if (subject === null) { subject = (this.pdfViewer.annotationSettings.subject !== '' && !isNullOrUndefined(this.pdfViewer.annotationSettings.subject)) ? this.pdfViewer.annotationSettings.subject : this.pdfViewer.customStampSettings.subject ? this.pdfViewer.customStampSettings.subject : ''; } if (annotation.IsLocked && annotation.AnnotationSettings) { annotation.AnnotationSettings.isLock = annotation.IsLocked; } else { annotationSettings.isLock = annotation.IsLocked; } } else { annotationName = this.pdfViewer.annotation.createGUID(); author = (this.pdfViewer.annotationSettings.author !== 'Guest') ? this.pdfViewer.annotationSettings.author : this.pdfViewer.customStampSettings.author ? this.pdfViewer.customStampSettings.author : 'Guest'; subject = (this.pdfViewer.annotationSettings.subject !== '' && !isNullOrUndefined(this.pdfViewer.annotationSettings.subject)) ? this.pdfViewer.annotationSettings.subject : this.pdfViewer.customStampSettings.subject ? this.pdfViewer.customStampSettings.subject : ''; isCommentsLock = false; } if (!modifiedDate) { modifiedDate = annotation.ModifiedDate ? annotation.ModifiedDate : new Date().toLocaleString(); } var annotationAddMode = annotation ? annotation.annotationAddMode : 'UI Drawn Annotation '; var isPrint = true; if (!isExistingStamp) { isPrint = this.pdfViewer.customStampSettings.isPrint; } else { if (annotation.annotationAddMode === 'Imported Annotation') { isPrint = annotation.IsPrint; } else if (annotation.AnnotationSettings) { isPrint = annotation.AnnotationSettings.isPrint; } } var annotationSelectorSettings; if (!isNullOrUndefined(annotation) && !isNullOrUndefined(annotation.AnnotationSelectorSettings)) { annotationSelectorSettings = typeof (annotation.AnnotationSelectorSettings) === 'string' ? JSON.parse(annotation.AnnotationSelectorSettings) : annotation.AnnotationSelectorSettings; } else { annotationSelectorSettings = this.pdfViewer.stampSettings.annotationSelectorSettings; this.pdfViewerBase.updateSelectorSettings(annotationSelectorSettings); } var annot = { id: 'stamp' + this.pdfViewerBase.customStampCount, allowedInteractions: allowedInteractions, bounds: { x: position.left, y: position.top, width: position.width, height: position.height }, pageIndex: pageIndex, data: image.src, modifiedDate: modifiedDate, shapeAnnotationType: 'Image', opacity: opacity, rotateAngle: RotationAngle, annotName: annotationName, comments: [], review: { state: '', stateModel: '', modifiedDate: '', author: author }, annotationSettings: annotationSettings, annotationSelectorSettings: annotationSelectorSettings, annotationAddMode: annotationAddMode, signatureName: annotName, isPrint: isPrint, isCommentLock: isCommentsLock, subject: subject, template: isTemplate ? annotation.template : null, templateSize: annotation ? annotation.templateSize : 0 }; this.currentStampAnnotation = annot; if (isExistingStamp || isCustomStamp) { if (!annotation) { this.isStampAnnotSelected = false; annotation = annot; annotation.Note = ''; annotation.State = ''; annotation.StateModel = ''; var commentsDivid = this.pdfViewer.annotation.stickyNotesAnnotationModule.addComments('stamp', pageIndex + 1); if (commentsDivid) { document.getElementById(commentsDivid).id = annotationName; } } annotationObject = { stampAnnotationType: 'image', author: author, allowedInteractions: allowedInteractions, modifiedDate: modifiedDate, subject: subject, note: annotation.Note, strokeColor: '', fillColor: '', opacity: opacity, rotateAngle: '0', creationDate: currentDate, pageNumber: pageIndex, icon: '', stampAnnotationPath: image.src, randomId: 'stamp' + this.pdfViewerBase.customStampCount, bounds: { left: position.left, top: position.top, width: position.width, height: position.height }, stampFillcolor: '', isDynamicStamp: false, annotName: annotationName, comments: this.pdfViewer.annotationModule.getAnnotationComments(annotation.Comments, annotation, annotation.Author), review: { state: annotation.State, stateModel: annotation.StateModel, author: author, modifiedDate: modifiedDate }, shapeAnnotationType: 'stamp', annotationSelectorSettings: annotationSelectorSettings, annotationSettings: annotationSettings, customData: this.pdfViewer.annotation.getCustomData(annotation), isPrint: isPrint, isCommentLock: isCommentsLock, isMaskedImage: annotation.IsMaskedImage, customStampName: annotation.CustomStampName, template: isTemplate ? annotation.template : null, temp