UNPKG

@syncfusion/ej2-pdfviewer

Version:
1,010 lines 146 kB
import { PdfViewerBase } from '../index'; import { createElement, isNullOrUndefined, isBlazor, SanitizeHtmlHelper, Browser } from '@syncfusion/ej2-base'; import { Dialog } from '@syncfusion/ej2-popups'; import { splitArrayCollection, processPathData, getPathString } from '@syncfusion/ej2-drawings'; import { TextBox } from '@syncfusion/ej2-inputs'; import { cloneObject } from '../drawing/drawing-util'; import { CheckBox } from '@syncfusion/ej2-buttons'; import { Tab } from '@syncfusion/ej2-navigations'; import { Button } from '@syncfusion/ej2-buttons'; import { DisplayMode } from './types'; /* eslint-disable valid-jsdoc */ /** * * @param {Event} e - The event object. * @param {any} args - Additional arguments passed to the event handler. * @hidden * @returns {void} */ var Signature = /** @class */ (function () { /** * Initialize the constructor of blazorUIadapater. * * @private * @param { PdfViewer } pdfViewer - Specified PdfViewer class. * @param { PdfViewerBase } pdfViewerBase - The pdfViewerBase. */ function Signature(pdfViewer, pdfViewerBase) { var _this = this; this.mouseMoving = true; this.canvasTouched = false; this.imageSignatureDataUrl = ''; this.drawSignatureDataUrl = ''; this.newObject = []; /** * @private */ this.outputString = ''; /** * @private */ this.drawOutputString = ''; /** * @private */ this.imageOutputString = ''; /** * @private */ this.signaturecollection = []; /** * @private */ this.outputcollection = []; /** * @private */ this.signAnnotationIndex = []; this.fontsign = []; this.signfontStyle = []; this.isSaveSignature = false; this.isSaveInitial = false; this.isInitialFiledSaveSignature = false; this.isSignatureFieldsSaveSignature = false; this.issaveTypeSignature = false; this.issaveImageSignature = false; this.issaveTypeInitial = false; this.issaveImageInitial = false; this.saveSignatureTypeString = ''; this.saveInitialTypeString = ''; this.saveTypeString = ''; this.signatureTypeString = ''; this.initialTypeString = ''; this.saveUploadString = ''; this.saveSignatureUploadString = ''; this.saveInitialUploadString = ''; this.signatureUploadString = ''; this.initialUploadString = ''; this.clearUploadString = false; this.textValue = ''; this.signatureDrawString = ''; this.initialDrawString = ''; this.signatureTextContentTop = 0.2; this.signatureTextContentLeft = 0.7; this.saveSignatureString = ''; this.saveInitialString = ''; /** * @private */ this.saveImageString = ''; this.signatureFieldCollection = []; this.signatureImageString = ''; this.initialImageString = ''; /** * @private */ this.maxSaveLimit = 5; this.select = function (e) { if (this.canvasTouched) { this.mouseMoving = true; this.canvasTouched = false; } if (e.isSwiped && this.signaturetype === 'Draw' && this.mouseMoving) { e.cancel = true; this.mouseMoving = false; } }; this.addStampImage = function (args) { // eslint-disable-next-line var proxy = _this; var upoadedFiles = args.target.files; if (args.target.files[0] !== null) { var uploadedFile = upoadedFiles[0]; if (uploadedFile.type.split('/')[0] === 'image') { var reader = new FileReader(); reader.onload = function (e) { var canvas = document.getElementById(_this.pdfViewer.element.id + '_signatureuploadCanvas_'); var context = canvas.getContext('2d'); var image = new Image(); // eslint-disable-next-line var proxy = _this; image.onload = function () { var signbutton = document.getElementById(_this.pdfViewer.element.id + '_e-pv-upload-button'); signbutton.style.visibility = 'hidden'; context.drawImage(image, 0, 0, canvas.width, canvas.height); proxy.enableCreateButton(false); proxy.outputString = image.src; proxy.signatureImageHeight = image.naturalHeight; proxy.signatureImageWidth = image.naturalWidth; }; image.src = e.currentTarget.result; proxy.outputString = e.currentTarget.result; proxy.switchTabImageSignature = e.currentTarget.result; }; reader.readAsDataURL(uploadedFile); } } args.target.value = ''; args.currentTarget.value = ''; }; this.pdfViewer = pdfViewer; this.pdfViewerBase = pdfViewerBase; } /** * @private * @returns {void} */ Signature.prototype.createSignaturePanel = function () { var _this = this; var maximumWidth = 750; this.imageSignatureDataUrl = ''; this.drawSignatureDataUrl = ''; if (!isBlazor()) { var elementID = this.pdfViewer.element.id; var dialogDiv = createElement('div', { id: elementID + '_signature_window', className: 'e-pv-signature-window' }); dialogDiv.style.display = 'block'; this.pdfViewerBase.pageContainer.appendChild(dialogDiv); var appearanceTab = this.createSignatureCanvas(); var signaturePanelHeader = void 0; if (!this.pdfViewerBase.isToolbarSignClicked) { if (this.pdfViewerBase.isInitialField) { signaturePanelHeader = this.pdfViewer.localeObj.getConstant('HandwrittenInitialDialogHeaderText'); } else { signaturePanelHeader = this.pdfViewer.localeObj.getConstant('HandwrittenSignatureDialogHeaderText'); } } else { if (this.pdfViewerBase.isInitialField) { signaturePanelHeader = this.pdfViewer.localeObj.getConstant('InitialFieldDialogHeaderText'); } else { signaturePanelHeader = this.pdfViewer.localeObj.getConstant('SignatureFieldDialogHeaderText'); } } if (this.signatureDialog) { this.signatureDialog.content = appearanceTab; } else { this.signatureDialog = new Dialog({ showCloseIcon: true, closeOnEscape: false, isModal: true, header: signaturePanelHeader, cssClass: 'e-pv-signature-dialog-height', target: this.pdfViewerBase.mainContainer, content: appearanceTab, width: '750px', visible: true, allowDragging: true, beforeClose: function () { _this.clearSignatureCanvas(); _this.signatureDialog.destroy(); _this.signatureDialog = null; if (_this.tabObj) { _this.tabObj.destroy(); } var signatureWindow = document.getElementById(_this.pdfViewer.element.id + '_signature_window'); if (signatureWindow) { if (signatureWindow.parentNode) { signatureWindow.parentNode.removeChild(signatureWindow); } else { signatureWindow.parentElement.removeChild(signatureWindow); } } if (!_this.pdfViewerBase.isToolbarSignClicked && !_this.pdfViewerBase.drawSignatureWithTool && _this.pdfViewer.formFieldsModule && !isNullOrUndefined(_this.pdfViewer.formFieldsModule.currentTarget)) { _this.pdfViewer.fireFocusOutFormField(_this.pdfViewer.formFieldsModule.currentTarget.name, ''); } _this.pdfViewerBase.isToolbarSignClicked = false; _this.setFocus(); } }); this.signatureDialog.buttons = [ { buttonModel: { content: this.pdfViewer.localeObj.getConstant('Clear'), disabled: true, cssClass: 'e-pv-clearbtn' }, click: this.clearSignatureCanvas.bind(this) }, { buttonModel: { content: this.pdfViewer.localeObj.getConstant('Cancel'), cssClass: 'e-pv-cancelbtn' }, click: this.closeSignaturePanel.bind(this) }, { buttonModel: { content: this.pdfViewer.localeObj.getConstant('Create'), isPrimary: true, disabled: true, cssClass: 'e-pv-createbtn' }, click: this.addSignatureInPage.bind(this) } ]; this.signatureDialog.appendTo(dialogDiv); } if (this.pdfViewer.element.offsetWidth < maximumWidth) { this.updateCanvasSize(); } if (this.pdfViewer.enableRtl) { this.signatureDialog.enableRtl = this.pdfViewer.enableRtl; } var checkboxItem = this.signatureDialog.content.ej2_instances[0].items[0]; if (checkboxItem.header.label === 'DRAW') { var drawCheckbox = document.getElementById('checkbox'); this.hideSignatureCheckbox(drawCheckbox); } else if (checkboxItem.header.label === 'TYPE') { var typeCheckbox = document.getElementById('checkbox1'); this.hideSignatureCheckbox(typeCheckbox); } else { var imageCheckbox = document.getElementById('checkbox2'); this.hideSignatureCheckbox(imageCheckbox); } this.setSignatureCanvasWidth(); } else { var canvas = document.getElementById(this.pdfViewer.element.id + '_signatureCanvas_'); if (canvas) { if (!this.pdfViewerBase.pageContainer.querySelector('.e-pv-signature-window')) { var elementID = this.pdfViewer.element.id; var dialogDiv = createElement('div', { id: elementID + '_signature_window', className: 'e-pv-signature-window' }); dialogDiv.style.display = 'block'; this.pdfViewerBase.pageContainer.appendChild(dialogDiv); } canvas.addEventListener('mousedown', this.signaturePanelMouseDown.bind(this)); canvas.addEventListener('mousemove', this.signaturePanelMouseMove.bind(this)); canvas.addEventListener('mouseup', this.signaturePanelMouseUp.bind(this)); canvas.addEventListener('mouseleave', this.signaturePanelMouseUp.bind(this)); canvas.addEventListener('touchstart', this.signaturePanelMouseDown.bind(this)); canvas.addEventListener('touchmove', this.signaturePanelMouseMove.bind(this)); canvas.addEventListener('touchend', this.signaturePanelMouseUp.bind(this)); this.clearSignatureCanvas(); } this.pdfViewer._dotnetInstance.invokeMethodAsync('OpenSignaturePanel', this.pdfViewerBase.isToolbarSignClicked); } this.drawSavedSignature(); }; Signature.prototype.setSignatureCanvasWidth = function () { var appearanceElement = document.getElementById(this.pdfViewer.element.id + 'Signature_appearance'); if (appearanceElement) { var apperanceTabWidth = appearanceElement.clientWidth; var pathcanvas = document.getElementById(this.pdfViewer.element.id + '_signatureCanvas_'); if (pathcanvas) { pathcanvas.width = apperanceTabWidth; pathcanvas.style.width = apperanceTabWidth + 'px'; } var uploadCanvas = document.getElementById(this.pdfViewer.element.id + '_signatureuploadCanvas_'); if (uploadCanvas) { uploadCanvas.width = apperanceTabWidth; uploadCanvas.style.width = apperanceTabWidth + 'px'; } var textDiv = document.getElementById(this.pdfViewer.element.id + '_font_appearance'); if (textDiv) { textDiv.width = apperanceTabWidth; textDiv.style.width = apperanceTabWidth + 'px'; } } }; Signature.prototype.drawSavedSignature = function () { if (!this.pdfViewerBase.isToolbarSignClicked && (this.isSaveSignature || this.isSaveInitial)) { if (!this.pdfViewerBase.isInitialField && this.isSaveSignature) { this.outputString = this.saveSignatureString; } else if (this.pdfViewerBase.isInitialField && this.isSaveInitial) { this.outputString = this.saveInitialString; } var canvas = document.getElementById(this.pdfViewer.element.id + '_signatureCanvas_'); var context_1 = canvas.getContext('2d'); var image_1 = new Image(); image_1.onload = function () { context_1.drawImage(image_1, 0, 0); }; if (!this.pdfViewerBase.isInitialField && this.isSaveSignature) { image_1.src = this.signatureDrawString; } else if (this.pdfViewerBase.isInitialField && this.isSaveInitial) { image_1.src = this.initialDrawString; } var checkbox = document.getElementById(this.pdfViewer.element.id + '_signatureCheckBox'); if (checkbox) { checkbox.checked = true; } this.enableCreateButton(false); this.enableClearbutton(false); } }; Signature.prototype.drawSavedTypeSignature = function () { var output = ''; if (!this.pdfViewerBase.isToolbarSignClicked && (this.issaveTypeSignature || this.issaveTypeInitial)) { if (!this.pdfViewerBase.isInitialField && this.issaveTypeSignature) { output = this.saveSignatureTypeString; } else { output = this.saveInitialTypeString; } } return output; }; Signature.prototype.drawSavedImageSignature = function () { var output = ''; if (!this.pdfViewerBase.isToolbarSignClicked && (this.issaveImageSignature || this.issaveImageInitial)) { if (!this.pdfViewerBase.isInitialField && this.issaveImageSignature) { output = this.saveSignatureUploadString; } else { output = this.saveInitialUploadString; } } return output; }; Signature.prototype.hideSignatureCheckbox = function (checkbox) { if (this.pdfViewerBase.isToolbarSignClicked) { if (this.pdfViewerBase.isInitialField) { if (this.pdfViewer.handWrittenSignatureSettings.initialDialogSettings && this.pdfViewer.handWrittenSignatureSettings.initialDialogSettings.hideSaveSignature) { this.hideCheckboxParent(checkbox); } } else if (this.pdfViewer.handWrittenSignatureSettings.signatureDialogSettings && this.pdfViewer.handWrittenSignatureSettings.signatureDialogSettings.hideSaveSignature) { this.hideCheckboxParent(checkbox); } } else { if (this.pdfViewerBase.isInitialField) { if (this.pdfViewer.initialFieldSettings.initialDialogSettings && this.pdfViewer.initialFieldSettings.initialDialogSettings.hideSaveSignature) { this.hideCheckboxParent(checkbox); } } else { if (this.pdfViewer.signatureFieldSettings.signatureDialogSettings && this.pdfViewer.signatureFieldSettings.signatureDialogSettings.hideSaveSignature) { this.hideCheckboxParent(checkbox); } } } }; Signature.prototype.saveSignatureCheckbox = function () { if (this.pdfViewerBase.isToolbarSignClicked) { return false; } else { if (this.pdfViewerBase.isInitialField) { if (this.pdfViewer.initialFieldSettings.initialDialogSettings && this.pdfViewer.initialFieldSettings.initialDialogSettings.hideSaveSignature) { return false; } else { return this.isInitialFiledSaveSignature; } } else { if (this.pdfViewer.signatureFieldSettings.signatureDialogSettings && this.pdfViewer.signatureFieldSettings.signatureDialogSettings.hideSaveSignature) { return false; } else { return this.isSignatureFieldsSaveSignature; } } } }; Signature.prototype.hideCheckboxParent = function (checkbox) { if (checkbox) { checkbox.parentElement.style.display = 'none'; } }; Signature.prototype.saveSignatureImage = function () { var checkbox = document.getElementById(this.pdfViewer.element.id + '_signatureCheckBox'); if (checkbox && checkbox.checked) { if (this.outputString !== '') { if (!this.pdfViewerBase.isInitialField) { this.isSaveSignature = true; this.saveSignatureString = this.outputString; } else { this.isSaveInitial = true; this.saveInitialString = this.outputString; } var canvas = document.getElementById(this.pdfViewer.element.id + '_signatureCanvas_'); this.saveImageString = canvas.toDataURL(); if (!this.pdfViewerBase.isInitialField) { this.signatureImageString = this.saveImageString; } else { this.initialImageString = this.saveImageString; } } } else { if (this.isSaveSignature && !this.pdfViewerBase.isInitialField) { this.isSaveSignature = false; this.saveSignatureString = ''; this.saveImageString = ''; this.signatureImageString = ''; } else if (this.isSaveInitial && this.pdfViewerBase.isInitialField) { this.isSaveInitial = false; this.saveInitialString = ''; this.saveImageString = ''; this.initialImageString = ''; } this.clearSignatureCanvas(); } }; /** * @param {any} type - It describes about the type * @private * @returns {void} */ Signature.prototype.addSignature = function (type) { var annot; if (this.pdfViewerBase.isToolbarSignClicked) { var annotationName = this.pdfViewer.annotation.createGUID(); this.pdfViewerBase.currentSignatureAnnot = null; this.pdfViewerBase.isSignatureAdded = true; var pageIndex = this.pdfViewerBase.currentPageNumber - 1; var thickness = this.pdfViewer.handWrittenSignatureSettings.thickness ? this.pdfViewer.handWrittenSignatureSettings.thickness : 1; var opacity = this.pdfViewer.handWrittenSignatureSettings.opacity ? this.pdfViewer.handWrittenSignatureSettings.opacity : 1; var strokeColor = this.pdfViewer.handWrittenSignatureSettings.strokeColor ? this.pdfViewer.handWrittenSignatureSettings.strokeColor : '#000000'; var fontSize = 16; var fontFamily = 'Helvetica'; var signatureBounds = this.updateSignatureAspectRatio(this.outputString, true); var canvas = document.getElementById(this.pdfViewer.element.id + '_signatureCanvas_'); this.saveImageString = canvas.toDataURL(); if (!this.pdfViewerBase.isInitialField) { this.signatureImageString = this.saveImageString; } else { this.initialImageString = this.saveImageString; } annot = { id: 'sign' + this.pdfViewerBase.signatureCount, bounds: signatureBounds, pageIndex: pageIndex, data: this.outputString, fontFamily: fontFamily, fontSize: fontSize, shapeAnnotationType: 'HandWrittenSignature', opacity: opacity, strokeColor: strokeColor, thickness: thickness, signatureName: annotationName }; this.pdfViewerBase.currentSignatureAnnot = annot; var checkbox = void 0; if (isBlazor()) { checkbox = document.getElementById(this.pdfViewer.element.id + '_signatureCheckBox'); } else { checkbox = document.getElementById('checkbox'); } if (checkbox && checkbox.checked) { this.addSignatureCollection(); } this.hideSignaturePanel(); this.pdfViewerBase.isToolbarSignClicked = false; } else { var checkbox = document.getElementById('checkbox'); var typeCheckbox = document.getElementById('checkbox1'); var imageCheckbox = document.getElementById('checkbox2'); var isSignatureAdded = false; if (!isSignatureAdded) { var canvas = document.getElementById(this.pdfViewer.element.id + '_signatureCanvas_'); this.saveImageString = canvas.toDataURL(); if (checkbox) { if (checkbox.checked) { if (!this.pdfViewerBase.isInitialField) { this.isSaveSignature = true; this.signatureDrawString = this.saveImageString; this.saveSignatureString = this.outputString; } else { this.isSaveInitial = true; this.initialDrawString = this.saveImageString; this.saveInitialString = this.outputString; } this.checkSaveFiledSign(this.pdfViewerBase.isInitialField, true); } else { if (!this.pdfViewerBase.isInitialField) { this.isSaveSignature = false; this.saveSignatureString = ''; } else { this.isSaveInitial = false; this.saveInitialString = ''; } this.checkSaveFiledSign(this.pdfViewerBase.isInitialField, false); } } this.saveTypeSignature(typeCheckbox); this.saveUploadSignature(imageCheckbox); if (!this.pdfViewerBase.isInitialField) { this.signatureImageString = this.saveImageString; } else { this.initialImageString = this.saveImageString; } if (this.pdfViewer.formFieldsModule) { this.pdfViewer.formFieldsModule.drawSignature(null, null, this.pdfViewerBase.currentTarget, null); } isSignatureAdded = true; } } }; /** * @param {any} data - It describes about the data * @param {boolean} isSignature - It describes about the whether the isSignature is true or not * @param {any} currentField - It describes about the current field * @param {any} currentData - It describes about the current data * @private * @returns {any} - any */ Signature.prototype.updateSignatureAspectRatio = function (data, isSignature, currentField, currentData) { var collectionData = processPathData(data); var csData = splitArrayCollection(collectionData); var minimumX = -1; var minimumY = -1; var maximumX = -1; var maximumY = -1; var signatureCanvas = document.getElementById(this.pdfViewer.element.id + '_signatureCanvas_'); var signatureCavasWidth = 0; var signatureCavasHeight = 0; for (var m = 0; m < csData.length; m++) { var val = csData[parseInt(m.toString(), 10)]; if (minimumX === -1) { minimumX = parseFloat(val['x'].toString()); maximumX = parseFloat(val['x'].toString()); minimumY = parseFloat(val['y'].toString()); maximumY = parseFloat(val['y'].toString()); } else { var point1 = parseFloat(val['x'].toString()); var point2 = parseFloat(val['y'].toString()); if (minimumX >= point1) { minimumX = point1; } if (minimumY >= point2) { minimumY = point2; } if (maximumX <= point1) { maximumX = point1; } if (maximumY <= point2) { maximumY = point2; } } } signatureCavasWidth = signatureCanvas ? signatureCanvas.clientWidth : 650; signatureCavasHeight = signatureCanvas ? signatureCanvas.clientHeight : 300; var newdifferenceX = maximumX - minimumX; var newdifferenceY = maximumY - minimumY; var signBounds = this.calculateSignatureBounds(signatureCavasWidth, signatureCavasHeight, newdifferenceX, newdifferenceY, isSignature, currentField, currentData); if (isSignature) { var zoomvalue = this.pdfViewerBase.getZoomFactor(); var pageIndex = this.pdfViewerBase.currentPageNumber - 1; var pageDiv = document.getElementById(this.pdfViewer.element.id + '_pageDiv_' + pageIndex); var currentLeft = ((parseFloat(pageDiv.style.width) / 2) - (signBounds.currentWidth / 2)) / zoomvalue; var currentTop = ((parseFloat(pageDiv.style.height) / 2) - (signBounds.currentHeight / 2)) / zoomvalue; return { x: currentLeft, y: currentTop, width: signBounds.currentWidth, height: signBounds.currentHeight }; } else { return { left: signBounds.currentLeftDiff, top: signBounds.currentTopDiff, width: signBounds.currentWidth, height: signBounds.currentHeight }; } }; Signature.prototype.calculateSignatureBounds = function (signatureCavasWidth, signatureCavasHeight, newdifferenceX, newdifferenceY, isSignature, currentField, currentData) { var ratioX = newdifferenceX / signatureCavasWidth; var ratioY = newdifferenceY / signatureCavasHeight; var zoomvalue = this.pdfViewerBase.getZoomFactor(); var currentWidth = 0; var currentHeight = 0; var isSignatureStretched = false; var isHeightStretched = false; var leftDifference = 0; var topDifference = 0; if (isSignature) { currentWidth = this.pdfViewer.handWrittenSignatureSettings.width ? this.pdfViewer.handWrittenSignatureSettings.width : 150; currentHeight = this.pdfViewer.handWrittenSignatureSettings.height ? this.pdfViewer.handWrittenSignatureSettings.height : 100; } else { var fieldWidth = currentField ? currentField.style.width === '100%' ? currentField.clientWidth : parseFloat(currentField.style.width) : this.ConvertPointToPixel(currentData.LineBounds.Width); var fieldHeight = currentField ? currentField.style.height === '100%' ? currentField.clientHeight : parseFloat(currentField.style.height) : this.ConvertPointToPixel(currentData.LineBounds.Height); var fieldWidthRatio = fieldWidth / fieldHeight; var fieldHeightRatio = fieldHeight / fieldWidth; var canvasWidthRatio = signatureCavasWidth / signatureCavasHeight; var canvasHeightRatio = signatureCavasHeight / signatureCavasWidth; var fieldRotation = currentField ? currentField.offsetParent.offsetParent.style.transform ? currentField.offsetParent.offsetParent.style.transform : currentField.style.transform : currentData.RotationAngle; if ((fieldWidthRatio > canvasWidthRatio) || (fieldHeightRatio > canvasWidthRatio) || ((Math.abs(fieldWidthRatio - fieldHeightRatio)) <= 1)) { var ratioDifference = 0; if ((fieldHeightRatio > canvasWidthRatio) || ((Math.abs(fieldWidthRatio - fieldHeightRatio)) <= 1)) { isHeightStretched = true; ratioDifference = fieldHeightRatio / canvasHeightRatio; } else { isSignatureStretched = true; ratioDifference = fieldWidthRatio / canvasWidthRatio; } if (fieldRotation === 'rotate(90deg)' || fieldRotation === 'rotate(270deg)') { currentWidth = fieldHeight / zoomvalue; currentHeight = fieldWidth / zoomvalue; } else { if (isSignatureStretched) { leftDifference = fieldWidth / zoomvalue; currentWidth = (fieldWidth / ratioDifference) / zoomvalue; currentHeight = fieldHeight / zoomvalue; } if (isHeightStretched) { topDifference = fieldHeight / zoomvalue; currentWidth = fieldWidth / zoomvalue; currentHeight = (fieldHeight / ratioDifference) / zoomvalue; } } } else { if (fieldRotation === 'rotate(90deg)' || fieldRotation === 'rotate(270deg)') { currentWidth = fieldHeight / zoomvalue; currentHeight = fieldWidth / zoomvalue; } else { currentWidth = fieldWidth / zoomvalue; currentHeight = fieldHeight / zoomvalue; } } } var currentLeftDiff = (signatureCavasWidth - newdifferenceX) / 2; var currentTopDiff = (signatureCavasHeight - newdifferenceY) / 2; if (isSignatureStretched) { currentLeftDiff = (currentLeftDiff / signatureCavasWidth) * leftDifference; var leftValueDiff = ((leftDifference * ratioX) - (currentWidth * ratioX)) / 2; currentLeftDiff = currentLeftDiff + leftValueDiff; currentTopDiff = (currentTopDiff / signatureCavasHeight) * currentHeight; } else if (isHeightStretched) { currentLeftDiff = (currentLeftDiff / signatureCavasWidth) * currentWidth; currentTopDiff = (currentTopDiff / signatureCavasHeight) * topDifference; var topValueDiff = ((topDifference * ratioY) - (currentHeight * ratioY)) / 2; currentTopDiff = currentTopDiff + topValueDiff; } else { currentLeftDiff = (currentLeftDiff / signatureCavasWidth) * currentWidth; currentTopDiff = (currentTopDiff / signatureCavasHeight) * currentHeight; } if (this.pdfViewer.signatureFitMode !== 'Stretch') { currentWidth = currentWidth * ratioX; currentHeight = currentHeight * ratioY; } return { currentLeftDiff: currentLeftDiff, currentTopDiff: currentTopDiff, currentWidth: currentWidth, currentHeight: currentHeight }; }; /** * @param {string} id - It describes about the id value * @private * @returns {void} */ Signature.prototype.setFocus = function (id) { if (!id) { if (this.currentTarget) { document.getElementById(this.currentTarget.id).focus(); } } else { this.removeFocus(); var signatureElement = document.getElementById(id); signatureElement.classList.add('e-pv-signature-focus'); } }; /** * @private * @returns {void} */ Signature.prototype.removeFocus = function () { if (this.signatureFieldCollection) { var signatureFields = this.signatureFieldCollection; if (signatureFields.length === 0) { signatureFields = this.getSignField(); } for (var i = 0; i < this.signatureFieldCollection.length; i++) { var signatureFieldId = this.pdfViewer.formDesignerModule ? this.signatureFieldCollection[parseInt(i.toString(), 10)].FormField.uniqueID : this.signatureFieldCollection[parseInt(i.toString(), 10)].uniqueID; var signatureElement = document.getElementById(signatureFieldId); if (signatureElement) { signatureElement.classList.remove('e-pv-signature-focus'); } } if (this.pdfViewer.formFieldsModule.currentTarget) { this.pdfViewer.formFieldsModule.currentTarget.classList.remove('e-pv-signature-focus'); } } }; Signature.prototype.getSignField = function () { if (this.pdfViewer.formDesignerModule) { this.signatureFieldCollection = this.pdfViewer.formDesignerModule.getFormDesignerSignField(this.signatureFieldCollection); } else { this.signatureFieldCollection = this.getFormFieldSignField(); } return this.signatureFieldCollection; }; Signature.prototype.getFormFieldSignField = function () { var data = this.pdfViewerBase.getItemFromSessionStorage('_formfields'); var currentData; if (data) { var formFieldsData = JSON.parse(data); for (var i = 0; i < formFieldsData.length; i++) { currentData = formFieldsData[parseInt(i.toString(), 10)]; if (currentData.Name === 'SignatureField' || currentData.Name === 'InitialField') { currentData['uniqueID'] = this.pdfViewer.element.id + 'input_' + currentData.PageIndex + '_' + i; this.signatureFieldCollection.push(formFieldsData[parseInt(i.toString(), 10)]); } } } return this.signatureFieldCollection; }; Signature.prototype.checkSaveFiledSign = function (initialField, saveSign) { if (initialField) { this.isInitialFiledSaveSignature = saveSign; } else { this.isSignatureFieldsSaveSignature = saveSign; } }; Signature.prototype.addSignatureInPage = function () { if (this.signaturetype === 'Draw') { this.addSignature(); } else if (this.signaturetype === 'Type') { this.typeAddSignature(); } else { this.imageAddSignature(); } this.drawOutputString = ''; this.imageOutputString = ''; }; Signature.prototype.typeAddSignature = function (type) { if (this.pdfViewerBase.isToolbarSignClicked) { var zoomvalue = this.pdfViewerBase.getZoomFactor(); var annot = null; var annotationName = this.pdfViewer.annotation.createGUID(); this.pdfViewerBase.currentSignatureAnnot = null; this.pdfViewerBase.isSignatureAdded = true; var pageIndex = this.pdfViewerBase.currentPageNumber - 1; var pageDiv = document.getElementById(this.pdfViewer.element.id + '_pageDiv_' + pageIndex); var thickness = this.pdfViewer.handWrittenSignatureSettings.thickness ? this.pdfViewer.handWrittenSignatureSettings.thickness : 1; var opacity = this.pdfViewer.handWrittenSignatureSettings.opacity ? this.pdfViewer.handWrittenSignatureSettings.opacity : 1; var strokeColor = this.pdfViewer.handWrittenSignatureSettings.strokeColor ? this.pdfViewer.handWrittenSignatureSettings.strokeColor : '#000000'; var fontSize = 16; var currentLeft = 0; var currentTop = 0; var currentHeight = 65; var currentWidth = 200; if (!isNullOrUndefined(this.pdfViewer.handWrittenSignatureSettings.height) && (this.pdfViewer.signatureFitMode === 'Stretch')) { currentHeight = this.pdfViewer.handWrittenSignatureSettings.height; } if (!isNullOrUndefined(this.pdfViewer.handWrittenSignatureSettings.width) && (this.pdfViewer.signatureFitMode === 'Stretch')) { currentWidth = this.pdfViewer.handWrittenSignatureSettings.width; } currentLeft = ((parseFloat(pageDiv.style.width) / 2) - (currentWidth / 2)) / zoomvalue; currentTop = ((parseFloat(pageDiv.style.height) / 2) - (currentHeight / 2)) / zoomvalue; var zoomFactor = this.pdfViewerBase.getZoomFactor(); if (!this.signtypevalue) { this.updateSignatureTypeValue(true); } var inputValue = this.signtypevalue; if (this.pdfViewer.enableHtmlSanitizer && this.outputString) { this.outputString = SanitizeHtmlHelper.sanitize(this.outputString); } annot = { id: 'Typesign' + this.pdfViewerBase.signatureCount, bounds: { left: currentLeft / zoomFactor, top: currentTop / zoomFactor, x: currentLeft / zoomFactor, y: currentTop / zoomFactor, width: currentWidth, height: currentHeight }, pageIndex: pageIndex, dynamicText: inputValue, data: this.pdfViewerBase.signatureModule.outputString, shapeAnnotationType: 'SignatureText', opacity: opacity, strokeColor: strokeColor, thickness: thickness, fontSize: fontSize, fontFamily: this.fontName, signatureName: annotationName }; this.pdfViewerBase.currentSignatureAnnot = annot; var checkbox = void 0; if (isBlazor()) { checkbox = document.getElementById(this.pdfViewer.element.id + '_signatureCheckBox'); } else { checkbox = document.getElementById('checkbox1'); } if (checkbox && checkbox.checked) { this.addSignatureCollection(); } this.signtypevalue = ''; this.hideSignaturePanel(); this.pdfViewerBase.isToolbarSignClicked = false; } else { var checkbox = document.getElementById('checkbox'); var typeCheckbox = document.getElementById('checkbox1'); var imageCheckbox = document.getElementById('checkbox2'); var isSignatureAdded = false; if (!isSignatureAdded) { this.saveDrawSignature(checkbox); this.saveUploadSignature(imageCheckbox); var canvas = document.getElementById(this.pdfViewer.element.id + '_signatureCanvas_'); if (canvas) { this.saveTypeString = canvas.toDataURL(); } this.updateSignatureTypeValue(); if (this.pdfViewer.enableHtmlSanitizer && this.textValue) { this.textValue = SanitizeHtmlHelper.sanitize(this.textValue); } if (typeCheckbox && typeCheckbox.checked) { if (!this.pdfViewerBase.isInitialField) { this.isSaveSignature = true; this.signatureImageString = this.saveTypeString; this.saveSignatureTypeString = this.textValue; this.issaveTypeSignature = true; } else { this.isSaveInitial = true; this.initialImageString = this.saveTypeString; this.saveInitialTypeString = this.textValue; this.issaveTypeInitial = true; } } else { if (!this.pdfViewerBase.isInitialField) { this.isSaveSignature = false; this.saveSignatureTypeString = ''; this.issaveTypeSignature = false; } else { this.isSaveInitial = false; this.saveInitialTypeString = ''; this.issaveTypeInitial = false; } } if (!this.pdfViewerBase.isInitialField) { this.signatureTypeString = this.saveTypeString; } else { this.initialTypeString = this.saveTypeString; } if (this.pdfViewer.formFieldsModule) { this.pdfViewer.formFieldsModule.drawSignature('Type', this.textValue, this.pdfViewerBase.currentTarget); } isSignatureAdded = true; this.hideSignaturePanel(); } } }; Signature.prototype.imageAddSignature = function (type) { if (this.pdfViewerBase.isToolbarSignClicked) { var zoomvalue = this.pdfViewerBase.getZoomFactor(); var annot = null; var annotationName = this.pdfViewer.annotation.createGUID(); this.pdfViewerBase.currentSignatureAnnot = null; this.pdfViewerBase.isSignatureAdded = true; var pageIndex = this.pdfViewerBase.currentPageNumber - 1; var pageDiv = document.getElementById(this.pdfViewer.element.id + '_pageDiv_' + pageIndex); var thickness = this.pdfViewer.handWrittenSignatureSettings.thickness ? this.pdfViewer.handWrittenSignatureSettings.thickness : 1; var opacity = this.pdfViewer.handWrittenSignatureSettings.opacity ? this.pdfViewer.handWrittenSignatureSettings.opacity : 1; var strokeColor = this.pdfViewer.handWrittenSignatureSettings.strokeColor ? this.pdfViewer.handWrittenSignatureSettings.strokeColor : '#000000'; var fontSize = 16; var currentLeft = 0; var currentTop = 0; var standardImageRatio = 100; var currentHeight = 0; var currentWidth = 0; if (this.pdfViewer.enableHtmlSanitizer && this.outputString) { this.outputString = SanitizeHtmlHelper.sanitize(this.outputString); } if (!isNullOrUndefined(this.pdfViewer.handWrittenSignatureSettings.height) && (this.pdfViewer.signatureFitMode === 'Stretch')) { currentHeight = this.pdfViewer.handWrittenSignatureSettings.height; } else if (this.signatureImageHeight >= this.signatureImageWidth) { currentHeight = ((this.signatureImageHeight / this.signatureImageHeight) * standardImageRatio); } else { currentHeight = ((this.signatureImageHeight / this.signatureImageWidth) * standardImageRatio); } if (!isNullOrUndefined(this.pdfViewer.handWrittenSignatureSettings.width) && (this.pdfViewer.signatureFitMode === 'Stretch')) { currentWidth = this.pdfViewer.handWrittenSignatureSettings.width; } else if (this.signatureImageHeight >= this.signatureImageWidth) { currentWidth = ((this.signatureImageWidth / this.signatureImageHeight) * standardImageRatio); } else { currentWidth = ((this.signatureImageWidth / this.signatureImageWidth) * standardImageRatio); } currentLeft = ((parseFloat(pageDiv.style.width) / 2) - (currentWidth / 2)) / zoomvalue; currentTop = ((parseFloat(pageDiv.style.height) / 2) - (currentHeight / 2)) / zoomvalue; var zoomFactor = this.pdfViewerBase.getZoomFactor(); var inputValue = this.signtypevalue; annot = { id: 'Typesign' + this.pdfViewerBase.signatureCount, bounds: { left: currentLeft / zoomFactor, top: currentTop / zoomFactor, x: currentLeft / zoomFactor, y: currentTop / zoomFactor, width: currentWidth, height: currentHeight }, pageIndex: pageIndex, dynamicText: inputValue, data: this.pdfViewerBase.signatureModule.outputString, shapeAnnotationType: 'SignatureImage', opacity: opacity, strokeColor: strokeColor, thickness: thickness, fontSize: fontSize, fontFamily: this.fontName, signatureName: annotationName }; this.pdfViewerBase.currentSignatureAnnot = annot; var checkbox = void 0; if (isBlazor()) { checkbox = document.getElementById(this.pdfViewer.element.id + '_signatureCheckBox'); } else { checkbox = document.getElementById('checkbox2'); } if (checkbox && checkbox.checked) { this.addSignatureCollection(); } this.hideSignaturePanel(); this.pdfViewerBase.isToolbarSignClicked = false; } else { var checkbox = document.getElementById('checkbox'); var typeCheckbox = document.getElementById('checkbox1'); var imageCheckbox = document.getElementById('checkbox2'); var isSignatureAdded = false; if (!isSignatureAdded) { this.saveDrawSignature(checkbox); this.saveTypeSignature(typeCheckbox); var canvas = document.getElementById(this.pdfViewer.element.id + '_signatureCanvas_'); if (canvas) { this.saveUploadString = canvas.toDataURL(); } if (this.pdfViewer.enableHtmlSanitizer && this.outputString) { this.outputString = SanitizeHtmlHelper.sanitize(this.outputString); } if (imageCheckbox && imageCheckbox.checked) { if (!this.pdfViewerBase.isInitialField) { this.isSaveSignature = true; this.signatureImageString = this.saveUploadString; this.saveSignatureUploadString = this.outputString; this.issaveImageSignature = true; } else { this.isSaveInitial = true; this.initialImageString = this.saveUploadString; this.saveInitialUploadString = this.outputString; this.issaveImageInitial = true; } } else { if (!this.pdfViewerBase.isInitialField) { this.isSaveSignature = false; this.saveSignatureUploadString = ''; this.issaveImageSignature = false; } else { this.isSaveInitial = false; this.saveInitialUploadString = ''; this.issaveImageInitial = false; } } if (!this.pdfViewerBase.isInitialField) { this.signatureUploadString = this.saveUploadString; } else { this.initialUploadString = this.saveUploadString; } if (this.pdfViewer.formFieldsModule) { this.pdfViewer.formFieldsModule.drawSignature('Image', '', this.pdfViewerBase.currentTarget); } isSignatureAdded = true; this.hideSignaturePanel(); } } }; Signature.prototype.saveDrawSignature = function (checkbox) { if (checkbox) { if (checkbox.checked) { if (this.drawOutputString !== '') { var canvas = document.getElementById(this.pdfViewer.element.id + '_signatureCanvas_'); this.saveImageString = canvas.toDataURL(); if (!this.pdfViewerBase.isInitialField) { this.saveSignatureString = this.drawOutputString; this.signatureDrawString = this.saveImageString; } else { this.saveInitialString = this.drawOutputString; this.initialDrawString = this.saveImageString; } this.checkSaveFiledSign(this.pdfViewerBase.isInitialField, true); } } else { if (!this.pdfViewerBase.isInitialField) { this.saveSignatureStrin