nuxeo-development-framework 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19764,6 +19764,7 @@
19764
19764
  */
19765
19765
  var PdftronComponent = /** @class */ (function () {
19766
19766
  function PdftronComponent(cdr, pdftronService, nuxeo, baseHref, securePipe, translationService, environment) {
19767
+ var _this = this;
19767
19768
  this.cdr = cdr;
19768
19769
  this.pdftronService = pdftronService;
19769
19770
  this.nuxeo = nuxeo;
@@ -19774,6 +19775,7 @@
19774
19775
  this.actionClicked = false; // used to know if there is action clicked outside to start edit mode or not
19775
19776
  this.DOCUMENT_TYPE = 'application/pdf';
19776
19777
  this.fitMode = 'FitWidth';
19778
+ this.searchString = ''; // string to search for it in the document
19777
19779
  this.useOutsideAnotations = false; // flage to indicat if using out side anotations or not
19778
19780
  this.onAddingAnotation = new i0.EventEmitter(); // used to export all anotations to outside
19779
19781
  this.events = new i0.EventEmitter();
@@ -19781,6 +19783,55 @@
19781
19783
  this.firstTimeLoad = true; //flage to control importing signatures in the first time load only
19782
19784
  this.firstSignatureLoad = true; // flage to pass first load of imported signatures without emitting the event
19783
19785
  this.newSignCreation = false; // flage to indicate signature creation is created or choosed from stored ones
19786
+ this.savedAnotations = [];
19787
+ this.fileWithOcr = false;
19788
+ this.newAnnotations = [];
19789
+ this.mySearchStringResults = [];
19790
+ this.searchFn = function (searchValue, options) {
19791
+ _this.mySearchStringResults = [];
19792
+ if (_this.savedAnotations.length > 0) {
19793
+ _this.savedAnotations.map(function (annotation) {
19794
+ annotation.Hidden = true;
19795
+ // Always redraw annotation if rendering was updated
19796
+ _this.webViewerInstance.annotManager.redrawAnnotation(annotation);
19797
+ });
19798
+ }
19799
+ // don't do any search until there is a search pattern
19800
+ if (searchValue.trim().length > 0) {
19801
+ if (_this.fileWithOcr) {
19802
+ // add redaction annotation for each search result
19803
+ // const annotation = new Annotations.TextHighlightAnnotation();
19804
+ var mySearch_1 = searchValue.split(' ');
19805
+ if (mySearch_1.length > 1) {
19806
+ // then i am searching with more than one word
19807
+ _this.pages.pages.forEach(function (page, index) {
19808
+ _this.pageHeight = page.page_height;
19809
+ _this.pageWidth = page.page_width;
19810
+ _this.standardHeight = _this.webViewerInstance.docViewer.getPageHeight((index + 1));
19811
+ _this.standardWidth = _this.webViewerInstance.docViewer.getPageWidth((index + 1));
19812
+ page.zones.forEach(function (zone) {
19813
+ zone.paragraphs.forEach(function (paragraph) {
19814
+ paragraph.lines.forEach(function (line) {
19815
+ if (line.text.includes(searchValue)) {
19816
+ _this.SearchForWordInLine(mySearch_1, line, (index + 1), page);
19817
+ }
19818
+ });
19819
+ });
19820
+ });
19821
+ });
19822
+ }
19823
+ else {
19824
+ // then i am searching with only one word
19825
+ _this.searchForWordInAllPages(searchValue);
19826
+ }
19827
+ _this.webViewerInstance.docViewer.clearSearchResults();
19828
+ _this.dispalaySearchResults(_this.webViewerInstance.docViewer);
19829
+ }
19830
+ }
19831
+ else {
19832
+ _this.webViewerInstance.docViewer.clearSearchResults();
19833
+ }
19834
+ };
19784
19835
  }
19785
19836
  PdftronComponent.prototype.ngOnInit = function () {
19786
19837
  return __awaiter(this, void 0, void 0, function () {
@@ -19816,12 +19867,23 @@
19816
19867
  forceClientSideInit: true,
19817
19868
  streaming: true,
19818
19869
  licenseKey: this.environment.pdftronLicenceKey,
19870
+ css: this.isArabic ? (this.baseHref + '/assets/styles/ar-mypdftron.css') : (this.baseHref + '/assets/styles/en-mypdftron.css'),
19819
19871
  annotationUser: this.nuxeo.nuxeoClient.user.properties.firstName + ' ' + this.nuxeo.nuxeoClient.user.properties.lastName,
19820
19872
  disabledElements: ['downloadButton', 'printButton'],
19821
19873
  }, this.viewerRef.nativeElement).then(function (instance) { return __awaiter(_this, void 0, void 0, function () {
19822
19874
  return __generator(this, function (_a) {
19823
19875
  this.isArabic ? instance.setLanguage('ar') : instance.setLanguage('en');
19824
19876
  this.pdftronService.instance = this.webViewerInstance = instance;
19877
+ if (this.correspondance.facets.indexOf('ctocr') > -1) {
19878
+ this.fileWithOcr = true;
19879
+ this.pages = JSON.parse(this.correspondance.properties['ctocr:recognizedJson']);
19880
+ // override search funtion to use our search in ocr not defult search
19881
+ instance.overrideSearchExecution(this.searchFn);
19882
+ }
19883
+ else {
19884
+ // if no ocr then add search lisner to lisne to internal search and catch results
19885
+ this.addSearchListner();
19886
+ }
19825
19887
  this.addPrintButton();
19826
19888
  this.addDownloadButton();
19827
19889
  this.importSignature();
@@ -19832,6 +19894,14 @@
19832
19894
  this.importAnotationsFromOutside();
19833
19895
  this.exportAnotationsToOutside();
19834
19896
  }
19897
+ this.webViewerInstance.docViewer.setSearchHighlightColors({
19898
+ // setSearchHighlightColors accepts both Annotations.Color objects or 'rgba' strings
19899
+ searchResult: new this.webViewerInstance.Annotations.Color(250, 206, 0, 0.50196),
19900
+ activeSearchResult: new this.webViewerInstance.Annotations.Color(250, 206, 0, 0.50196),
19901
+ });
19902
+ if (this.searchString.trim().length !== 0) {
19903
+ this.automaticSearch(this.searchString);
19904
+ }
19835
19905
  this.loadDocument();
19836
19906
  return [2 /*return*/];
19837
19907
  });
@@ -20138,6 +20208,225 @@
20138
20208
  // this[event.action](event.params); // call it
20139
20209
  }
20140
20210
  };
20211
+ // adding search lisner to lisen to internal search from ui and without ocr
20212
+ PdftronComponent.prototype.addSearchListner = function () {
20213
+ var _this = this;
20214
+ var _a = this.webViewerInstance, annotManager = _a.annotManager, docViewer = _a.docViewer, Annotations = _a.Annotations;
20215
+ var searchListener = function (searchPattern, options, results) {
20216
+ var _a;
20217
+ _this.mySearchStringResults = [];
20218
+ if (_this.savedAnotations.length > 0) {
20219
+ _this.savedAnotations.map(function (annotation) {
20220
+ annotation.Hidden = true;
20221
+ // Always redraw annotation if rendering was updated
20222
+ annotManager.redrawAnnotation(annotation);
20223
+ });
20224
+ }
20225
+ // don't do any search until there is a search pattern
20226
+ if (searchPattern.trim().length > 0) {
20227
+ // add redaction annotation for each search result
20228
+ _this.newAnnotations = results.map(function (result) {
20229
+ var annotation = new Annotations.TextHighlightAnnotation();
20230
+ annotation.Quads = result.quads.map(function (quad) { return quad.getPoints(); });
20231
+ annotation.PageNumber = result.pageNum;
20232
+ annotation.StrokeColor = new Annotations.Color(250, 206, 0, 0.50196);
20233
+ annotation.Author = _this.webViewerInstance.annotManager.getCurrentUser();
20234
+ return annotation;
20235
+ });
20236
+ (_a = _this.savedAnotations).push.apply(_a, __spreadArray([], __read(_this.newAnnotations)));
20237
+ annotManager.addAnnotations(_this.newAnnotations);
20238
+ annotManager.drawAnnotationsFromList(_this.newAnnotations);
20239
+ }
20240
+ else {
20241
+ docViewer.clearSearchResults();
20242
+ }
20243
+ };
20244
+ docViewer.on('documentLoaded', function () {
20245
+ _this.webViewerInstance.addSearchListener(searchListener);
20246
+ });
20247
+ };
20248
+ // perform automatic search when intering the page
20249
+ PdftronComponent.prototype.automaticSearch = function (searchText) {
20250
+ var _this = this;
20251
+ var _a = this.webViewerInstance, annotManager = _a.annotManager, docViewer = _a.docViewer, Annotations = _a.Annotations;
20252
+ var searchOptions;
20253
+ this.webViewerInstance.openElements(['searchPanel']);
20254
+ docViewer.on('documentLoaded', function () {
20255
+ var mode = _this.webViewerInstance.CoreControls.Search.Mode.PAGE_STOP | _this.webViewerInstance.CoreControls.Search.Mode.HIGHLIGHT | _this.webViewerInstance.CoreControls.Search.Mode.AMBIENT_STRING;
20256
+ _this.mySearchStringResults = []; // empty my search result when starting new search
20257
+ if (_this.fileWithOcr) {
20258
+ // add redaction annotation for each search result
20259
+ var annotation = new Annotations.TextHighlightAnnotation();
20260
+ var mySearch_2 = searchText.split(' ');
20261
+ if (mySearch_2.length > 1) {
20262
+ // then i am searching with more than one word
20263
+ _this.pages.pages.forEach(function (page, index) {
20264
+ _this.pageHeight = page.page_height;
20265
+ _this.pageWidth = page.page_width;
20266
+ _this.standardHeight = _this.webViewerInstance.docViewer.getPageHeight((index + 1));
20267
+ _this.standardWidth = _this.webViewerInstance.docViewer.getPageWidth((index + 1));
20268
+ page.zones.forEach(function (zone) {
20269
+ zone.paragraphs.forEach(function (paragraph) {
20270
+ paragraph.lines.forEach(function (line) {
20271
+ if (line.text.includes(searchText)) {
20272
+ _this.SearchForWordInLine(mySearch_2, line, (index + 1), page);
20273
+ }
20274
+ });
20275
+ });
20276
+ });
20277
+ });
20278
+ }
20279
+ else {
20280
+ // then i am searching with only one word
20281
+ _this.searchForWordInAllPages(searchText);
20282
+ }
20283
+ docViewer.clearSearchResults();
20284
+ _this.dispalaySearchResults(docViewer);
20285
+ }
20286
+ else {
20287
+ searchOptions = {
20288
+ // If true, a search of the entire document will be performed. Otherwise, a single search will be performed.
20289
+ fullSearch: true,
20290
+ // The callback function that is called when the search returns a result.
20291
+ onResult: function (result) {
20292
+ // with 'PAGE_STOP' mode, the callback is invoked after each page has been searched.
20293
+ if (result.resultCode === _this.webViewerInstance.CoreControls.Search.ResultCode.FOUND) {
20294
+ var annotation = new Annotations.TextHighlightAnnotation();
20295
+ annotation.Quads = result.quads.map(function (quad) { return quad.getPoints(); });
20296
+ console.log(annotation.Quads);
20297
+ annotation.PageNumber = result.pageNum;
20298
+ annotation.StrokeColor = new Annotations.Color(250, 206, 0, 0.50196);
20299
+ annotation.Author = _this.webViewerInstance.annotManager.getCurrentUser();
20300
+ _this.savedAnotations.push(annotation);
20301
+ annotManager.addAnnotations([annotation]);
20302
+ annotManager.drawAnnotationsFromList([annotation]);
20303
+ docViewer.displayAdditionalSearchResults([result]);
20304
+ }
20305
+ }
20306
+ };
20307
+ docViewer.textSearchInit(searchText, mode, searchOptions);
20308
+ }
20309
+ });
20310
+ };
20311
+ // search for single word in all pages
20312
+ PdftronComponent.prototype.searchForWordInAllPages = function (searchedWord) {
20313
+ var _this = this;
20314
+ this.pages.pages.forEach(function (page, index) {
20315
+ _this.pageHeight = page.page_height;
20316
+ _this.pageWidth = page.page_width;
20317
+ _this.standardHeight = _this.webViewerInstance.docViewer.getPageHeight((index + 1));
20318
+ _this.standardWidth = _this.webViewerInstance.docViewer.getPageWidth((index + 1));
20319
+ var x = (_this.pageWidth / _this.standardWidth); // width ratio
20320
+ var y = (_this.pageHeight / _this.standardHeight); // height ratio
20321
+ page.zones.forEach(function (zone) {
20322
+ zone.paragraphs.forEach(function (paragraph) {
20323
+ paragraph.lines.forEach(function (line) {
20324
+ line.words.forEach(function (word) {
20325
+ if (word.text.includes(searchedWord)) {
20326
+ // annotation.PageNumber = index+1;
20327
+ var quads = [{
20328
+ x1: (word.coordinates.upper_left.x / x),
20329
+ x2: (word.coordinates.bottom_right.x / x),
20330
+ x3: (word.coordinates.bottom_right.x / x),
20331
+ x4: (word.coordinates.upper_left.x / x),
20332
+ y1: (word.coordinates.upper_left.y / y),
20333
+ y2: (word.coordinates.upper_left.y / y),
20334
+ y3: (word.coordinates.bottom_right.y / y),
20335
+ y4: (word.coordinates.bottom_right.y / y),
20336
+ }];
20337
+ _this.higlightText(quads, index + 1);
20338
+ _this.constructSearchResult(searchedWord, index + 1, quads, line.text);
20339
+ }
20340
+ });
20341
+ });
20342
+ });
20343
+ });
20344
+ });
20345
+ };
20346
+ // search for word in single line
20347
+ PdftronComponent.prototype.SearchForWordInLine = function (listOfSearchedWords, line, pagenumber, page) {
20348
+ this.pageHeight = page.page_height;
20349
+ this.pageWidth = page.page_width;
20350
+ this.standardHeight = this.webViewerInstance.docViewer.getPageHeight((pagenumber));
20351
+ this.standardWidth = this.webViewerInstance.docViewer.getPageWidth((pagenumber));
20352
+ var x = (this.pageWidth / this.standardWidth); // width ratio
20353
+ var y = (this.pageHeight / this.standardHeight); // height ratio
20354
+ // find only words related to my search form the line
20355
+ var myFoundedResults = [];
20356
+ var correctResults = [];
20357
+ line.words.forEach(function (word, wordIndex) {
20358
+ if (listOfSearchedWords.indexOf(word.text) > -1) {
20359
+ myFoundedResults.push({ word: word, wordIndex: wordIndex });
20360
+ }
20361
+ });
20362
+ // find only words exist in my search sentence and not single and repeated word
20363
+ myFoundedResults.map(function (result, index) {
20364
+ if ((myFoundedResults[index]['wordIndex'] - 1 === (myFoundedResults[index - 1] && myFoundedResults[index - 1]['wordIndex'])) ||
20365
+ (myFoundedResults[index + 1] && (myFoundedResults[index + 1]['wordIndex'] - 1 === myFoundedResults[index]['wordIndex']))) {
20366
+ correctResults.push(result);
20367
+ }
20368
+ });
20369
+ // highliht these words after eleminating all repeated and related words
20370
+ // must be for loop sp i can control the step in each loop
20371
+ var quads = [];
20372
+ for (var i = 0; i < correctResults.length; (i = i + listOfSearchedWords.length)) {
20373
+ quads.push({
20374
+ x1: (correctResults[((i + listOfSearchedWords.length) - 1)].word.coordinates.upper_left.x / x),
20375
+ x2: (correctResults[i].word.coordinates.bottom_right.x / x),
20376
+ x3: (correctResults[i].word.coordinates.bottom_right.x / x),
20377
+ x4: (correctResults[((i + listOfSearchedWords.length) - 1)].word.coordinates.upper_left.x / x),
20378
+ y1: (correctResults[i].word.coordinates.upper_left.y / y),
20379
+ y2: (correctResults[((i + listOfSearchedWords.length) - 1)].word.coordinates.upper_left.y / y),
20380
+ y3: (correctResults[((i + listOfSearchedWords.length) - 1)].word.coordinates.bottom_right.y / y),
20381
+ y4: (correctResults[i].word.coordinates.bottom_right.y / y),
20382
+ });
20383
+ this.higlightText(quads, pagenumber);
20384
+ this.constructSearchResult(listOfSearchedWords.join(" "), pagenumber, quads, line.text);
20385
+ }
20386
+ };
20387
+ PdftronComponent.prototype.constructSearchResult = function (searchedText, pageNum, quads, line) {
20388
+ var mySearchStartTextIndex = line.indexOf(searchedText);
20389
+ var mySeearchedTextEndIndex = mySearchStartTextIndex + searchedText.length;
20390
+ var searchResultObject = {
20391
+ ambientStr: line,
20392
+ resultStr: searchedText,
20393
+ resultStrStart: mySearchStartTextIndex,
20394
+ resultStrEnd: mySeearchedTextEndIndex,
20395
+ pageNum: pageNum,
20396
+ resultCode: 2,
20397
+ quads: [{
20398
+ ea: quads[0]['y3'],
20399
+ fa: quads[0]['y4'],
20400
+ ha: quads[0]['x1'],
20401
+ ia: quads[0]['x2'],
20402
+ pB: quads[0]['x3'],
20403
+ qB: quads[0]['x4'],
20404
+ rB: quads[0]['y1'],
20405
+ sB: quads[0]['y2']
20406
+ }]
20407
+ };
20408
+ this.mySearchStringResults.push(searchResultObject);
20409
+ console.log(this.mySearchStringResults);
20410
+ };
20411
+ PdftronComponent.prototype.dispalaySearchResults = function (docViewer) {
20412
+ var _this = this;
20413
+ setTimeout(function () {
20414
+ docViewer.displayAdditionalSearchResults(_this.mySearchStringResults);
20415
+ }, 500);
20416
+ };
20417
+ // draw hiligthing around certain charatacters
20418
+ PdftronComponent.prototype.higlightText = function (quads, pageNumber) {
20419
+ var highlightingAnnot = new this.webViewerInstance.Annotations.TextHighlightAnnotation();
20420
+ highlightingAnnot.StrokeColor = new this.webViewerInstance.Annotations.Color(250, 206, 0, 0.50196);
20421
+ highlightingAnnot.Quads = quads;
20422
+ highlightingAnnot.PageNumber = pageNumber;
20423
+ highlightingAnnot.Author = this.webViewerInstance.annotManager.getCurrentUser();
20424
+ this.savedAnotations.push(highlightingAnnot);
20425
+ this.webViewerInstance.annotManager.addAnnotation(highlightingAnnot);
20426
+ // need to draw the annotation otherwise it won't show up until the page is refreshed
20427
+ this.webViewerInstance.annotManager.redrawAnnotation(highlightingAnnot);
20428
+ };
20429
+ // ------------------------------------------------------------------------ ------------------------------------------
20141
20430
  PdftronComponent.prototype.ngOnDestroy = function () {
20142
20431
  if (this.webViewerInstance) {
20143
20432
  this.webViewerInstance.closeDocument().then(function () {
@@ -20150,7 +20439,7 @@
20150
20439
  return PdftronComponent;
20151
20440
  }());
20152
20441
  PdftronComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.4", ngImport: i0__namespace, type: PdftronComponent, deps: [{ token: i0__namespace.ChangeDetectorRef }, { token: PdftronService }, { token: NuxeoService$1 }, { token: i4.APP_BASE_HREF }, { token: SecurePipe }, { token: TranslationService$1 }, { token: 'environment' }], target: i0__namespace.ɵɵFactoryTarget.Component });
20153
- PdftronComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.4", type: PdftronComponent, selector: "app-pdftron", inputs: { editMode: "editMode", actionClicked: "actionClicked", fileTitle: "fileTitle", docId: "docId", DOCUMENT_TYPE: "DOCUMENT_TYPE", fileData: "fileData", fitMode: "fitMode", authHeader: "authHeader", fileURL: "fileURL", correspondance: "correspondance", secrecyProperty: "secrecyProperty", editingType: "editingType", userSignatures: "userSignatures", useOutsideAnotations: "useOutsideAnotations", importedAnotations: "importedAnotations" }, outputs: { onAddingAnotation: "onAddingAnotation", events: "events", SignatureEvent: "SignatureEvent" }, providers: [SecurePipe], viewQueries: [{ propertyName: "viewerRef", first: true, predicate: ["fileViewer"], descendants: true }], usesOnChanges: true, ngImport: i0__namespace, template: "<div #fileViewer style=\"width: 100%; height: 100%;\"></div>\r\n", styles: [""] });
20442
+ PdftronComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.4", type: PdftronComponent, selector: "app-pdftron", inputs: { editMode: "editMode", actionClicked: "actionClicked", fileTitle: "fileTitle", docId: "docId", DOCUMENT_TYPE: "DOCUMENT_TYPE", fileData: "fileData", fitMode: "fitMode", authHeader: "authHeader", fileURL: "fileURL", correspondance: "correspondance", secrecyProperty: "secrecyProperty", editingType: "editingType", userSignatures: "userSignatures", searchString: "searchString", useOutsideAnotations: "useOutsideAnotations", importedAnotations: "importedAnotations" }, outputs: { onAddingAnotation: "onAddingAnotation", events: "events", SignatureEvent: "SignatureEvent" }, providers: [SecurePipe], viewQueries: [{ propertyName: "viewerRef", first: true, predicate: ["fileViewer"], descendants: true }], usesOnChanges: true, ngImport: i0__namespace, template: "<div #fileViewer style=\"width: 100%; height: 100%;\"></div>\r\n", styles: [""] });
20154
20443
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.4", ngImport: i0__namespace, type: PdftronComponent, decorators: [{
20155
20444
  type: i0.Component,
20156
20445
  args: [{
@@ -20196,6 +20485,8 @@
20196
20485
  type: i0.Input
20197
20486
  }], userSignatures: [{
20198
20487
  type: i0.Input
20488
+ }], searchString: [{
20489
+ type: i0.Input
20199
20490
  }], useOutsideAnotations: [{
20200
20491
  type: i0.Input
20201
20492
  }], importedAnotations: [{