UNPKG

@syncfusion/ej2-pdfviewer

Version:
888 lines 158 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import { PdfViewerBase } from '../index'; import { Browser, isBlazor, isNullOrUndefined, initializeCSPTemplate } from '@syncfusion/ej2-base'; import { splitArrayCollection, processPathData, cornersPointsBeforeRotation, getPathString } from '@syncfusion/ej2-drawings'; import { Tooltip } from '@syncfusion/ej2-popups'; /** * The `FormFields` module is to render formfields in the PDF document. * * @hidden */ var FormFields = /** @class */ (function () { /** * @param {PdfViewer} viewer - It describes about the viewer * @param {PdfViewerBase} base - It describes about the base * @private * @returns {void} */ function FormFields(viewer, base) { this.maintainTabIndex = {}; this.maintanMinTabindex = {}; this.isSignatureField = false; /** * @private */ this.paddingDifferenceValue = 10; this.indicatorPaddingValue = 4; this.isKeyDownCheck = false; /** * @private */ this.signatureFontSizeConstent = 1.35; /** * @private */ this.readOnlyCollection = []; this.isSignatureRendered = false; /** * @private */ this.signatureFieldCollection = []; this.selectedIndex = []; /** * @private */ this.renderedPageList = []; this.pdfViewer = viewer; this.pdfViewerBase = base; } /** * @param {number} pageIndex - It describes about the page index * @param {boolean} isImportFormField - It describes about the isImportFormField * @private * @returns {void} */ FormFields.prototype.renderFormFields = function (pageIndex, isImportFormField) { this.maxTabIndex = 0; this.minTabIndex = -1; if (this.renderedPageList.indexOf(pageIndex) !== -1 && !isImportFormField) { this.data = this.pdfViewerBase.getItemFromSessionStorage('_formDesigner'); if (!this.data || this.data === '[]') { this.data = this.pdfViewerBase.getItemFromSessionStorage('_formfields'); } } else { this.data = this.pdfViewerBase.getItemFromSessionStorage('_formfields'); } if (this.data) { this.formFieldsData = JSON.parse(this.data); if (this.formFieldsData[0] === '[') { this.formFieldsData = JSON.parse(this.formFieldsData); } var textLayer = document.getElementById(this.pdfViewer.element.id + '_textLayer_' + pageIndex); var canvasElement = document.getElementById(this.pdfViewer.element.id + '_pageCanvas_' + pageIndex); var count = void 0; if (this.formFieldsData !== null && canvasElement !== null && textLayer !== null) { var flag = false; for (var i = 0; i < this.formFieldsData.length; i++) { var formField = this.formFieldsData[parseInt(i.toString(), 10)]; if (!flag && isNullOrUndefined(formField.ActualFieldName) && formField.PageIndex === pageIndex) { count = parseInt(formField.FieldName.slice(formField.FieldName.lastIndexOf('_') + 1), 10); flag = true; } } if (this.renderedPageList.indexOf(pageIndex) === -1) { this.renderedPageList.push(pageIndex); } var _loop_1 = function (i) { var currentData = this_1.formFieldsData[parseInt(i.toString(), 10)]; if (currentData.FieldName !== '') { if (currentData.IsInitialField) { currentData.Name = 'InitialField'; } var font = currentData['Font']; if (this_1.pdfViewer.formDesigner) { if (parseFloat(currentData['PageIndex']) === pageIndex) { var fontFamily = void 0; var fontStyle = void 0; var fontSize = void 0; if (!isNullOrUndefined(font) && font.Height) { fontFamily = font.Name; if (font.Italic) { fontStyle = 'Italic'; } if (font.Bold) { fontStyle = 'Bold'; } if (font.Strikeout) { fontStyle = 'Strikethrough'; } if (font.Underline) { fontStyle = 'Underline'; } fontSize = this_1.ConvertPointToPixel(font.Size); } var textAlignment = currentData.Alignment === 2 ? 'right' : (currentData.Alignment === 1 ? 'center' : 'left'); var backgroundColor = currentData['BackColor']; var bounds = currentData['LineBounds']; var backColor = 'rgba(' + backgroundColor.R + ',' + backgroundColor.G + ',' + backgroundColor.B + ',' + 1 + ')'; if (currentData.IsTransparent === true) { backColor = 'rgba(0,0,0,0)'; } backColor = this_1.rgbaToHex(backColor); // set default color if field have black color as bg. if (backColor === '#000000ff') { backColor = '#daeaf7ff'; } var fontColor = currentData['FontColor']; var left = this_1.ConvertPointToPixel(bounds.X); var top_1 = this_1.ConvertPointToPixel(bounds.Y); var width = this_1.ConvertPointToPixel(bounds.Width); var height = this_1.ConvertPointToPixel(bounds.Height); var boundArray = { left: left, top: top_1, width: width, height: height }; var isFieldRotated = false; var rotateFieldAngle = 0; if (currentData['Rotation'] !== 0) { if (currentData['RotationAngle'] === -90 || currentData['RotationAngle'] === -270 || currentData['RotationAngle'] === -180) { boundArray = this_1.getBounds(boundArray, pageIndex, 0, isFieldRotated); } } else { isFieldRotated = true; boundArray = this_1.getBounds(boundArray, pageIndex, 0, isFieldRotated); rotateFieldAngle = this_1.getAngle(pageIndex); } var foreColor = 'rgba(' + fontColor.R + ',' + fontColor.G + ',' + fontColor.B + ',' + 1 + ')'; foreColor = this_1.rgbaToHex(foreColor); var borderColor = currentData['BorderColor']; var borderRGB = void 0; if (currentData.IsTansparentBorderColor) { borderRGB = 'rgba(' + borderColor.R + ',' + borderColor.G + ',' + borderColor.B + ',' + 0 + ')'; } else { borderRGB = 'rgba(' + borderColor.R + ',' + borderColor.G + ',' + borderColor.B + ',' + 1 + ')'; } borderRGB = this_1.rgbaToHex(borderRGB); var borderWidth = currentData['BorderWidth']; this_1.selectedIndex = []; var elementValue = ''; if (currentData.Name === 'RadioButton' || currentData.Name === 'CheckBox') { elementValue = currentData['Text'] ? currentData['Text'] : currentData['Value']; } else { elementValue = currentData['Text']; } var indicatorSettings = (currentData['Name'] === 'SignatureField') ? this_1.pdfViewer.signatureFieldSettings.signatureIndicatorSettings : this_1.pdfViewer.initialFieldSettings.initialIndicatorSettings; var fieldProperties = { bounds: { X: boundArray.left, Y: boundArray.top, Width: boundArray.width, Height: boundArray.height }, pageNumber: parseFloat(currentData['PageIndex']) + 1, name: currentData['ActualFieldName'] ? currentData['ActualFieldName'] : currentData['FieldName'], tooltip: currentData['ToolTip'], value: elementValue, insertSpaces: currentData['InsertSpaces'], isChecked: currentData['Selected'], isSelected: currentData['Selected'], fontFamily: fontFamily, fontStyle: fontStyle, backgroundColor: backColor, color: foreColor, borderColor: borderRGB, thickness: borderWidth, fontSize: fontSize, isMultiline: currentData.Multiline, rotateAngle: rotateFieldAngle, isReadOnly: currentData['IsReadonly'], isRequired: currentData['IsRequired'], alignment: textAlignment, options: this_1.getListValues(currentData), selectedIndex: this_1.selectedIndex, maxLength: currentData.MaxLength, visibility: currentData.Visible === 1 ? 'hidden' : 'visible', font: { isItalic: !isNullOrUndefined(font) ? font.Italic : false, isBold: !isNullOrUndefined(font) ? font.Bold : false, isStrikeout: !isNullOrUndefined(font) ? font.Strikeout : false, isUnderline: !isNullOrUndefined(font) ? font.Underline : false }, isTransparent: currentData.IsTransparent, customData: !isNullOrUndefined(currentData['CustomData']) ? typeof currentData['CustomData'] === 'object' ? currentData['CustomData'] : currentData['CustomData'].trim() !== '' ? JSON.parse(currentData['CustomData']) : '' : '', signatureIndicatorSettings: indicatorSettings }; if (!currentData.id && this_1.pdfViewer.formFieldCollections[parseInt(i.toString(), 10)] && !isNullOrUndefined(currentData['ActualFieldName'])) { fieldProperties.id = this_1.pdfViewer.formFieldCollections[parseInt(i.toString(), 10)].id; } if (currentData.Name === 'DropDown' || currentData.Name === 'ListBox') { fieldProperties.value = currentData['SelectedValue']; } var fieldType = this_1.getFormFieldType(currentData); if (currentData.Name !== 'SignatureText' || currentData.Name !== 'SignatureImage') { if (!isNullOrUndefined(this_1.getFormFieldType(currentData))) { if (currentData.IsRequired) { var thickness = fieldProperties.thickness; thickness = thickness > 0 ? thickness : 1; fieldProperties.thickness = thickness; } var addedElement1 = this_1.pdfViewer.formDesignerModule. addField(fieldType, fieldProperties, false, fieldProperties.id); if (addedElement1 && addedElement1.parentElement) { currentData.id = addedElement1.parentElement.id.split('_')[0]; } if (addedElement1 && addedElement1.style.visibility === 'hidden') { addedElement1.childNodes[0].disabled = true; } } } if (fieldType === 'SignatureField' || fieldType === 'InitialField') { this_1.addSignaturePath(currentData, count); if (!isNullOrUndefined(currentData.Value) && currentData.Value !== '') { this_1.renderExistingAnnnot(currentData, parseFloat(currentData['PageIndex']) + 1, null, isFieldRotated); this_1.isSignatureRendered = true; count++; } } if (currentData.ActualFieldName == null && !isNullOrUndefined(currentData.FieldName) && this_1.formFieldsData.filter(function (item) { return !isNullOrUndefined(item.FieldName) && item.FieldName.includes(currentData.FieldName.replace(/_\d$/, '')); }).filter(function (value) { return value.Name !== 'ink'; }).length === 0) { this_1.renderExistingAnnnot(currentData, parseFloat(currentData['PageIndex']) + 1, null, isFieldRotated); this_1.pdfViewerBase.signatureModule.storeSignatureData(pageIndex, currentData); this_1.isSignatureRendered = true; count++; } this_1.pdfViewerBase.isLoadedFormFieldAdded = true; } } else { if (parseFloat(currentData['PageIndex']) === pageIndex) { var field = this_1.createFormFields(currentData, pageIndex, i, null, count); var inputField = field.currentField; var signCount = field.count; var isFieldRotated = false; if (currentData.ActualFieldName === null && !isNullOrUndefined(currentData.FieldName) && this_1.formFieldsData.filter(function (item) { return !isNullOrUndefined(item.FieldName) && item.FieldName.includes(currentData.FieldName.replace(/_\d$/, '')); }).filter(function (value) { return value.Name !== 'ink'; }).length === 0) { this_1.renderExistingAnnnot(currentData, parseFloat(currentData['PageIndex']) + 1, null, isFieldRotated); this_1.pdfViewerBase.signatureModule.storeSignatureData(pageIndex, currentData); this_1.isSignatureRendered = true; count++; } if (inputField) { var divElement = this_1.createParentElement(currentData, pageIndex); var bounds = currentData['LineBounds']; var font_1 = currentData['Font']; var rotateAngle = 0; if (currentData['Rotation'] === 0) { isFieldRotated = true; rotateAngle = this_1.getAngle(pageIndex); if (divElement) { divElement.style.transform = 'rotate(' + rotateAngle + 'deg)'; } else { inputField.style.transform = 'rotate(' + rotateAngle + 'deg)'; } } else { if (divElement) { divElement.style.transform = 'rotate(' + rotateAngle + 'deg)'; } else { inputField.style.transform = 'rotate(' + rotateAngle + 'deg)'; } } this_1.applyPosition(inputField, bounds, font_1, pageIndex, 0, isFieldRotated); inputField.InsertSpaces = currentData.InsertSpaces; if (inputField.InsertSpaces) { var zoomFactor = this_1.pdfViewerBase.getZoomFactor(); var font_2 = ((parseInt(inputField.style.width, 10) / inputField.maxLength) - (parseFloat(inputField.style.fontSize) / 2)) - (0.6 * zoomFactor); inputField.style.letterSpacing = '' + font_2 + 'px'; inputField.style.fontFamily = 'monospace'; inputField.style.paddingLeft = (font_2 / 2) + 'px'; } currentData['uniqueID'] = this_1.pdfViewer.element.id + 'input_' + pageIndex + '_' + i; for (var j = 0; j < this_1.pdfViewer.formFieldCollections.length; j++) { if ((inputField.type === 'text' || inputField.type === 'password' || inputField.type === 'textarea') && currentData.Name !== 'SignatureField') { if (currentData['uniqueID'] === this_1.pdfViewer.formFieldCollections[parseInt(j.toString(), 10)].id) { this_1.pdfViewer.formFieldCollections[parseInt(j.toString(), 10)].value = currentData['Text']; } } } if (isNullOrUndefined(currentData.Value)) { currentData.Value = currentData['Text']; } if (currentData.ToolTip) { this_1.setToolTip(currentData.ToolTip, inputField); } this_1.applyCommonProperties(inputField, pageIndex, i, currentData, isFieldRotated); this_1.checkIsReadonly(currentData, inputField); this_1.applyTabIndex(currentData, inputField, pageIndex); this_1.checkIsRequiredField(currentData, inputField); this_1.applyDefaultColor(inputField); this_1.updateFormFieldsCollection(currentData); if (divElement) { divElement.appendChild(inputField); textLayer.appendChild(divElement); } else { inputField.style.position = 'absolute'; textLayer.appendChild(inputField); } inputField.addEventListener('focus', this_1.focusFormFields.bind(this_1)); inputField.addEventListener('blur', this_1.blurFormFields.bind(this_1)); inputField.addEventListener('click', this_1.updateFormFields.bind(this_1)); inputField.addEventListener('change', this_1.changeFormFields.bind(this_1)); inputField.addEventListener('keydown', this_1.updateFormFieldsValue.bind(this_1)); inputField.addEventListener('keyup', this_1.updateSameFieldsValue.bind(this_1)); count = signCount; } } } } }; var this_1 = this; for (var i = 0; i < this.formFieldsData.length; i++) { _loop_1(i); } if (!this.pdfViewer.formDesigner) { PdfViewerBase.sessionStorageManager.removeItem(this.pdfViewerBase.documentId + '_formfields'); this.pdfViewerBase.setItemInSessionStorage(this.formFieldsData, '_formfields'); } } } if (this.pdfViewerBase.isFocusField && this.pdfViewerBase.focusField) { var currentField = document.getElementById(this.pdfViewerBase.focusField.id); if (currentField) { if ((this.pdfViewerBase.focusField.type === 'SignatureField' || this.pdfViewerBase.focusField.type === 'InitialField') && this.pdfViewer.formDesignerModule) { var y = this.pdfViewerBase.focusField.bounds.y; var height = this.pdfViewerBase.pageSize[parseInt(pageIndex.toString(), 10)].height; this.pdfViewer.bookmark.goToBookmark(this.pdfViewerBase.focusField.pageIndex, height - y); } else { currentField.focus(); } this.pdfViewerBase.isFocusField = false; this.pdfViewerBase.focusField = []; } } }; FormFields.prototype.setToolTip = function (tooltipContent, targetElement) { //initialize tooltip component var tooltip = new Tooltip({ content: initializeCSPTemplate(function () { return tooltipContent; }) }); // render initialized tooltip tooltip.appendTo(targetElement); }; FormFields.prototype.trim = function (str) { return str.replace(/^\s+|\s+$/gm, ''); }; FormFields.prototype.rgbaToHex = function (rgba) { var inParts = rgba.substring(rgba.indexOf('(')).split(','); var r = parseInt(this.trim(inParts[0].substring(1)), 10); var g = parseInt(this.trim(inParts[1]), 10); var b = parseInt(this.trim(inParts[2]), 10); var a = parseFloat(parseFloat(this.trim(inParts[3].substring(0, inParts[3].length - 1))).toFixed(2)); var outParts = [ r.toString(16), g.toString(16), b.toString(16), Math.round(a * 255).toString(16).substring(0, 2) ]; // Pad single-digit output values outParts.forEach(function (part, i) { if (part.length === 1) { outParts[parseInt(i.toString(), 10)] = '0' + part; } }); return ('#' + outParts.join('')); }; FormFields.prototype.getListValues = function (currentData) { var listItem = currentData['TextList']; var options = []; if (this.getFormFieldType(currentData) === 'DropDown') { listItem = currentData['ComboBoxList']; for (var i = 0; i < listItem.length; i++) { var itemValue = listItem[parseInt(i.toString(), 10)].itemValue ? listItem[parseInt(i.toString(), 10)].itemValue : listItem[parseInt(i.toString(), 10)].ItemValue; var itemName = listItem[parseInt(i.toString(), 10)].itemName ? listItem[parseInt(i.toString(), 10)].itemName : listItem[parseInt(i.toString(), 10)].ItemName; if (itemName === currentData['SelectedValue']) { this.selectedIndex.push(i); } options.push({ itemName: itemName, itemValue: itemValue }); } } else { for (var i = 0; i < listItem.length; i++) { if (listItem[parseInt(i.toString(), 10)] === currentData['SelectedValue']) { this.selectedIndex.push(i); } options.push({ itemName: listItem[parseInt(i.toString(), 10)], itemValue: listItem[parseInt(i.toString(), 10)] }); } } if (this.getFormFieldType(currentData) === 'ListBox') { this.selectedIndex = currentData['SelectedList']; } return options; }; FormFields.prototype.createParentElement = function (data, pageIndex) { var divElement; if (data['Name'] === 'Textbox' || data['Name'] === 'Password') { divElement = document.createElement('div'); divElement.style.background = 'white'; if (data.InsertSpaces) { divElement.style.background = 'transparent'; } var bounds = data['LineBounds']; var font = data['Font']; divElement.style.position = 'absolute'; var isFieldRotated = false; if (data['Rotation'] === 0) { isFieldRotated = true; } this.applyPosition(divElement, bounds, font, pageIndex, 0, isFieldRotated); } return divElement; }; /** * @param {number} pageIndex - It describes about the page index * @private * @returns {number} - number */ FormFields.prototype.getAngle = function (pageIndex) { var angle = 0; var pageDetails = this.pdfViewerBase.pageSize[parseInt(pageIndex.toString(), 10)]; if (pageDetails && pageDetails.rotation) { switch (pageDetails.rotation) { case 0: angle = 0; break; case 1: angle = 90; break; case 2: angle = 180; break; case 3: angle = 270; break; } } return angle; }; FormFields.prototype.nextField = function () { this.signatureFieldNavigate(true); }; FormFields.prototype.previousField = function () { this.signatureFieldNavigate(false); }; FormFields.prototype.signatureFieldNavigate = function (nextSign) { var isNextSignField = nextSign; var signatureFields = this.signatureFieldCollection; var collectionData = this.pdfViewer.formFieldCollections; if (signatureFields.length === 0) { signatureFields = this.pdfViewerBase.signatureModule.getSignField(); } var currentField; if (this.currentTarget) { if (this.pdfViewer.formDesignerModule) { for (var i = 0; i < collectionData.length; i++) { currentField = collectionData[parseInt(i.toString(), 10)]; if (this.currentTarget.id === currentField.id) { this.currentTarget = document.getElementById(currentField.id); this.getSignatureIndex(i, collectionData.length, isNextSignField); break; } } } else { for (var i = 0; i < signatureFields.length; i++) { currentField = this.pdfViewer.formDesignerModule ? signatureFields[parseInt(i.toString(), 10)]. FormField : signatureFields[parseInt(i.toString(), 10)]; if (this.currentTarget.id === currentField.uniqueID) { this.currentTarget = document.getElementById(currentField.uniqueID); this.getSignatureIndex(i, signatureFields.length, isNextSignField); break; } } } } else { if (nextSign) { if (this.pdfViewer.formDesignerModule) { currentField = signatureFields[0]; if (currentField.id) { this.currentTarget = document.getElementById(currentField.id); this.getSignatureIndex(0, signatureFields.length, isNextSignField, true); } } else { currentField = signatureFields[0]; if (currentField.uniqueID) { this.currentTarget = document.getElementById(currentField.uniqueID); this.getSignatureIndex(0, signatureFields.length, isNextSignField, true); } } } } }; FormFields.prototype.getSignatureIndex = function (currentSignatureIndex, signatureCount, isNextSign, isFirstNavigate) { var signatureIndex = currentSignatureIndex; if (!isFirstNavigate) { if (isNextSign) { signatureIndex++; } else { signatureIndex--; } } if (signatureCount === 1) { this.renderSignatureField(0); } else { if (signatureIndex < signatureCount && signatureIndex >= 0) { this.renderSignatureField(signatureIndex); } else { if (isNextSign) { if (signatureIndex >= signatureCount) { this.renderSignatureField(0); } } else { if (signatureIndex <= 0) { this.renderSignatureField(signatureCount - 1); } } } } }; FormFields.prototype.renderSignatureField = function (currentSignIndex) { var curSignIndex = currentSignIndex; var signatureFields = this.signatureFieldCollection; var collectionData = this.pdfViewer.formFieldCollections; var currentField; if (curSignIndex < collectionData.length) { for (var i = 0; i < collectionData.length; i++) { if (this.pdfViewer.formDesignerModule) { var curSignIndexId = collectionData[parseInt(curSignIndex.toString(), 10)].id; var signatureFieldData = collectionData[parseInt(i.toString(), 10)]; if (curSignIndexId === signatureFieldData.id) { var pageIndex = signatureFieldData.pageIndex >= 0 ? signatureFieldData.pageIndex : signatureFieldData.pageNumber; var isRender = this.pdfViewer.annotationModule.findRenderPageList(pageIndex); if (!isRender) { this.pdfViewer.navigation.goToPage(pageIndex + 1); this.renderFormFields(pageIndex, false); } this.currentTarget = document.getElementById(signatureFieldData.id); currentField = signatureFieldData; break; } } else { var curSignIndexId = this.pdfViewer.formDesignerModule ? signatureFields[parseInt(curSignIndex.toString(), 10)].FormField.uniqueID : signatureFields[parseInt(curSignIndex.toString(), 10)].uniqueID; var signatureFieldData = this.pdfViewer.formDesignerModule ? signatureFields[parseInt(i.toString(), 10)]. FormField : signatureFields[parseInt(i.toString(), 10)]; if (curSignIndexId === signatureFieldData.uniqueID) { var pageIndex = signatureFieldData.PageIndex >= 0 ? signatureFieldData.PageIndex : signatureFieldData.pageNumber; var isRender = this.pdfViewer.annotationModule.findRenderPageList(pageIndex); if (!isRender) { this.pdfViewer.navigation.goToPage(pageIndex + 1); this.renderFormFields(pageIndex, false); } this.currentTarget = document.getElementById(signatureFieldData.uniqueID); currentField = signatureFieldData; break; } } } if (this.currentTarget === null) { var pageIndex = currentField.PageIndex >= 0 ? currentField.PageIndex : currentField.pageNumber; this.pdfViewer.navigation.goToPage(pageIndex); this.currentTarget = document.getElementById(currentField.uniqueID); } if (this.currentTarget) { if (this.currentTarget.className === 'e-pdfviewer-signatureformfields-signature' && !(this.pdfViewer.formDesignerModule)) { document.getElementById(this.currentTarget.id).focus(); this.pdfViewer.select([this.currentTarget.id], null); } else if (this.currentTarget.className === 'e-pdfviewer-signatureformfields' || this.currentTarget.className === 'e-pdfviewer-signatureformfields-signature') { if (this.pdfViewer.formDesignerModule) { document.getElementById(this.currentTarget.id).parentElement.focus(); } else { document.getElementById(this.currentTarget.id).focus(); } } } } }; /** * @private * @returns {void} */ FormFields.prototype.formFieldCollections = function () { var data = this.pdfViewerBase.getItemFromSessionStorage('_formfields'); if (data) { var formFieldsData = JSON.parse(data); var _loop_2 = function (i) { var currentData = formFieldsData[parseInt(i.toString(), 10)]; var type = currentData['Name']; if (this_2.pdfViewer.formDesignerModule) { if (currentData.Name !== 'ink' && currentData.Name !== 'SignatureImage' && currentData.Name !== 'SignatureText') { this_2.retreiveFormFieldsData(currentData, true); } else { var index = this_2.pdfViewer.formFieldCollections.findIndex(function (field) { return (field.type === 'SignatureField' || field.type === 'InitialField') && currentData.FieldName && currentData.FieldName.includes(field.name) && currentData.FieldName.includes(field.name + '_'); }); if (index >= 0) { var value = currentData.Value; if (currentData.Name === 'ink') { var collectionData = processPathData(value); var csData = splitArrayCollection(collectionData); value = JSON.stringify(csData); } this_2.pdfViewer.formFieldCollections[parseInt(index.toString(), 10)].value = value; } } } else { if (currentData.Name !== 'ink') { var bounds = void 0; if (currentData.LineBounds) { if (isNullOrUndefined(currentData.Bounds)) { bounds = this_2.updateBoundsValue(currentData.LineBounds); } else { bounds = currentData.Bounds; } } var formFieldCollection = { name: this_2.retriveFieldName(currentData), id: this_2.pdfViewer.element.id + 'input_' + parseFloat(currentData['PageIndex']) + '_' + i, isReadOnly: false, type: currentData.IsInitialField ? 'InitialField' : type, value: this_2.retriveCurrentValue(currentData), fontName: '', isRequired: currentData.IsRequired, bounds: bounds }; this_2.pdfViewer.formFieldCollections.push(formFieldCollection); } } }; var this_2 = this; for (var i = 0; i < formFieldsData.length; i++) { _loop_2(i); } } }; FormFields.prototype.retreiveFormFieldsData = function (currentData, isCollection) { var fontFamily; var fontStyle; var fontSize; if (currentData.FieldName !== '') { if (currentData.IsInitialField) { currentData.Name = 'InitialField'; } var font = currentData['Font']; if (!isNullOrUndefined(font) && font.Height) { fontFamily = font.Name; if (font.Italic) { fontStyle = 'Italic'; } if (font.Bold) { fontStyle = 'Bold'; } if (font.Strikeout) { fontStyle = 'Strikethrough'; } if (font.Underline) { fontStyle = 'Underline'; } fontSize = this.ConvertPointToPixel(font.Size); } var textAlignment = currentData.Alignment === 2 ? 'right' : (currentData.Alignment === 1 ? 'center' : 'left'); var backgroundColor = currentData['BackColor']; var bounds = currentData['LineBounds']; var backColor = 'rgba(' + backgroundColor.R + ',' + backgroundColor.G + ',' + backgroundColor.B + ',' + 1 + ')'; backColor = this.rgbaToHex(backColor); // set default color if field have black color as bg. if (currentData.IsTransparent === true) { backColor = 'rgba(0,0,0,0)'; } else if (backColor === '#000000ff') { backColor = '#daeaf7ff'; } var fontColor = currentData['FontColor']; var left = this.ConvertPointToPixel(bounds.X); var top_2 = this.ConvertPointToPixel(bounds.Y); var width = this.ConvertPointToPixel(bounds.Width); var height = this.ConvertPointToPixel(bounds.Height); var boundArray = { left: left, top: top_2, width: width, height: height }; var foreColor = 'rgba(' + fontColor.R + ',' + fontColor.G + ',' + fontColor.B + ',' + 1 + ')'; foreColor = this.rgbaToHex(foreColor); var borderColor = currentData['BorderColor']; var borderRGB = 'rgba(' + borderColor.R + ',' + borderColor.G + ',' + borderColor.B + ',' + 1 + ')'; borderRGB = this.rgbaToHex(borderRGB); if (currentData.IsTansparentBorderColor === true) { borderRGB = 'rgba(0,0,0,0)'; } var borderWidth = currentData['BorderWidth']; this.selectedIndex = []; var fieldProperties = { bounds: { X: boundArray.left, Y: boundArray.top, Width: boundArray.width, Height: boundArray.height }, pageNumber: parseFloat(currentData['PageIndex']) + 1, name: currentData['ActualFieldName'], tooltip: currentData['ToolTip'], value: currentData['Text'], isChecked: currentData['Selected'], isSelected: currentData['Selected'], fontFamily: fontFamily, fontStyle: fontStyle, backgroundColor: backColor, color: foreColor, borderColor: borderRGB, thickness: borderWidth, fontSize: fontSize, isMultiline: currentData.Multiline, isReadOnly: currentData['IsReadonly'], isRequired: currentData['IsRequired'], insertSpaces: currentData['InsertSpaces'], alignment: textAlignment, options: this.getListValues(currentData), selectedIndex: this.selectedIndex, maxLength: currentData.MaxLength, visibility: currentData.Visible === 1 ? 'hidden' : 'visible', font: { isItalic: !isNullOrUndefined(font) ? font.Italic : false, isBold: !isNullOrUndefined(font) ? font.Bold : false, isStrikeout: !isNullOrUndefined(font) ? font.Strikeout : false, isUnderline: !isNullOrUndefined(font) ? font.Underline : false }, pageIndex: currentData['PageIndex'], isTransparent: currentData['IsTransparent'], rotationAngle: currentData['RotationAngle'], signatureType: currentData['SignatureType'] ? currentData['SignatureType'] : '', signatureIndicatorSettings: currentData['SignatureIndicatorSettings'], zIndex: currentData['zIndex'], customData: !isNullOrUndefined(currentData['CustomData']) ? typeof currentData['CustomData'] === 'object' ? currentData['CustomData'] : currentData['CustomData'].trim() !== '' ? JSON.parse(currentData['CustomData']) : '' : '' }; if (currentData.Name === 'DropDown' || currentData.Name === 'ListBox') { fieldProperties.value = currentData['SelectedValue']; } if (currentData.Name === 'RadioButton') { fieldProperties.value = currentData['Value']; } var fieldType = this.getFormFieldType(currentData); if (fieldType === 'SignatureField' || fieldType === 'InitialField') { this.addSignaturePath(currentData); if (this.isSignatureField) { fieldProperties.value = currentData.Value; } } var addedElement = this.pdfViewer.formDesignerModule.addField(fieldType, fieldProperties, isCollection); return addedElement; } return null; }; FormFields.prototype.updateBoundsValue = function (lineBounds) { var bounds = { x: this.ConvertPointToPixel(lineBounds.X), y: this.ConvertPointToPixel(lineBounds.Y), width: this.ConvertPointToPixel(lineBounds.Width), height: this.ConvertPointToPixel(lineBounds.Height) }; return bounds; }; /** * @param {any} formField - It describes about the form field * @private * @returns {void} */ FormFields.prototype.updateFormFieldsCollection = function (formField) { var type = formField['Name']; var bounds; if (formField.LineBounds) { if (isNullOrUndefined(formField.Bounds)) { bounds = this.updateBoundsValue(formField.LineBounds); } else { bounds = formField.Bounds; } } var textList = (formField.Name === 'DropDown') ? formField.ComboBoxList : formField.TextList; var formFieldCollection = { name: this.retriveFieldName(formField), id: formField.uniqueID, isReadOnly: formField.IsReadonly, isRequired: formField.IsRequired, isSelected: formField.Selected, isChecked: type === 'RadioButton' ? false : formField.Selected, type: type, value: type === 'ListBox' || type === 'DropDown' ? formField.SelectedValue : formField.Value, fontName: formField.FontFamily ? formField.FontFamily : '', pageIndex: formField.PageIndex, pageNumber: formField.PageIndex + 1, isMultiline: formField.isMultiline ? formField.isMultiline : formField.Multiline, insertSpaces: formField.insertSpaces ? formField.insertSpaces : formField.InsertSpaces, isTransparent: formField.isTransparent ? formField.isTransparent : formField.IsTransparent, rotateAngle: formField.rotateAngle ? formField.rotateAngle : formField.RotationAngle, selectedIndex: formField.selectedIndex ? formField.selectedIndex : formField.SelectedList, options: formField.options ? formField.options : textList ? textList : [], bounds: bounds, signatureType: formField.signatureType ? formField.signatureType : '', zIndex: formField.zIndex, tooltip: formField.tooltip ? formField.tooltip : formField.ToolTip ? formField.ToolTip : '', signatureIndicatorSettings: formField.signatureIndicatorSettings ? formField.signatureIndicatorSettings : '' }; this.pdfViewer.formFieldCollections[this.pdfViewer.formFieldCollections. findIndex(function (el) { return el.id === formFieldCollection.id; })] = formFieldCollection; }; FormFields.prototype.updateFormFieldValues = function (formFields) { this.readOnlyCollection.push(formFields.id); if (formFields) { var currentElement = document.getElementById(formFields.id); if (currentElement) { if (formFields.isReadOnly) { currentElement.disabled = true; currentElement.style.backgroundColor = ''; currentElement.style.cursor = 'default'; } else { if (currentElement.style.backgroundColor === '') { currentElement.style.backgroundColor = 'rgba(0, 20, 200, 0.2)'; } currentElement.disabled = false; currentElement.style.cursor = ''; } } this.updateDataInSession(currentElement); } }; /** * @param {any} currentData - It describes about the current data * @private * @returns {string} - string */ FormFields.prototype.retriveFieldName = function (currentData) { var currentField; switch (currentData['Name']) { case 'Textbox': case 'Password': case 'SignatureField': case 'InitialField': currentField = currentData.FieldName; break; case 'RadioButton': case 'CheckBox': currentField = currentData.GroupName; break; case 'DropDown': currentField = currentData.ActualFieldName; break; case 'ListBox': currentField = currentData.Text; break; } return currentField; }; FormFields.prototype.retriveCurrentValue = function (currentData) { var currentField; switch (currentData['Name']) { case 'Textbox': case 'Password': currentField = currentData.Text; break; case 'SignatureField': currentField = currentData.Value; break; case 'RadioButton': case 'CheckBox': currentField = currentData.Selected; break; case 'DropDown': currentField = currentData.SelectedValue; break; case 'ListBox': currentField = currentData.SelectedList; break; } return currentField; }; FormFields.prototype.getSignatureBounds = function (LineBounds, bounds, pageIndex) { var pageDetails = this.pdfViewerBase.pageSize[parseInt(pageIndex.toString(), 10)]; var bound = 0; switch (pageDetails.rotation) { case 0: bound = bounds; break; case 1: bound = { x: bounds.x + LineBounds.Width + (bounds.width / 3.5), y: pageDetails.width - LineBounds.X + (bounds.height / 4) }; break; case 2: bound = { x: pageDetails.width - bounds.x - bounds.width, y: pageDetails.height - bounds.y - bounds.height }; break; case 3: bound = { x: bounds.y - (bounds.width / 2) + bounds.height, y: bounds.x + (bounds.width / 3) }; break; } return bound; }; /** * @private * @returns {any} - any */ FormFields.prototype.downloadFormFieldsData = function () { var data = this.pdfViewerBase.getItemFromSessionStorage('_for