UNPKG

@syncfusion/ej2-pdfviewer

Version:
822 lines 409 kB
import { Browser, isNullOrUndefined } from '@syncfusion/ej2-base'; import { Rect } from './../ej2-drawings/index'; import { PdfAnnotationBorder, PdfRotationAngle, PdfSquareAnnotation, PdfAnnotationFlag, _PdfDictionary, _PdfName, PdfBorderEffectStyle, PdfBorderEffect, PdfAnnotationState, PdfAnnotationStateModel, PdfCircleAnnotation, PdfPopupAnnotation, PdfLineAnnotation, PdfLineEndingStyle, PdfFontStyle, PdfFontFamily, PdfStandardFont, PdfStringFormat, PdfTextAlignment, PdfRubberStampAnnotation, PdfPen, PdfBrush, PdfVerticalAlignment, PdfPath, PdfRubberStampAnnotationIcon, PdfBitmap, PdfPolyLineAnnotation, PdfCircleMeasurementType, PdfPopupIcon, PdfFreeTextAnnotation, PdfBorderStyle, PdfRectangleAnnotation, PdfPolygonAnnotation, PdfEllipseAnnotation, PdfTextMarkupAnnotation, PdfInkAnnotation, PdfLineIntent, PdfTemplate, PdfTextMarkupAnnotationType, PdfLineCaptionType, PdfMeasurementUnit, PdfAnnotationIntent, PdfTrueTypeFont, _decode, _annotationFlagsToString, PdfRedactionAnnotation } from '@syncfusion/ej2-pdf'; import { SizeBase, getArialFontData } from '../index'; import { PdfViewerUtils } from '../base/pdfviewer-utlis'; /** * AnnotationRenderer * * @hidden */ var AnnotationRenderer = /** @class */ (function () { /** * @param {PdfViewer} pdfViewer - The PdfViewer. * @param {PdfViewerBase} pdfViewerBase - The PdfViewerBase. * @private */ function AnnotationRenderer(pdfViewer, pdfViewerBase) { this.annotNames = new Set(); this.formats = ['M/d/yyyy h:mm:ss tt', 'M/d/yyyy, h:mm:ss tt', 'M/d/yyyy h:mm tt', 'MM/dd/yyyy hh:mm:ss', 'M/d/yyyy h:mm:ss', 'M/d/yyyy hh:mm tt', 'M/d/yyyy hh tt', 'M/d/yyyy h:mm', 'M/d/yyyy h:mm', 'MM/dd/yyyy hh:mm', 'M/dd/yyyy hh:mm', 'dd/M/yyyy h:mm:ss tt', 'dd/M/yyyy, h:mm:ss tt', 'M/d/yy, h:mm:ss tt', 'yyyy/MM/dd, h:mm:ss tt', 'dd/MMM/yy, h:mm:ss tt', 'yyyy-MM-dd, h:mm:ss tt', 'dd-MMM-yy, h:mm:ss tt', 'MM-dd-yy, h:mm:ss tt', 'YYYY-MM-DDTHH:mm:ss.sssZ', '±YYYYYY-MM-DDTHH:mm:ss.sssZ', 'yyyy-MM-ddTHH:mm:ss.fffZ']; this.pdfViewer = pdfViewer; this.pdfViewerBase = pdfViewerBase; } /** * @param {any} details - details * @param {PdfPage} page - page * @private * @returns {void} */ AnnotationRenderer.prototype.addShape = function (details, page) { var shapeAnnotation = details; var isLock = this.checkAnnotationLock(shapeAnnotation); if (!isNullOrUndefined(shapeAnnotation.shapeAnnotationType) && shapeAnnotation.shapeAnnotationType === 'Line') { var points = JSON.parse(shapeAnnotation.vertexPoints); var linePoints = this.getSaveVertexPoints(points, page); var startPoint = { x: linePoints[0].x, y: linePoints[0].y }; var endPoint = { x: linePoints[1].x, y: linePoints[1].y }; var lineAnnotation = new PdfLineAnnotation(startPoint, endPoint); if (!isNullOrUndefined(shapeAnnotation.note)) { lineAnnotation.text = shapeAnnotation.note.toString(); } lineAnnotation.author = !isNullOrUndefined(shapeAnnotation.author) && shapeAnnotation.author.toString() !== '' ? shapeAnnotation.author.toString() : 'Guest'; lineAnnotation._dictionary.set('NM', shapeAnnotation.annotName.toString()); if (!isNullOrUndefined(shapeAnnotation.subject)) { lineAnnotation.subject = shapeAnnotation.subject.toString(); } if (!isNullOrUndefined(shapeAnnotation.strokeColor)) { var strokeColor = JSON.parse(shapeAnnotation.strokeColor); var color = { r: strokeColor.r, g: strokeColor.g, b: strokeColor.b }; lineAnnotation.color = color; } if (!isNullOrUndefined(shapeAnnotation.fillColor)) { var fillColor = JSON.parse(shapeAnnotation.fillColor); if (!isNullOrUndefined(fillColor.r) && !isNullOrUndefined(fillColor.g) && !isNullOrUndefined(fillColor.b) && !isNullOrUndefined(fillColor.a) && fillColor.a > 0) { var innerColor = { r: fillColor.r, g: fillColor.g, b: fillColor.b }; lineAnnotation.innerColor = innerColor; } } if (!isNullOrUndefined(shapeAnnotation.opacity)) { lineAnnotation.opacity = shapeAnnotation.opacity; } var lineBorder = new PdfAnnotationBorder(); lineBorder.width = shapeAnnotation.thickness; lineBorder.style = shapeAnnotation.borderStyle; lineBorder.dash = shapeAnnotation.borderDashArray; lineAnnotation.border = lineBorder; lineAnnotation.rotationAngle = this.getRotateAngle(shapeAnnotation.rotateAngle); lineAnnotation.lineEndingStyle.begin = this.getLineEndingStyle(shapeAnnotation.lineHeadStart); lineAnnotation.lineEndingStyle.end = this.getLineEndingStyle(shapeAnnotation.lineHeadEnd); var dateValue = void 0; if (!isNullOrUndefined(shapeAnnotation.modifiedDate) && !isNaN(Date.parse(shapeAnnotation.modifiedDate))) { dateValue = new Date(Date.parse(shapeAnnotation.modifiedDate)); lineAnnotation.modifiedDate = dateValue; } var commentsDetails = shapeAnnotation.comments; var bounds = JSON.parse(shapeAnnotation.bounds); lineAnnotation.bounds = bounds; lineAnnotation.bounds.x = bounds.left; lineAnnotation.bounds.y = bounds.top; if (commentsDetails.length > 0) { for (var i = 0; i < commentsDetails.length; i++) { lineAnnotation.comments.add(this.addCommentsCollection(commentsDetails[parseInt(i.toString(), 10)], lineAnnotation.bounds)); } } var reviewDetails = shapeAnnotation.review; lineAnnotation.reviewHistory.add(this.addReviewCollections(reviewDetails, lineAnnotation.bounds)); this.preserveIsLockProperty(shapeAnnotation, lineAnnotation); if (!isNullOrUndefined(shapeAnnotation.customData)) { lineAnnotation.setValues('CustomData', JSON.stringify(shapeAnnotation.customData)); } if (shapeAnnotation.allowedInteractions && shapeAnnotation['allowedInteractions'] != null) { lineAnnotation.setValues('AllowedInteractions', JSON.stringify(shapeAnnotation['allowedInteractions'])); } if (shapeAnnotation.annotationSelectorSettings && shapeAnnotation['annotationSelectorSettings'] != null) { lineAnnotation.setValues('AnnotationSelectorSettings', JSON.stringify(shapeAnnotation['annotationSelectorSettings'])); } if (shapeAnnotation.originalName) { lineAnnotation.name = shapeAnnotation.originalName; } if (!isNullOrUndefined(shapeAnnotation.isPrint)) { lineAnnotation._dictionary.set('IsPrint', shapeAnnotation.isPrint); } lineAnnotation.setAppearance(true); page.annotations.add(lineAnnotation); } else if (!isNullOrUndefined(shapeAnnotation.shapeAnnotationType) && shapeAnnotation.shapeAnnotationType === 'Square') { var bounds = JSON.parse(shapeAnnotation.bounds); if (isNullOrUndefined(bounds.left)) { shapeAnnotation.bounds.left = 0; } if (isNullOrUndefined(bounds.top)) { shapeAnnotation.bounds.top = 0; } var cropValues = this.getCropBoxValue(page, false); var left = this.convertPixelToPoint(bounds.left); var top_1 = this.convertPixelToPoint(bounds.top); var width = this.convertPixelToPoint(bounds.width); var height = this.convertPixelToPoint(bounds.height); var cropX = 0; var cropY = 0; if (cropValues.x !== 0 && cropValues.y !== 0 && cropValues.x === left) { cropX = cropValues.x; cropY = cropValues.y; } else if (cropValues.x === 0 && page.cropBox[2] === page.size.width && cropValues.y === page.size.height) { cropX = cropValues.x; cropY = cropValues.y; } var squareAnnotation = new PdfSquareAnnotation({ x: cropX + left, y: cropY + top_1, width: width, height: height }); if (!isNullOrUndefined(shapeAnnotation.note)) { squareAnnotation.text = shapeAnnotation.note.toString(); } squareAnnotation.author = !isNullOrUndefined(shapeAnnotation.author) && shapeAnnotation.author.toString() !== '' ? shapeAnnotation.author.toString() : 'Guest'; squareAnnotation._dictionary.set('NM', shapeAnnotation.annotName.toString()); if (!isNullOrUndefined(shapeAnnotation.subject)) { squareAnnotation.subject = shapeAnnotation.subject.toString(); } if (!isNullOrUndefined(shapeAnnotation.strokeColor)) { var strokeColor = JSON.parse(shapeAnnotation.strokeColor); var color = { r: strokeColor.r, g: strokeColor.g, b: strokeColor.b }; squareAnnotation.color = color; } if (!isNullOrUndefined(shapeAnnotation.fillColor)) { var fillColor = JSON.parse(shapeAnnotation.fillColor); if (!this.isTransparentColor(fillColor)) { var innerColor = { r: fillColor.r, g: fillColor.g, b: fillColor.b }; squareAnnotation.innerColor = innerColor; } if (fillColor.a < 1 && fillColor.a > 0) { squareAnnotation._dictionary.update('FillOpacity', fillColor.a); fillColor.a = 1; } else { squareAnnotation._dictionary.update('FillOpacity', fillColor.a); } } if (!isNullOrUndefined(shapeAnnotation.opacity)) { squareAnnotation.opacity = shapeAnnotation.opacity; } var lineBorder = new PdfAnnotationBorder(); lineBorder.width = shapeAnnotation.thickness; lineBorder.style = shapeAnnotation.borderStyle; lineBorder.dash = shapeAnnotation.borderDashArray; squareAnnotation.border = lineBorder; squareAnnotation.rotationAngle = this.getRotateAngle(shapeAnnotation.rotateAngle); var dateValue = void 0; if (!isNullOrUndefined(shapeAnnotation.modifiedDate) && !isNaN(Date.parse(shapeAnnotation.modifiedDate))) { dateValue = new Date(Date.parse(shapeAnnotation.modifiedDate)); squareAnnotation.modifiedDate = dateValue; } var commentsDetails = shapeAnnotation.comments; if (commentsDetails.length > 0) { for (var i = 0; i < commentsDetails.length; i++) { squareAnnotation.comments.add(this.addCommentsCollection(commentsDetails[parseInt(i.toString(), 10)], squareAnnotation.bounds)); } } var reviewDetails = shapeAnnotation.review; squareAnnotation.reviewHistory.add(this.addReviewCollections(reviewDetails, squareAnnotation.bounds)); if (!isNullOrUndefined(shapeAnnotation.isCloudShape) && shapeAnnotation.isCloudShape) { var borderEffect = new PdfBorderEffect(); borderEffect.style = PdfBorderEffectStyle.cloudy; borderEffect.intensity = shapeAnnotation.cloudIntensity; squareAnnotation.borderEffect = borderEffect; var rectDifferences = JSON.parse(shapeAnnotation.rectangleDifference); if (rectDifferences.length > 0) { var rd = this.getRDValues(rectDifferences); squareAnnotation._dictionary.update('RD', rd); } } this.preserveIsLockProperty(shapeAnnotation, squareAnnotation); if (!isNullOrUndefined(shapeAnnotation.customData)) { squareAnnotation.setValues('CustomData', JSON.stringify(shapeAnnotation.customData)); } if (shapeAnnotation.allowedInteractions && shapeAnnotation['allowedInteractions'] != null) { squareAnnotation.setValues('AllowedInteractions', JSON.stringify(shapeAnnotation['allowedInteractions'])); } if (shapeAnnotation.annotationSelectorSettings && shapeAnnotation['annotationSelectorSettings'] != null) { squareAnnotation.setValues('AnnotationSelectorSettings', JSON.stringify(shapeAnnotation['annotationSelectorSettings'])); } if (shapeAnnotation.originalName) { squareAnnotation.name = shapeAnnotation.originalName; } if (!isNullOrUndefined(shapeAnnotation.isPrint)) { squareAnnotation._dictionary.set('IsPrint', shapeAnnotation.isPrint); } squareAnnotation.setAppearance(true); page.annotations.add(squareAnnotation); } else if (!isNullOrUndefined(shapeAnnotation.shapeAnnotationType) && shapeAnnotation.shapeAnnotationType === 'Circle') { var bounds = JSON.parse(shapeAnnotation.bounds); var left = !isNullOrUndefined(bounds.left) ? this.convertPixelToPoint(bounds.left) : 0; var top_2 = !isNullOrUndefined(bounds.top) ? this.convertPixelToPoint(bounds.top) : 0; var width = !isNullOrUndefined(bounds.width) ? this.convertPixelToPoint(bounds.width) : 0; var height = !isNullOrUndefined(bounds.height) ? this.convertPixelToPoint(bounds.height) : 0; var cropValues = this.getCropBoxValue(page, false); var cropX = 0; var cropY = 0; if (cropValues.x !== 0 && cropValues.y !== 0 && cropValues.x === left) { cropX = cropValues.x; cropY = cropValues.y; } else if (cropValues.x === 0 && page.cropBox[2] === page.size.width && cropValues.y === page.size.height) { cropX = cropValues.x; cropY = cropValues.y; } var circleAnnotation = new PdfCircleAnnotation({ x: cropX + left, y: cropY + top_2, width: width, height: height }); if (!isNullOrUndefined(shapeAnnotation.note)) { circleAnnotation.text = shapeAnnotation.note.toString(); } circleAnnotation.author = !isNullOrUndefined(shapeAnnotation.author) && shapeAnnotation.author.toString() !== '' ? shapeAnnotation.author.toString() : 'Guest'; circleAnnotation._dictionary.set('NM', shapeAnnotation.annotName.toString()); if (!isNullOrUndefined(shapeAnnotation.subject)) { circleAnnotation.subject = shapeAnnotation.subject.toString(); } if (!isNullOrUndefined(shapeAnnotation.strokeColor)) { var strokeColor = JSON.parse(shapeAnnotation.strokeColor); var color = { r: strokeColor.r, g: strokeColor.g, b: strokeColor.b }; circleAnnotation.color = color; } if (!isNullOrUndefined(shapeAnnotation.fillColor)) { var fillColor = JSON.parse(shapeAnnotation.fillColor); if (!this.isTransparentColor(fillColor)) { var innerColor = { r: fillColor.r, g: fillColor.g, b: fillColor.b }; circleAnnotation.innerColor = innerColor; } if (fillColor.a < 1 && fillColor.a > 0) { circleAnnotation._dictionary.update('FillOpacity', fillColor.a); fillColor.a = 1; } else { circleAnnotation._dictionary.update('FillOpacity', fillColor.a); } } if (!isNullOrUndefined(shapeAnnotation.opacity)) { circleAnnotation.opacity = shapeAnnotation.opacity; } var lineBorder = new PdfAnnotationBorder(); lineBorder.width = shapeAnnotation.thickness; lineBorder.style = shapeAnnotation.borderStyle; lineBorder.dash = shapeAnnotation.borderDashArray; circleAnnotation.border = lineBorder; circleAnnotation.rotationAngle = this.getRotateAngle(shapeAnnotation.rotateAngle); var dateValue = void 0; if (!isNullOrUndefined(shapeAnnotation.modifiedDate) && !isNaN(Date.parse(shapeAnnotation.modifiedDate))) { dateValue = new Date(Date.parse(shapeAnnotation.modifiedDate)); circleAnnotation.modifiedDate = dateValue; } var commentsDetails = shapeAnnotation.comments; if (commentsDetails.length > 0) { for (var i = 0; i < commentsDetails.length; i++) { circleAnnotation.comments.add(this.addCommentsCollection(commentsDetails[parseInt(i.toString(), 10)], circleAnnotation.bounds)); } } var reviewDetails = shapeAnnotation.review; circleAnnotation.reviewHistory.add(this.addReviewCollections(reviewDetails, circleAnnotation.bounds)); if (!isNullOrUndefined(shapeAnnotation.isCloudShape) && shapeAnnotation.isCloudShape) { var borderEffect = new PdfBorderEffect(); borderEffect.style = PdfBorderEffectStyle.cloudy; borderEffect.intensity = shapeAnnotation.cloudIntensity; circleAnnotation._borderEffect = borderEffect; var rectDifferences = JSON.parse(shapeAnnotation.rectangleDifference); if (rectDifferences.length > 0) { var rd = this.getRDValues(rectDifferences); circleAnnotation._dictionary.update('RD', rd); } } this.preserveIsLockProperty(shapeAnnotation, circleAnnotation); if (!isNullOrUndefined(shapeAnnotation.customData)) { circleAnnotation.setValues('CustomData', JSON.stringify(shapeAnnotation.customData)); } if (shapeAnnotation.allowedInteractions && shapeAnnotation['allowedInteractions'] != null) { circleAnnotation.setValues('AllowedInteractions', JSON.stringify(shapeAnnotation['allowedInteractions'])); } if (shapeAnnotation.annotationSelectorSettings && shapeAnnotation['annotationSelectorSettings'] != null) { circleAnnotation.setValues('AnnotationSelectorSettings', JSON.stringify(shapeAnnotation['annotationSelectorSettings'])); } if (shapeAnnotation.originalName) { circleAnnotation.name = shapeAnnotation.originalName; } if (!isNullOrUndefined(shapeAnnotation.isPrint)) { circleAnnotation._dictionary.set('IsPrint', shapeAnnotation.isPrint); } circleAnnotation.setAppearance(true); page.annotations.add(circleAnnotation); } else if (!isNullOrUndefined(shapeAnnotation.shapeAnnotationType) && shapeAnnotation.shapeAnnotationType === 'Polygon') { var points = JSON.parse(shapeAnnotation.vertexPoints); var linePoints = this.getSaveVertexPoints(points, page); var bounds = JSON.parse(shapeAnnotation.bounds); if (isNullOrUndefined(bounds.left)) { shapeAnnotation.bounds.left = 0; } if (isNullOrUndefined(bounds.top)) { shapeAnnotation.bounds.top = 0; } var left = this.convertPixelToPoint(bounds.left); var top_3 = this.convertPixelToPoint(bounds.top); var width = this.convertPixelToPoint(bounds.width); var height = this.convertPixelToPoint(bounds.height); var polygonAnnotation = new PdfPolygonAnnotation(linePoints); polygonAnnotation.bounds = new Rect(left, top_3, width, height); if (!isNullOrUndefined(shapeAnnotation.note)) { polygonAnnotation.text = shapeAnnotation.note.toString(); } polygonAnnotation.author = !isNullOrUndefined(shapeAnnotation.author) && shapeAnnotation.author.toString() !== '' ? shapeAnnotation.author.toString() : 'Guest'; if (!isNullOrUndefined(shapeAnnotation.subject)) { polygonAnnotation.subject = shapeAnnotation.subject.toString(); } polygonAnnotation._dictionary.set('NM', shapeAnnotation.annotName.toString()); if (!isNullOrUndefined(shapeAnnotation.strokeColor)) { var strokeColor = JSON.parse(shapeAnnotation.strokeColor); var color = { r: strokeColor.r, g: strokeColor.g, b: strokeColor.b }; polygonAnnotation.color = color; } if (!isNullOrUndefined(shapeAnnotation.fillColor)) { var fillColor = JSON.parse(shapeAnnotation.fillColor); if (!this.isTransparentColor(fillColor)) { var innerColor = { r: fillColor.r, g: fillColor.g, b: fillColor.b }; polygonAnnotation.innerColor = innerColor; } if (fillColor.a < 1 && fillColor.a > 0) { polygonAnnotation._dictionary.update('FillOpacity', fillColor.a); fillColor.a = 1; } else { polygonAnnotation._dictionary.update('FillOpacity', fillColor.a); } } if (!isNullOrUndefined(shapeAnnotation.opacity)) { polygonAnnotation.opacity = shapeAnnotation.opacity; } var lineBorder = new PdfAnnotationBorder(); lineBorder.width = shapeAnnotation.thickness; lineBorder.style = shapeAnnotation.borderStyle; lineBorder.dash = shapeAnnotation.borderDashArray; polygonAnnotation.border = lineBorder; polygonAnnotation.rotationAngle = this.getRotateAngle(shapeAnnotation.rotateAngle); var dateValue = void 0; if (!isNullOrUndefined(shapeAnnotation.modifiedDate) && !isNaN(Date.parse(shapeAnnotation.modifiedDate))) { dateValue = new Date(Date.parse(shapeAnnotation.modifiedDate)); polygonAnnotation.modifiedDate = dateValue; } var commentsDetails = shapeAnnotation.comments; if (commentsDetails.length > 0) { for (var i = 0; i < commentsDetails.length; i++) { polygonAnnotation.comments.add(this.addCommentsCollection(commentsDetails[parseInt(i.toString(), 10)], polygonAnnotation.bounds)); } } var reviewDetails = shapeAnnotation.review; polygonAnnotation.reviewHistory.add(this.addReviewCollections(reviewDetails, polygonAnnotation.bounds)); if (!isNullOrUndefined(shapeAnnotation.isCloudShape) && shapeAnnotation.isCloudShape) { var borderEffect = new PdfBorderEffect(); borderEffect.style = PdfBorderEffectStyle.cloudy; borderEffect.intensity = shapeAnnotation.cloudIntensity; polygonAnnotation.borderEffect = borderEffect; var rectDifferences = JSON.parse(shapeAnnotation.rectangleDifference); if (rectDifferences.length > 0) { var rd = this.getRDValues(rectDifferences); polygonAnnotation._dictionary.update('RD', rd); } } this.preserveIsLockProperty(shapeAnnotation, polygonAnnotation); if (!isNullOrUndefined(shapeAnnotation.customData)) { polygonAnnotation.setValues('CustomData', JSON.stringify(shapeAnnotation.customData)); } if (!isNullOrUndefined(shapeAnnotation.allowedInteractions)) { polygonAnnotation.setValues('AllowedInteractions', JSON.stringify(shapeAnnotation.allowedInteractions)); } if (shapeAnnotation.annotationSelectorSettings && shapeAnnotation['annotationSelectorSettings'] != null) { polygonAnnotation.setValues('AnnotationSelectorSettings', JSON.stringify(shapeAnnotation['annotationSelectorSettings'])); } if (shapeAnnotation.originalName) { polygonAnnotation.name = shapeAnnotation.originalName; } if (!isNullOrUndefined(shapeAnnotation.isPrint)) { polygonAnnotation._dictionary.set('IsPrint', shapeAnnotation.isPrint); } polygonAnnotation.setAppearance(true); page.annotations.add(polygonAnnotation); } else if (!isNullOrUndefined(shapeAnnotation.shapeAnnotationType) && shapeAnnotation.shapeAnnotationType === 'Polyline') { var points = JSON.parse(shapeAnnotation.vertexPoints); var linePoints = this.getSaveVertexPoints(points, page); var bounds = JSON.parse(shapeAnnotation.bounds); var polylineAnnotation = new PdfPolyLineAnnotation(linePoints); polylineAnnotation.bounds = new Rect(this.convertPixelToPoint(bounds.left ? bounds.left : 0), this.convertPixelToPoint(bounds.top ? bounds.top : 0), this.convertPixelToPoint(bounds.width ? bounds.width : 0), this.convertPixelToPoint(bounds.height ? bounds.height : 0)); if (!isNullOrUndefined(shapeAnnotation.note)) { polylineAnnotation.text = shapeAnnotation.note.toString(); } polylineAnnotation.author = !isNullOrUndefined(shapeAnnotation.author) && shapeAnnotation.author.toString() !== '' ? shapeAnnotation.author.toString() : 'Guest'; if (!isNullOrUndefined(shapeAnnotation.subject)) { polylineAnnotation.subject = shapeAnnotation.subject.toString(); } polylineAnnotation._dictionary.set('NM', shapeAnnotation.annotName.toString()); if (!isNullOrUndefined(shapeAnnotation.strokeColor)) { var strokeColor = JSON.parse(shapeAnnotation.strokeColor); var color = { r: strokeColor.r, g: strokeColor.g, b: strokeColor.b }; polylineAnnotation.color = color; } if (!isNullOrUndefined(shapeAnnotation.fillColor)) { var fillColor = JSON.parse(shapeAnnotation.fillColor); if (!this.isTransparentColor(fillColor)) { var innerColor = { r: fillColor.r, g: fillColor.g, b: fillColor.b }; polylineAnnotation.innerColor = innerColor; } if (fillColor.a < 1 && fillColor.a > 0) { polylineAnnotation._dictionary.update('FillOpacity', fillColor.a); fillColor.a = 1; } else { polylineAnnotation._dictionary.update('FillOpacity', fillColor.a); } } if (!isNullOrUndefined(shapeAnnotation.opacity)) { polylineAnnotation.opacity = shapeAnnotation.opacity; } var lineBorder = new PdfAnnotationBorder(); lineBorder.width = shapeAnnotation.thickness; lineBorder.style = shapeAnnotation.borderStyle; lineBorder.dash = shapeAnnotation.borderDashArray; polylineAnnotation.border = lineBorder; polylineAnnotation.rotationAngle = this.getRotateAngle(shapeAnnotation.rotateAngle); polylineAnnotation.beginLineStyle = this.getLineEndingStyle(shapeAnnotation.lineHeadStart); polylineAnnotation.endLineStyle = this.getLineEndingStyle(shapeAnnotation.lineHeadEnd); var dateValue = void 0; if (!isNullOrUndefined(shapeAnnotation.modifiedDate) && !isNaN(Date.parse(shapeAnnotation.modifiedDate))) { dateValue = new Date(Date.parse(shapeAnnotation.modifiedDate)); polylineAnnotation.modifiedDate = dateValue; } var commentsDetails = shapeAnnotation.comments; if (commentsDetails.length > 0) { for (var i = 0; i < commentsDetails.length; i++) { polylineAnnotation.comments.add(this.addCommentsCollection(commentsDetails[parseInt(i.toString(), 10)], polylineAnnotation.bounds)); } } var reviewDetails = shapeAnnotation.review; polylineAnnotation.reviewHistory.add(this.addReviewCollections(reviewDetails, polylineAnnotation.bounds)); if (!isNullOrUndefined(shapeAnnotation.isCloudShape) && shapeAnnotation.isCloudShape) { var dictionary = new _PdfDictionary(page._crossReference); dictionary.update('S', _PdfName.get('C')); dictionary.update('I', shapeAnnotation.cloudIntensity); polylineAnnotation._dictionary.update('BE', dictionary); var rectDifferences = JSON.parse(shapeAnnotation.rectangleDifference); if (rectDifferences.length > 0) { var rd = this.getRDValues(rectDifferences); polylineAnnotation._dictionary.update('RD', rd); } } this.preserveIsLockProperty(shapeAnnotation, polylineAnnotation); polylineAnnotation.setAppearance(true); if (!isNullOrUndefined(shapeAnnotation.customData)) { polylineAnnotation.setValues('CustomData', JSON.stringify(shapeAnnotation.customData)); } if (!isNullOrUndefined(shapeAnnotation.allowedInteractions)) { polylineAnnotation.setValues('AllowedInteractions', JSON.stringify(shapeAnnotation.allowedInteractions)); } if (shapeAnnotation.annotationSelectorSettings && shapeAnnotation['annotationSelectorSettings'] != null) { polylineAnnotation.setValues('AnnotationSelectorSettings', JSON.stringify(shapeAnnotation['annotationSelectorSettings'])); } if (shapeAnnotation.originalName) { polylineAnnotation.name = shapeAnnotation.originalName; } if (!isNullOrUndefined(shapeAnnotation.isPrint)) { polylineAnnotation._dictionary.set('IsPrint', shapeAnnotation.isPrint); } page.annotations.add(polylineAnnotation); } if (!isNullOrUndefined(shapeAnnotation.enableShapeLabel) && shapeAnnotation.enableShapeLabel) { this.addLabelToAnnotations(shapeAnnotation, page); } }; /** * @param {any} details - details * @param {PdfPage} page - page * @private * @returns {void} */ AnnotationRenderer.prototype.updateShape = function (details, page) { var shapeAnnotation = details; var isLock = this.checkAnnotationLock(shapeAnnotation); var pageNo = parseInt(shapeAnnotation['pageNumber'].toString(), 10); var annotationIndex = parseInt(shapeAnnotation['annotationIndex'].toString(), 10); var shapeLabelName = shapeAnnotation['shapeLabelName']; var annotation; var shapeLableAnnotation; var pdfAnnotations = page.annotations; var matchedAnnotation = this.pdfViewerBase.pdfAnnotationList.find(function (item) { return item.annotationIndex === annotationIndex && item.pageIndex === pageNo; }); for (var i = 0; i < pdfAnnotations.count; i++) { var currentAnnotation = page.annotations.at(i); if (currentAnnotation._dictionary.objId === matchedAnnotation.annotation._dictionary.objId) { annotation = currentAnnotation; break; } } var matchedShapeLabelAnnotation = this.pdfViewerBase.pdfAnnotationList.find(function (item) { return item.annotation.name === shapeLabelName; }); if (matchedShapeLabelAnnotation) { for (var i = 0; i < pdfAnnotations.count; i++) { var currentAnnotation = page.annotations.at(i); if (currentAnnotation._dictionary.objId === matchedShapeLabelAnnotation.annotation._dictionary.objId) { shapeLableAnnotation = currentAnnotation; break; } } } if (!isNullOrUndefined(shapeAnnotation.shapeAnnotationType) && shapeAnnotation.shapeAnnotationType === 'Line' && (annotation instanceof PdfLineAnnotation)) { var points = JSON.parse(shapeAnnotation.vertexPoints); var linePoints = this.getSaveVertexPoints(points, page); var lineAnnotation = annotation; lineAnnotation.linePoints = linePoints; if (!isNullOrUndefined(shapeAnnotation.note)) { lineAnnotation.text = shapeAnnotation.note.toString(); } lineAnnotation.author = !isNullOrUndefined(shapeAnnotation.author) && shapeAnnotation.author.toString() !== '' ? shapeAnnotation.author.toString() : 'Guest'; lineAnnotation._dictionary.set('NM', shapeAnnotation.annotName.toString()); if (!isNullOrUndefined(shapeAnnotation.subject)) { lineAnnotation.subject = shapeAnnotation.subject.toString(); } if (!isNullOrUndefined(shapeAnnotation.strokeColor)) { var strokeColor = JSON.parse(shapeAnnotation.strokeColor); var color = { r: strokeColor.r, g: strokeColor.g, b: strokeColor.b }; lineAnnotation.color = color; } if (!isNullOrUndefined(shapeAnnotation.fillColor)) { var fillColor = JSON.parse(shapeAnnotation.fillColor); if (!isNullOrUndefined(fillColor.r) && !isNullOrUndefined(fillColor.g) && !isNullOrUndefined(fillColor.b) && !isNullOrUndefined(fillColor.a) && fillColor.a > 0) { var innerColor = { r: fillColor.r, g: fillColor.g, b: fillColor.b }; lineAnnotation.innerColor = innerColor; } } if (!isNullOrUndefined(shapeAnnotation.opacity)) { lineAnnotation.opacity = shapeAnnotation.opacity; } var lineBorder = lineAnnotation.border; lineBorder.width = shapeAnnotation.thickness; lineBorder.style = shapeAnnotation.borderStyle; lineBorder.dash = shapeAnnotation.borderDashArray; lineAnnotation.border = lineBorder; lineAnnotation.rotationAngle = this.getRotateAngle(shapeAnnotation.rotateAngle); lineAnnotation.lineEndingStyle.begin = this.getLineEndingStyle(shapeAnnotation.lineHeadStart); lineAnnotation.lineEndingStyle.end = this.getLineEndingStyle(shapeAnnotation.lineHeadEnd); var dateValue = void 0; if (!isNullOrUndefined(shapeAnnotation.modifiedDate) && !isNaN(Date.parse(shapeAnnotation.modifiedDate))) { dateValue = new Date(Date.parse(shapeAnnotation.modifiedDate)); lineAnnotation.modifiedDate = dateValue; } var commentsDetails = shapeAnnotation.comments; var bounds = JSON.parse(shapeAnnotation.bounds); lineAnnotation.bounds.height = bounds.height; lineAnnotation.bounds.width = bounds.width; lineAnnotation.bounds.x = bounds.left; lineAnnotation.bounds.y = bounds.top; if (commentsDetails.length > 0) { var validIndices = commentsDetails.map(function (detail) { return detail.commentsIndex; }); var _loop_1 = function (j) { var detail = commentsDetails.find(function (d) { return d.commentsIndex === j; }); if (detail && detail.commentStatus === 'ExistingModified') { this_1.updateCommentsCollection(detail, lineAnnotation.comments.at(j), lineAnnotation.bounds); } }; var this_1 = this; // Step 1: Update existing comments for (var j = 0; j < lineAnnotation.comments.count; j++) { _loop_1(j); } // Step 2: Remove comments not present in commentsDetails for (var j = lineAnnotation.comments.count - 1; j >= 0; j--) { if (!validIndices.includes(j)) { lineAnnotation.comments.removeAt(j); } } // Step 3: Add new comments for (var _i = 0, commentsDetails_1 = commentsDetails; _i < commentsDetails_1.length; _i++) { var detail = commentsDetails_1[_i]; if (detail.commentStatus === 'NewlyAdded' && detail.shapeAnnotationType === '') { lineAnnotation.comments.add(this.addCommentsCollection(detail, lineAnnotation.bounds)); } } } var reviewDetails = shapeAnnotation.review; this.updateReviewCollections(lineAnnotation, reviewDetails, lineAnnotation.bounds); this.preserveIsLockProperty(shapeAnnotation, lineAnnotation); if (!isNullOrUndefined(shapeAnnotation.customData)) { lineAnnotation.setValues('CustomData', JSON.stringify(shapeAnnotation.customData)); } if (shapeAnnotation.allowedInteractions && shapeAnnotation['allowedInteractions'] != null) { lineAnnotation.setValues('AllowedInteractions', JSON.stringify(shapeAnnotation['allowedInteractions'])); } lineAnnotation.setAppearance(true); lineAnnotation._dictionary._updated = true; } else if (!isNullOrUndefined(shapeAnnotation.shapeAnnotationType) && shapeAnnotation.shapeAnnotationType === 'Square' && (annotation instanceof PdfSquareAnnotation || annotation instanceof PdfRectangleAnnotation)) { var bounds = JSON.parse(shapeAnnotation.bounds); if (isNullOrUndefined(bounds.left)) { shapeAnnotation.bounds.left = 0; } if (isNullOrUndefined(bounds.top)) { shapeAnnotation.bounds.top = 0; } var cropValues = this.getCropBoxValue(page, false); var left = this.convertPixelToPoint(bounds.left); var top_4 = this.convertPixelToPoint(bounds.top); var width = this.convertPixelToPoint(bounds.width); var height = this.convertPixelToPoint(bounds.height); var cropX = 0; var cropY = 0; if (cropValues.x !== 0 && cropValues.y !== 0 && cropValues.x === left) { cropX = cropValues.x; cropY = cropValues.y; } else if (cropValues.x === 0 && page.cropBox[2] === page.size.width && cropValues.y === page.size.height) { cropX = cropValues.x; cropY = cropValues.y; } var squareAnnotation = annotation; var x = cropX + left; var y = cropY + top_4; squareAnnotation.bounds = { x: x, y: y, width: width, height: height }; if (!isNullOrUndefined(shapeAnnotation.note)) { squareAnnotation.text = shapeAnnotation.note.toString(); } squareAnnotation.author = !isNullOrUndefined(shapeAnnotation.author) && shapeAnnotation.author.toString() !== '' ? shapeAnnotation.author.toString() : 'Guest'; squareAnnotation._dictionary.set('NM', shapeAnnotation.annotName.toString()); if (!isNullOrUndefined(shapeAnnotation.subject)) { squareAnnotation.subject = shapeAnnotation.subject.toString(); } if (!isNullOrUndefined(shapeAnnotation.strokeColor)) { var strokeColor = JSON.parse(shapeAnnotation.strokeColor); var color = { r: strokeColor.r, g: strokeColor.g, b: strokeColor.b }; squareAnnotation.color = color; } if (!isNullOrUndefined(shapeAnnotation.fillColor)) { var fillColor = JSON.parse(shapeAnnotation.fillColor); if (!this.isTransparentColor(fillColor)) { var innerColor = { r: fillColor.r, g: fillColor.g, b: fillColor.b }; squareAnnotation.innerColor = innerColor; } if (fillColor.a < 1 && fillColor.a > 0) { squareAnnotation._dictionary.update('FillOpacity', fillColor.a); fillColor.a = 1; } else { squareAnnotation._dictionary.update('FillOpacity', fillColor.a); } } if (!isNullOrUndefined(shapeAnnotation.opacity)) { squareAnnotation.opacity = shapeAnnotation.opacity; } var lineBorder = squareAnnotation.border; lineBorder.width = shapeAnnotation.thickness; lineBorder.style = shapeAnnotation.borderStyle; lineBorder.dash = shapeAnnotation.borderDashArray; squareAnnotation.border = lineBorder; squareAnnotation.rotationAngle = this.getRotateAngle(shapeAnnotation.rotateAngle); var dateValue = void 0; if (!isNullOrUndefined(shapeAnnotation.modifiedDate) && !isNaN(Date.parse(shapeAnnotation.modifiedDate))) { dateValue = new Date(Date.parse(shapeAnnotation.modifiedDate)); squareAnnotation.modifiedDate = dateValue; } var commentsDetails = shapeAnnotation.comments; if (commentsDetails.length > 0) { var validIndices = commentsDetails.map(function (detail) { return detail.commentsIndex; }); var _loop_2 = function (j) { var detail = commentsDetails.find(function (d) { return d.commentsIndex === j; }); if (detail && detail.commentStatus === 'ExistingModified') { this_2.updateCommentsCollection(detail, squareAnnotation.comments.at(j), squareAnnotation.bounds); } }; var this_2 = this; // Step 1: Update existing comments for (var j = 0; j < squareAnnotation.comments.count; j++) { _loop_2(j); } // Step 2: Remove comments not present in commentsDetails for (var j = squareAnnotation.comments.count - 1; j >= 0; j--) { if (!validIndices.includes(j)) { squareAnnotation.comments.removeAt(j); } } // Step 3: Add new comments for (var _a = 0, commentsDetails_2 = commentsDetails; _a < commentsDetails_2.length; _a++) { var detail = commentsDetails_2[_a]; if (detail.commentStatus === 'NewlyAdded' && detail.shapeAnnotationType === '') { squareAnnotation.comments.add(this.addCommentsCollection(detail, squareAnnotation.bounds)); } } } var reviewDetails = shapeAnnotation.review; this.updateReviewCollections(squareAnnotation, reviewDetails, squareAnnotation.bounds); if (!isNullOrUndefined(shapeAnnotation.isCloudShape) && shapeAnnotation.isCloudShape) { var borderEffect = squareAnnotation.borderEffect; borderEffect.style = PdfBorderEffectStyle.cloudy; borderEffect.intensity = shapeAnnotation.cloudIntensity; squareAnnotation.borderEffect = borderEffect; var rectDifferences = JSON.parse(shapeAnnotation.rectangleDifference); if (rectDifferences.length > 0) { var rd = this.getRDValues(rectDifferences); squareAnnotation._dictionary.update('RD', rd); } } this.preserveIsLockProperty(shapeAnnotation, squareAnnotation); if (!isNullOrUndefined(shapeAnnotation.customData)) { squareAnnotation.setValues('CustomData', JSON.stringify(shapeAnnotation.customData)); } if (shapeAnnotation.allowedInteractions && shapeAnnotation['allowedInteractions'] != null) { squareAnnotation.setValues('AllowedInteractions', JSON.stringify(shapeAnnotation['allowedInteractions'])); } squareAnnotation.setAppearance(true); squareAnnotation._dictionary._updated = true; } else if (!isNullOrUndefined(shapeAnnotation.shapeAnnotationType) && shapeAnnotation.shapeAnnotationType === 'Circle' && (annotation instanceof PdfCircleAnnotation || annotation instanceof PdfEllipseAnnotation)) { var bounds = JSON.parse(shapeAnnotation.bounds); var left = !isNullOrUndefined(bounds.left) ? this.convertPixelToPoint(bounds.left) : 0; var top_5 = !isNullOrUndefined(bounds.top) ? this.convertPixelToPoint(bounds.top) : 0; var width = !isNullOrUndefined(bounds.width) ? this.convertPixelToPoint(bounds.width) : 0; var height = !isNullOrUndefined(bounds.height) ? this.convertPixelToPoint(bounds.height) : 0; var cropValues = this.getCropBoxValue(page, false); var cropX = 0; var cropY = 0; if (cropValues.x !== 0 && cropValues.y !== 0 && cropValues.x === left) { cropX = cropValues.x; cropY = cropValues.y; } else if (cropValues.x === 0 && page.cropBox[2] === page.size.width && cropValues.y === page.size.height) { cropX = cropValues.x; cropY = cropValues.y; } var circleAnnotation = annotation; var x = cropX + left; var y = cropY + top_5; circleAnnotation.bounds = { x: x, y: y, width: width, height: height }; if (!isNullOrUndefined(shapeAnnotation.note)) { circleAnnotation.text = shapeAnnotation.note.toString(); } circleAnnotation.author = !isNullOrUndefined(shapeAnnotation.author) && shapeAnnotation.author.toString() !== '' ? shapeAnnotation.author.toString() : 'Guest'; circleAnnotation._dictionary.set('NM', shapeAnnotation.annotName.toString()); if (!isNullOrUndefined(shapeAnnotation.subject)) { circleAnnotation.subject = shapeAnnotation.subject.toString(); } if (!isNullOrUndefined(shapeAnnotation.strokeColor)) { var strokeColor = JSON.parse(shapeAnnotation.strokeColor); var color = { r: strokeColor.r, g: strokeColor.g, b: strokeColor.b }; circleAnnotation.color = color; } if (!isNullOrUndefined(shapeAnnotation.fillColor)) { var fillColor = JSON.parse(shapeAnnotation.fillColor); if (!this.isTransparentColor(fillColor)) { var innerColor = { r: fillColor.r, g: fillColor.g, b: fillColor.b }; circleAnnotation.innerColor = innerColor; } if (fillColor.a < 1 && fillColor.a > 0) { circleAnnotation._dictionary.update('FillOpacity', fillColor.a); fillColor.a = 1; } else { circleAnnotation._dictionary.update('FillOpacity', fillColor.a); } } if (!isNullOrUndefined(shapeAnnotation.opacity)) { circleAnnotation.opacity = shapeAnnotation.opacity; } var lineBorder = circleAnnotation.border; lineBorder.width = shapeAnnotation.thickness; lineBorder.style = shapeAnnotation.borderStyle; lineBorder.dash = shapeAnnotation.borderDashArray; circleAnnotation.border = lineBorder; circleAnnotation.rotationAngle = this.getRotateAngle(shapeAnnotation.rotateAngle); var dateValue = void 0; if (!isNullOrUndefined(shapeAnnotation.modifiedDate) && !isNaN(Date.parse(shapeAnnotation.modifiedDate))) { dateValue = new Date(Date.parse(shapeAnnotation.modifiedDate)); circleAnnotation.modifiedDate = dateValue; } var commentsDetails = shapeAnnotation.comments; if (commentsDetails.length > 0) { var validIndices = commentsDetails.map(function (detail) { return detail.commentsIndex; }); var _loop_3 = function (j) { var detail = commentsDetails.find(function (d) { return d.commentsIndex === j; }); if (detail && detail.commentStatus === 'ExistingModified') { this_3.updateCommentsCollection(detail, circleAnnotation.comments.at(j), circleAnnotation.bounds); } }; var this_3 = this; // Step 1: Update existing comments for (var j = 0; j < circleAnnotation.comments.count; j++) { _loop_3(j); } // Step 2: Remove comments not present in commentsDetails for (var j = circleAnnotation.comments.count - 1; j >= 0; j--) { if (!validIndices.includes(j)) { circleAnnotation.comments.removeAt(j); } } // Step 3: Add new comments for (var _b = 0, commentsDetails_3 = commentsDetails; _b < commentsDetails_3.length; _b++) { var detail = comme