@syncfusion/ej2-pdfviewer
Version:
Essential JS 2 PDF viewer Component
860 lines • 248 kB
JavaScript
import { Browser, 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, 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.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']));
}
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']));
}
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']));
}
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));
}
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));
}
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({ x: left, y: top_4, width: labelWidth, height: 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);
var modifiedFontSize = this.convertPixelToPoint(fontSize);
annotation.font = new PdfStandardFont(fontFamily, modifiedFontSize, 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 = { r: color.r, g: color.g, b: color.b };
annotation.borderColor = color1;
var fillColor = JSON.parse(shapeAnnotation.labelFillColor);
var color2 = { r: fillColor.r, g: fillColor.g, b: fillColor.b };
annotation.color = color2;
var textMarkupColor = JSON.parse(shapeAnnotation.fontColor);
var color3 = { r: textMarkupColor.r, g: textMarkupColor.g, b: 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);
}
};
/**
* @param {any} details - details
* @param {PdfPage} page - page
* @param {boolean} canRedact - canRedact
* @private
* @returns {void}
*/
AnnotationRenderer.prototype.addRedact = function (details, page, canRedact) {
var redactionAnnotation = details;
var isLock = this.checkAnnotationLock(redactionAnnotation);
var bounds = JSON.parse(redactionAnnotation.bounds);
var left;
var top;
var width;
var height;
// const bounds: {[key: string]: number}[] = JSON.parse(markupAnnotation.bounds);
var boundsCollection = [];
if (bounds.length > 1) {
for (var i = 0; i < bounds.length; i++) {
var bound = bounds[parseInt(i.toString(), 10)];
var cropValues_1 = this.getCropBoxValue(page, true);
if (!isNullOrUndefined(bound['left']) || !isNullOrUndefined(bound['x'])) {
var left_1 = bound['left'] ? bound['left'] : bound['x'];
var top_5 = bound['top'] ? bound['top'] : bound['y'];
boundsCollection.push(new Rect(cropValues_1.x + this.convertPixelToPoint(left_1), cropValues_1.y + this.convertPixelToPoint(top_5), Object.prototype.hasOwnProperty.call(bound, 'width') ? this.convertPixelToPoint(bound['width']) : 0, Object.prototype.hasOwnProperty.call(bound, 'height') ? this.convertPixelToPoint(bound['height']) : 0));
}
}
left = this.convertPixelToPoint(boundsCollection[0].left);
top = this.convertPixelToPoint(boundsCollection[0].top);
width = this.convertPixelToPoint(boundsCollection[0].width);
height = this.convertPixelToPoint(boundsCollection[0].height);
}
else {
if (isNullOrUndefined(bounds.width)) {
bounds = bounds[0];
}
left = this.convertPixelToPoint(bounds.left);
top = this.convertPixelToPoint(bounds.top);
width = this.convertPixelToPoint(bounds.width);
height = this.convertPixelToPoint(bounds.height);
}
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 redactAnnotation = new PdfRedactionAnnotation({ x: 0, y: 0, width: 0, height: 0 });
if (boundsCollection.length > 0) {
redactAnnotation.bounds = { x: boundsCollection[0].x, y: boundsCollection[0].y,
width: boundsCollection[0].width, height: boundsCollection[0].height };
}
else {
redactAnnotation.bounds = { x: cropX + left, y: cropY + top,
width: width, height: height };
}
if (!isNullOrUndefined(redactionAnnotation.note)) {
redactAnnotation.text = redactionAnnotation.note.toString();
}
redactAnnotation.author = !isNullOrUndefined(redactionAnnotation.author) &&
redactionAnnotation.author.toString() !== '' ? redactionAnnotation.author.toString() : 'Guest';
redactAnnotation._dictionary.set('NM', redactionAnnotation.annotName.toString());
if (!isNullOrUndefined(redactionAnnotation.subject)) {
redactAnnotation.subject = redactionAnnotation.subject.toString();
}
// Redaction-specific properties
redactAnnotation.opacity = canRedact ? 1 : redactionAnnotation.markerOpacity;
if (!isNullOrUndefined(redactionAnnotation.fillColor)) {
var fillColor = JSON.parse(redactionAnnotation.fillColor);
if (!this.isTransparentColor(fillColor)) {
var innerColor = { r: fillColor.r, g: fillColor.g, b: fillColor.b };
redactAnnotation.innerColor = innerColor;
}
if (fillColor.a < 1 && fillColor.a > 0) {
redactAnnotation._dictionary.update('FillOpacity', fillColor.a);
fillColor.a = 1;
}
else {
redactAnnotation._dictionary.update('FillOpacity', fillColor.a);
}
}
if (!isNullOrUndefined(redactionAnnotation.markerFillColor)) {
var markerFillColor = JSON.parse(redactionAnnotation.markerFillColor);
if (!this.isTransparentColor(markerFillColor)) {
var innerColor = { r: markerFillColor.r, g: markerFillColor.g, b: markerFillColor.b };
redactAnnotation.appearanceFillColor = innerColor;
}
if (markerFillColor.a < 1 && markerFillColor.a > 0) {
redactAnnotation._dictionary.update('FillOpacity', markerFillColor.a);
markerFillColor.a = 1;
}
else {
redactAnnotation._dictionary.update('FillOpacity', markerFillColor.a);
}
}
if (!isNullOrUndefined(redactionAnnotation.markerBorderColor) && !canRedact) {
var markerBorderColor = JSON.parse(redactionAnnotation.markerBorderColor);
var color = { r: markerBorderColor.r, g: markerBorderColor.g, b: markerBorderColor.b };
redactAnnotation.borderColor = color;
}
redactAnnotation.overlayText = redactionAnnotation.overlayText + ' ';
redactAnnotation.repeatText = redactionAnnotation.isRepeat;
// Font properties
if (!isNullOrUndefined(redactionAnnotation.fontColor)) {
var fontColor = JSON.parse(redactionAnnotation.fontColor);
var color = { r: fontColor.r, g: fontColor.g, b: fontColor.b };
redactAnnotation.textColor = color;
}
var fontFamily = this.getFontFamily(redactionAnnotation.fontFamily);
redactAnnotation.font = new PdfStandardFont(fontFamily, (redactionAnnotation.fontSize) * 72 / 96);
redactAnnotation.textAlignment = this.getPdfTextAlignment(redactionAnnotation.textAlign.toString().toLowerCase());
var lineBorder = new PdfAnnotationBorder();
lineBorder.width = redactionAnnotation.thickness;
lineBorder.style = redactionAnnotation.borderStyle;
lineBorder.dash = redactionAnnotation.borderDashArray;
redactAnnotation.border = lineBorder;
redactAnnotation.rotationAngle = this.getRotateAngle(redactionAnnotation.rotateAngle);
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_1 = _a.width, height_1 = _a.height;
if (x !== 0 && y !== 0 && width_1 !== 0 && height_1 !== 0) {
boundArrayCollection.push({ x: x, y: y, width: width_1, height: height_1 });
}
}
redactAnnotation.boundsCollection = boundArrayCollection;
}
var dateValue;
if (!isNullOrUndefined(redactionAnnotation.modifiedDate) && !isNaN(Date.parse(redactionAnnotation.modifiedDate))) {
dateValue = new Date(Date.parse(redactionAnnotation.modifiedDate));
redactAnnotation.modifiedDate = dateValue;
}
var commentsDetails = redactionAnnotation.comments;
if (commentsDetails.length > 0) {
for (var i = 0; i < commentsDetails.length; i++) {
redactAnnotation.comments.add(this.addCommentsCollection(commentsDetails[parseInt(i.toString(), 10)], redactAnnotation.bounds));
}
}
var reviewDetails = redactionAnnotation.review;
redactAnnotation.reviewHistory.add(this.addReviewCollections(reviewDetails, redactAnnotation.bounds));
if (!isNullOrUndefined(redactionAnnotation.isCloudShape) && redactionAnnotation.isCloudShape) {
var borderEffect = new PdfBorderEffect();
borderEffect.style = PdfBorderEffectStyle.cloudy;
borderEffect.intensity = redactionAnnotation.cloudIntensity;
var rectDifferences = JSON.parse(redactionAnnotation.rectangleDifference);
if (rectDifferences.length > 0) {
var rd = this.getRDValues(rectDifferences);
redactAnnotation._dictionary.update('RD', rd);
}
}
this.preserveIsLockProperty(redactionAnnotation, redactAnnotation);
if (!isNullOrUndefined(redactionAnnotation.customData)) {
redactAnnotation.setValues('CustomData', JSON.stringify(redactionAnnotation.customData));
}
if (redactionAnnotation.allowedInteractions && redactionAnnotation['allowedInteractions'] != null) {
redactAnnotation.setValues('AllowedInteractions', JSON.stringify(redactionAnnotation['allowedInteractions']));
}
if (!isNullOrUndefined(redactionAnnotation.annotType)) {
redactAnnotation.setValues('RedactionType', (redactionAnnotation.annotType));
}
redactAnnotation.setAppearance(true);
page.annotations.add(redactAnnotation);
};
/**
* @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 = { r: strokeColor.r, g: strokeColor.g, b: 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({ x: val.x, y: val.y }, { x: 0, y: 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({ x: (parseFloat(val['x'].toString())), y: (parseFloat(val['y'].toString())) });
}
var rotatedPoints = this.getRotatedPath(linePoints, rotationAngle);
linePoints = [];
for (var z = 0; z < rotatedPoints._points.length; z += 2) {
linePoints.push({
x: (rotatedPoints._points[parseInt(z.toString(), 10)].x - minimumX) / newDifferenceX + left,
y: page.size.height - (rotatedPoints._points[parseInt(z.toString(), 10)].y - 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;
}
var newX = ((val.y - minimumY) / newDifferenceY);
linePoints.push({ x: ((val.x - minimumX) / newDifferenceX) + left, y: page.size.height - newX - top });
}
}
var colors = { r: inkSignatureAnnotation.color.r, g: inkSignatureAnnotation.color.g,
b: inkSignatureAnnotation.color.b };
var inkAnnotation = new PdfInkAnnotation({ x: left, y: top, width: width, height: height }, linePoints);
var bound = new Rect();
bound = new Rect(inkAnnotation.bounds.x, (page.size.height - (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({ x: val['x'], y: 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({
x: (rotatedPoints._points[parseInt(z.toString(), 10)].x - minimumX) / newDifferenceX + left,
y: page.size.height - (rotatedPoints._points[parseInt(z.toString(), 10)].y - 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 = [];
}
var newX = ((val['y'] - minimumY) / newDifferenceY);
linePoints.push({ x: (val['x'] - minimumX) / newDifferenceX + left, y: page.size.height - 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));