UNPKG

@syncfusion/ej2-pdfviewer

Version:
875 lines 225 kB
import { isNullOrUndefined } from '@syncfusion/ej2-base'; import { Rect } from '@syncfusion/ej2-drawings'; 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 } 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.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 lineAnnotation = new PdfLineAnnotation(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 = [strokeColor.r, strokeColor.g, 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 = [fillColor.r, fillColor.g, 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'])); } 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[0] && cropValues.y === page.size[1]) { cropX = cropValues.x; cropY = cropValues.y; } var squareAnnotation = new PdfSquareAnnotation(cropX + left, cropY + top_1, width, 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 = [strokeColor.r, strokeColor.g, strokeColor.b]; squareAnnotation.color = color; } if (!isNullOrUndefined(shapeAnnotation.fillColor)) { var fillColor = JSON.parse(shapeAnnotation.fillColor); if (!this.isTransparentColor(fillColor)) { var innerColor = [fillColor.r, fillColor.g, 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'])); } 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[0] && cropValues.y === page.size[1]) { cropX = cropValues.x; cropY = cropValues.y; } var circleAnnotation = new PdfCircleAnnotation(cropX + left, cropY + top_2, width, 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 = [strokeColor.r, strokeColor.g, strokeColor.b]; circleAnnotation.color = color; } if (!isNullOrUndefined(shapeAnnotation.fillColor)) { var fillColor = JSON.parse(shapeAnnotation.fillColor); if (!this.isTransparentColor(fillColor)) { var innerColor = [fillColor.r, fillColor.g, 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'])); } 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 = [strokeColor.r, strokeColor.g, strokeColor.b]; polygonAnnotation.color = color; } if (!isNullOrUndefined(shapeAnnotation.fillColor)) { var fillColor = JSON.parse(shapeAnnotation.fillColor); if (!this.isTransparentColor(fillColor)) { var innerColor = [fillColor.r, fillColor.g, 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)); } 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 = [strokeColor.r, strokeColor.g, strokeColor.b]; polylineAnnotation.color = color; } if (!isNullOrUndefined(shapeAnnotation.fillColor)) { var fillColor = JSON.parse(shapeAnnotation.fillColor); if (!this.isTransparentColor(fillColor)) { var innerColor = [fillColor.r, fillColor.g, 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)); } page.annotations.add(polylineAnnotation); } if (!isNullOrUndefined(shapeAnnotation.enableShapeLabel) && shapeAnnotation.enableShapeLabel) { var labelBounds = JSON.parse(shapeAnnotation.labelBounds.toString()); var left = this.convertPixelToPoint(labelBounds.left); var top_4 = this.convertPixelToPoint(labelBounds.top); if (shapeAnnotation.shapeAnnotationType === 'Line') { top_4 = top_4 - 5; } var labelWidth = this.convertPixelToPoint(labelBounds.width); var labelHeight = this.convertPixelToPoint(labelBounds.height); var annotation = new PdfFreeTextAnnotation(top_4, left, labelWidth, labelHeight); annotation.author = shapeAnnotation.author; var dateValue = void 0; if (!isNullOrUndefined(shapeAnnotation.modifiedDate) && !isNaN(Date.parse(shapeAnnotation.modifiedDate))) { dateValue = new Date(Date.parse(shapeAnnotation.modifiedDate)); annotation.modifiedDate = dateValue; } annotation._dictionary.set('NM', shapeAnnotation.annotName.toString() + 'freeText'); annotation.lineEndingStyle = PdfLineEndingStyle.openArrow; annotation.annotationIntent = PdfAnnotationIntent.freeTextTypeWriter; var fontSize = 0; if (!isNullOrUndefined(shapeAnnotation.fontSize)) { fontSize = parseFloat(shapeAnnotation.fontSize); } fontSize = !isNullOrUndefined(fontSize) && !isNaN(fontSize) && fontSize > 0 ? fontSize : 16; var fontFamily = this.getFontFamily(shapeAnnotation.fontFamily); var fontJson = {}; var fontStyle = this.getFontStyle(fontJson); annotation.font = new PdfStandardFont(fontFamily, this.convertPixelToPoint(fontSize), fontStyle); annotation.subject = 'Text Box'; annotation.text = ''; if (!isNullOrUndefined(shapeAnnotation.labelContent)) { if (shapeAnnotation.labelContent.toString() !== null) { annotation.text = shapeAnnotation.labelContent.toString(); } } annotation.rotationAngle = this.getRotateAngle(shapeAnnotation.rotateAngle); annotation.border = new PdfAnnotationBorder(); if (Object.prototype.hasOwnProperty.call(shapeAnnotation, 'thickness')) { if (!isNullOrUndefined(shapeAnnotation.thickness)) { var thickness = parseInt(shapeAnnotation.thickness.toString(), 10); annotation.border.width = thickness; } } annotation.opacity = 1.0; if (Object.prototype.hasOwnProperty.call(shapeAnnotation, 'opacity')) { if (!isNullOrUndefined(shapeAnnotation.opacity)) { annotation.opacity = parseFloat(shapeAnnotation.opacity); } } var color = JSON.parse(shapeAnnotation.labelBorderColor); var color1 = [color.r, color.g, color.b]; annotation.borderColor = color1; var fillColor = JSON.parse(shapeAnnotation.labelFillColor); var color2 = [fillColor.r, fillColor.g, fillColor.b]; annotation.color = color2; var textMarkupColor = JSON.parse(shapeAnnotation.fontColor); var color3 = [textMarkupColor.r, textMarkupColor.g, textMarkupColor.b]; annotation.textMarkUpColor = color3; var commentsDetails = annotation.comments; if (commentsDetails.length > 0) { for (var i = 0; i < commentsDetails.length; i++) { annotation.comments.add(this.addCommentsCollection(commentsDetails[parseInt(i.toString(), 10)], annotation.bounds)); } } if (!isNullOrUndefined(shapeAnnotation.customData)) { annotation.setValues('CustomData', shapeAnnotation.customData); } page.annotations.add(annotation); } }; /** * @private * @param {any} details - details * @param {PdfPage} page - page * @returns {void} */ AnnotationRenderer.prototype.saveInkSignature = function (details, page) { var inkSignatureAnnotation = details; var bounds = JSON.parse(inkSignatureAnnotation.bounds); var stampObjects = JSON.parse(inkSignatureAnnotation.data.toString()); var rotationAngle = this.getInkRotateAngle(page.rotation.toString()); var left = this.convertPixelToPoint(bounds.x); var top = this.convertPixelToPoint(bounds.y); var width = this.convertPixelToPoint(bounds.width); var height = this.convertPixelToPoint(bounds.height); var opacity = inkSignatureAnnotation.opacity; var thickness = parseInt(inkSignatureAnnotation.thickness.toString(), 10); if (!isNullOrUndefined(inkSignatureAnnotation.strokeColor)) { var strokeColor = JSON.parse(inkSignatureAnnotation.strokeColor); var color = [strokeColor.r, strokeColor.g, strokeColor.b]; inkSignatureAnnotation.color = color; } var minimumX = -1; var minimumY = -1; var maximumX = -1; var maximumY = -1; var drawingPath = new PdfPath(); for (var p = 0; p < stampObjects.length; p++) { var val = stampObjects[parseInt(p.toString(), 10)]; drawingPath.addLine(val.x, val.y, 0, 0); } var rotatedPath = this.getRotatedPathForMinMax(drawingPath._points, rotationAngle); for (var k = 0; k < rotatedPath.points.length; k += 2) { var value = rotatedPath.points[parseInt(k.toString(), 10)]; if (minimumX === -1) { minimumX = value[0]; minimumY = value[1]; maximumX = value[0]; maximumY = value[1]; } else { var point1 = value[0]; var point2 = value[1]; if (minimumX >= point1) { minimumX = point1; } if (minimumY >= point2) { minimumY = point2; } if (maximumX <= point1) { maximumX = point1; } if (maximumY <= point2) { maximumY = point2; } } } var newDifferenceX = (maximumX - minimumX) / width; var newDifferenceY = (maximumY - minimumY) / height; if (newDifferenceX === 0) { newDifferenceX = 1; } else if (newDifferenceY === 0) { newDifferenceY = 1; } var linePoints = []; var isNewValues = 0; if (rotationAngle !== 0) { for (var j = 0; j < stampObjects.length; j++) { var val = stampObjects[parseInt(j.toString(), 10)]; var path = val['command'].toString(); if (path === 'M' && j !== isNewValues) { isNewValues = j; break; } linePoints.push((parseFloat(val['x'].toString()))); linePoints.push((parseFloat(val['y'].toString()))); } var rotatedPoints = this.getRotatedPath(linePoints, rotationAngle); linePoints = []; for (var z = 0; z < rotatedPoints._points.length; z += 2) { linePoints.push((rotatedPoints._points[parseInt(z.toString(), 10)][0] - minimumX) / newDifferenceX + left); linePoints.push(page.size[1] - (rotatedPoints._points[parseInt(z.toString(), 10)][1] - minimumY) / newDifferenceY - top); } } else { for (var j = 0; j < stampObjects.length; j++) { var val = stampObjects[parseInt(j.toString(), 10)]; var path = val['command'].toString(); if (path === 'M' && j !== isNewValues) { isNewValues = j; break; } linePoints.push(((val.x - minimumX) / newDifferenceX) + left); var newX = ((val.y - minimumY) / newDifferenceY); linePoints.push(page.size[1] - newX - top); } } var colors = [inkSignatureAnnotation.color[0], inkSignatureAnnotation.color[1], inkSignatureAnnotation.color[2]]; var inkAnnotation = new PdfInkAnnotation([left, top, width, height], linePoints); var bound = new Rect(); bound = new Rect(inkAnnotation.bounds.x, (page.size[1] - (inkAnnotation.bounds.y + inkAnnotation.bounds.height)), inkAnnotation.bounds.width, inkAnnotation.bounds.height); inkAnnotation.bounds = bound; inkAnnotation.color = colors; linePoints = []; if (isNewValues > 0) { if (rotationAngle !== 0) { var pathCollection = []; for (var i = isNewValues; i < stampObjects.length; i++) { var val = stampObjects[parseInt(i.toString(), 10)]; var path = val['command'].toString(); if (path === 'M' && i !== isNewValues) { pathCollection.push(linePoints); linePoints = []; } linePoints.push(val['x']); linePoints.push(val['y']); } if (linePoints.length > 0) { pathCollection.push(linePoints); } for (var g = 0; g < pathCollection.length; g++) { var graphicsPoints = []; var pointsCollections = pathCollection[parseInt(g.toString(), 10)]; if (pointsCollections.length > 0) { var rotatedPoints = this.getRotatedPath(pointsCollections, rotationAngle); for (var z = 0; z < rotatedPoints._points.length; z += 2) { graphicsPoints.push((rotatedPoints._points[parseInt(z.toString(), 10)][0] - minimumX) / newDifferenceX + left); graphicsPoints.push(page.size[1] - (rotatedPoints._points[parseInt(z.toString(), 10)][1] - minimumY) / newDifferenceY - top); } inkAnnotation.inkPointsCollection.push(graphicsPoints); } graphicsPoints = []; } } else { for (var i = isNewValues; i < stampObjects.length; i++) { var val = stampObjects[parseInt(i.toString(), 10)]; var path = val['command'].toString(); if (path === 'M' && i !== isNewValues) { inkAnnotation.inkPointsCollection.push(linePoints); linePoints = []; } linePoints.push((val['x'] - minimumX) / newDifferenceX + left); var newX = ((val['y'] - minimumY) / newDifferenceY); linePoints.push(page.size[1] - newX - top); } if (linePoints.length > 0) { inkAnnotation.inkPointsCollection.push(linePoints); } } } var isLock = this.checkAnnotationLock(inkSignatureAnnotation); if (isNullOrUndefined(inkSignatureAnnotation.author) || (isNullOrUndefined(inkSignatureAnnotation.author) && inkSignatureAnnotation.author === '')) { inkSignatureAnnotation.author = 'Guest'; } else { inkAnnotation.author = !isNullOrUndefined(inkSignatureAnnotation.author) ? inkSignatureAnnotation.author.toString() !== '' ? inkSignatureAnnotation.author.toString() : 'Guest' : 'Guest'; } if (!isNullOrUndefined(inkSignatureAnnotation.subject) && inkSignatureAnnotation.subject !== '') { inkAnnotation.subject = inkSignatureAnnotation.subject.toString(); } if (!isNullOrUndefined(inkSignatureAnnotation.note)) { inkAnnotation.text = inkSignatureAnnotation.note.toString(); } else if (!isNullOrUndefined(inkSignatureAnnotation.notes)) { inkAnnotation.text = inkSignatureAnnotation.notes.toString(); } var dateValue; if (!isNullOrUndefined(inkSignatureAnnotation.modifiedDate) && !isNaN(Date.parse(inkSignatureAnnotation.modifiedDate))) { dateValue = new Date(Date.parse(inkSignatureAnnotation.modifiedDate)); inkAnnotation.modifiedDate = dateValue; } var reviewDetails = inkSignatureAnnotation.review; inkAnnotation.reviewHistory.add(this.addReviewCollections(reviewDetails, inkAnnotation.bounds)); var commentsDetails = inkSignatureAnnotation.comments; if (commentsDetails.length > 0) { for (var i = 0; i < commentsDetails.length; i++) { inkAnnotation.comments.add(this.addCommentsCollection(commentsDetails[parseInt(i.toString(), 10)], inkAnnotation.bounds)); } } this.preserveIsLockProperty(inkSignatureAnnotation, inkAnnotation); inkAnnotation.border.width = thickness; inkAnnotation.opacity = opacity; inkAnnotation._isEnableControlPoints = false; inkAnnotation._dictionary.set('NM', inkSignatureAnnotation.annotName.toString()); inkAnnotation.rotationAngle = this.getRotateAngle(inkSignatureAnnotation.rotationAngle); if (!isNullOrUndefined(inkSignatureAnnotation.customData)) { inkAnnotation.setValues('CustomData', JSON.stringify(inkSignatureAnnotation.customData)); } inkAnnotation.setAppearance(true); page.annotations.add(inkAnnotation); return inkSignatureAnnotation; }; /** * @private * @param {number[]} linePoints - points * @param {number} rotationAngle - rotateAngle * @returns {PdfPath} - graphicsPath */ AnnotationRenderer.prototype.getRotatedPath = function (linePoints, rotationAngle) { var docPath = this.getRotatedPoints(linePoints, rotationAngle); var graphicsPath = new PdfPath(); for (var j = 0; j < docPath.points.length; j += 2) { graphicsPath.addLine(docPath.points[parseInt(j.toString(), 10)][0], docPath.points[parseInt(j.toString(), 10)][1], docPath.points[parseInt((j + 1).toString(), 10)][0], docPath.points[j + 1][1]); } return graphicsPath; }; AnnotationRenderer.prototype.getRotationMatrix = function (angleInDegrees) { var angleInRadians = angleInDegrees * (Math.PI / 180); var cosTheta = Math.cos(angleInRadians); var sinTheta = Math.sin(angleInRadians); return [ [cosTheta, -sinTheta, 0], [sinTheta, cosTheta, 0], [0, 0, 1] ]; }; AnnotationRenderer.prototype.getRotatedPoints = function (pointsCollection, rotationAngle) { var graphicsPath = new Path(); for (var j = 0; j < pointsCollection.length; j += 2) { graphicsPath.moveTo(pointsCollection[parseInt(j.toString(), 10)], pointsCollection[parseInt((j + 1).toString(), 10)]); graphicsPath.lineTo(0, 0); } var rotationMatrix = this.getRotationMatrix(rotationAngle); graphicsPath.transform(rotationMatrix); return graphicsPath; }; /** * Rotates a path based on the provided points collection and rotation angle. * @param {number[]} pointsCollection - The collection of points to be rotated. * @param {number} rotationAngle - The angle to rotate the points, in degrees. * @returns {Path} - The rotated graphics path. * @private */ AnnotationRenderer.prototype.getRotatedPathForMinMax = function (pointsCollection, rotationAngle) { var graphicsPath = new Path(); for (var j = 0; j < pointsCollection.length; j += 2) { graphicsPath.moveTo(pointsCollection[parseInt(j.toString(), 10)][0], pointsCollection[parseInt(j.toString(), 10)][1]); graphicsPath.lineTo(pointsCollection[parseInt((j + 1).toString(), 10)][0], pointsCollection[parseInt((j + 1).toString(), 10)][1]); } var rotationMatrix = this.getRotationMatrix(rotationAngle); graphicsPath.transform(rotationMatrix); return graphicsPath; }; /** * @param {any} details -details * @param {PdfDocument} loadedDocument - loadedDocument * @private * @returns {void} */ AnnotationRenderer.prototype.addTextMarkup = function (details, loadedDocument) { var markupAnnotation = details; var pageNo = parseInt(markupAnnotation['pageNumber'].toString(), 10); var page = loadedDocument.getPage(pageNo); var annotationtypes = new PdfTextMarkupAnnotation(); switch (markupAnnotation.textMarkupAnnotationType.toString()) { case 'Highlight': annotationtypes.textMarkupType = PdfTextMarkupAnnotationType.highlight; break; case 'Strikethrough': annotationtypes.textMarkupType = PdfTextMarkupAnnotationType.strikeOut; break; case 'Underline': annotationtypes.textMarkupType = PdfTextMarkupAnnotationType.underline; break; case 'Squiggly': annotationtypes.textMarkupType = PdfTextMarkupAnnotationType.squiggly; break; } var bounds = JSON.parse(markupAnnotation.bounds); var boundsCollection = []; for (var i = 0; i < bounds.length; i++) { var bound = bounds[parseInt(i.toString(), 10)]; var cropValues = this.getCropBoxValue(page, true); if (!isNullOrUndefined(bound['left'])) { boundsCollection.push(new Rect(cropValues.x + this.convertPixelToPoint(bound['left']), cropValues.y + this.convertPixelToPoint(bound['top']), Object.prototype.hasOwnProperty.call(bound, 'width') ? this.convertPixelToPoint(bound['width']) : 0, Object.prototype.hasOwnProperty.call(bound, 'height') ? this.convertPixelToPoint(bound['height']) : 0)); } } var annotation = new PdfTextMarkupAnnotation(null, 0, 0, 0, 0); if (boundsCollection.length > 0) { annotation.bounds = { x: boundsCollection[0].x, y: boundsCollection[0].y, width: boundsCollection[0].width, height: boundsCollection[0].height }; } annotation.textMarkupType = annotationtypes.textMarkupType; var isLock = this.checkAnnotationLock(markupAnnotation); if (isNullOrUndefined(markupAnnotation.author) || (isNullOrUndefined(markupAnnotation.author) && markupAnnotation.author === '')) { markupAnnotation.author = 'Guest'; } else { annotation.author = !isNullOrUndefined(markupAnnotation.author) ? markupAnnotation.author.toString() !== '' ? markupAnnotation.author.toString() : 'Guest' : 'Guest'; } if (!isNullOrUndefined(markupAnnotation.subject) && markupAnnotation.subject !== '') { annotation.subject = markupAnnotation.subject.toString(); } if (!isNullOrUndefined(markupAnnotation.note)) { annotation.text = markupAnnotation.note.toString(); } if (!isNullOrUndefined(markupAnnotation.annotationRotation)) { annotation.rotateAngle = this.getRotateAngle(markupAnnotation.annotationRotation); } var dateValue; if (!isNullOrUndefined(markupAnnotation.modifiedDate) && !isNaN(Date.parse(markupAnnotation.modifiedDate))) { dateValue = new Date(Date.parse(markupAnnotation.modifiedDate)); annotation.modifiedDate = dateValue; } annotation._dictionary.set('NM', markupAnnotation.annotName.toString()); if (!isNullOrUndefined(markupAnnotation.color)) { var annotColor = JSON.parse(markupAnnotation.color); var color = [annotColor.r, annotColor.g, annotColor.b]; annotation.color = color; } if (!isNullOrUndefined(markupAnnotation.opacity)) { annotation.opacity = markupAnnotation.opacity; } if (boundsCollection.length > 0) { // Don't need to set bounds explicitly for text markup annotation var boundArrayCollection = []; for (var i = 0; i < boundsCollection.length; i++) { var _a = boundsCollection[parseInt(i.toString(), 10)], x = _a.x, y = _a.y, width = _a.width, height = _a.height; if (x !== 0 && y !== 0 && width !== 0 && height !== 0) { boundArrayCollection.push([x, y, width, height]); } } annotation.boundsCollection = boundArrayCollection; } var commentsDetails = markupAnnotation.comments; if (commentsDetails.length > 0) { for (var i = 0; i < commentsDetails.length; i++) { annotation.comments.add(this.addCommentsCollection(commentsDetails[parseInt(i.toString(), 10)], annotation.bounds)); } } var reviewDetails = markupAnnotation.review; annotation.reviewHistory.add(this.addReviewCollections(reviewDetails, annotation.bounds)); if (!isNullOrUndefined(markupAnnotation.color)) { var annotColor = JSON.parse(markupAnnotation.color); var color = [annotColor.r, annotColor.g, annotColor.b]; annotation.textMarkUpColor = color; } this.preserveIsLockProperty(markupAnnotation, annotation); if (!isNullOrUndefined(markupAnnotation.customData)) { annotation.setValues('CustomData', JSON.stringify(markupAnnotation.customData)); } if (!isNullOrUndefined(markupAnnotation.allowedInteractions)) { annotation.setValues('AllowedInteractions', JSON.stringify(markupAnnotation.allowedInteractions)); } if (!isNullOrUndefined(markupAnnotation.textMarkupContent)) { annotation._dictionary.set('TextMarkupContent', markupAnnotation.textMarkupContent.toString()); } annotation.setAppearance(true); page.annotations.add(annotation); }; /** * @private * @param {PdfPage} page - page * @param {boolean} isPath - path * @returns {PointBase} - points */ AnnotationRenderer.prototype.getCropBoxValue = function (page, isPat