nuxeo-development-framework 2.0.0 → 2.0.3

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,56 @@
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.recivedSearchStringsArray = [];
19791
+ this.searchFn = function (searchValue, options) {
19792
+ _this.mySearchStringResults = [];
19793
+ if (_this.savedAnotations.length > 0) {
19794
+ _this.savedAnotations.map(function (annotation) {
19795
+ annotation.Hidden = true;
19796
+ // Always redraw annotation if rendering was updated
19797
+ _this.webViewerInstance.annotManager.redrawAnnotation(annotation);
19798
+ });
19799
+ }
19800
+ // don't do any search until there is a search pattern
19801
+ if (searchValue.trim().length > 0) {
19802
+ if (_this.fileWithOcr) {
19803
+ // add redaction annotation for each search result
19804
+ // const annotation = new Annotations.TextHighlightAnnotation();
19805
+ var mySearch_1 = searchValue.split(' ');
19806
+ if (mySearch_1.length > 1) {
19807
+ // then i am searching with more than one word
19808
+ _this.pages.pages.forEach(function (page, index) {
19809
+ _this.pageHeight = page.page_height;
19810
+ _this.pageWidth = page.page_width;
19811
+ _this.standardHeight = _this.webViewerInstance.docViewer.getPageHeight((index + 1));
19812
+ _this.standardWidth = _this.webViewerInstance.docViewer.getPageWidth((index + 1));
19813
+ page.zones.forEach(function (zone) {
19814
+ zone.paragraphs.forEach(function (paragraph) {
19815
+ paragraph.lines.forEach(function (line) {
19816
+ if (line.text.includes(searchValue)) {
19817
+ _this.SearchForWordInLine(mySearch_1, line, (index + 1), page);
19818
+ }
19819
+ });
19820
+ });
19821
+ });
19822
+ });
19823
+ }
19824
+ else {
19825
+ // then i am searching with only one word
19826
+ _this.searchForWordInAllPages(searchValue);
19827
+ }
19828
+ _this.webViewerInstance.docViewer.clearSearchResults();
19829
+ _this.dispalaySearchResults(_this.webViewerInstance.docViewer);
19830
+ }
19831
+ }
19832
+ else {
19833
+ _this.webViewerInstance.docViewer.clearSearchResults();
19834
+ }
19835
+ };
19784
19836
  }
19785
19837
  PdftronComponent.prototype.ngOnInit = function () {
19786
19838
  return __awaiter(this, void 0, void 0, function () {
@@ -19797,6 +19849,7 @@
19797
19849
  return __awaiter(this, void 0, void 0, function () {
19798
19850
  var _this = this;
19799
19851
  return __generator(this, function (_a) {
19852
+ this.recivedSearchStringsArray = this.searchString.trim() ? this.searchString.split(',') : [];
19800
19853
  if (this.fileTitle.endsWith('.ppt')) {
19801
19854
  this.DOCUMENT_TYPE = 'application/vnd.ms-powerpoint';
19802
19855
  }
@@ -19816,12 +19869,23 @@
19816
19869
  forceClientSideInit: true,
19817
19870
  streaming: true,
19818
19871
  licenseKey: this.environment.pdftronLicenceKey,
19872
+ css: this.isArabic ? (this.baseHref + '/assets/styles/ar-mypdftron.css') : (this.baseHref + '/assets/styles/en-mypdftron.css'),
19819
19873
  annotationUser: this.nuxeo.nuxeoClient.user.properties.firstName + ' ' + this.nuxeo.nuxeoClient.user.properties.lastName,
19820
19874
  disabledElements: ['downloadButton', 'printButton'],
19821
19875
  }, this.viewerRef.nativeElement).then(function (instance) { return __awaiter(_this, void 0, void 0, function () {
19822
19876
  return __generator(this, function (_a) {
19823
19877
  this.isArabic ? instance.setLanguage('ar') : instance.setLanguage('en');
19824
19878
  this.pdftronService.instance = this.webViewerInstance = instance;
19879
+ if (this.correspondance.facets.indexOf('ctocr') > -1) {
19880
+ this.fileWithOcr = true;
19881
+ this.pages = JSON.parse(this.correspondance.properties['ctocr:recognizedJson']);
19882
+ // override search funtion to use our search in ocr not defult search
19883
+ instance.overrideSearchExecution(this.searchFn);
19884
+ }
19885
+ else {
19886
+ // if no ocr then add search lisner to lisne to internal search and catch results
19887
+ this.addSearchListner();
19888
+ }
19825
19889
  this.addPrintButton();
19826
19890
  this.addDownloadButton();
19827
19891
  this.importSignature();
@@ -19832,6 +19896,14 @@
19832
19896
  this.importAnotationsFromOutside();
19833
19897
  this.exportAnotationsToOutside();
19834
19898
  }
19899
+ this.webViewerInstance.docViewer.setSearchHighlightColors({
19900
+ // setSearchHighlightColors accepts both Annotations.Color objects or 'rgba' strings
19901
+ searchResult: new this.webViewerInstance.Annotations.Color(250, 206, 0, 0.50196),
19902
+ activeSearchResult: new this.webViewerInstance.Annotations.Color(250, 206, 0, 0.50196),
19903
+ });
19904
+ if (this.recivedSearchStringsArray.length !== 0) {
19905
+ this.automaticSearch(this.recivedSearchStringsArray);
19906
+ }
19835
19907
  this.loadDocument();
19836
19908
  return [2 /*return*/];
19837
19909
  });
@@ -20138,6 +20210,229 @@
20138
20210
  // this[event.action](event.params); // call it
20139
20211
  }
20140
20212
  };
20213
+ // adding search lisner to lisen to internal search from ui and without ocr
20214
+ PdftronComponent.prototype.addSearchListner = function () {
20215
+ var _this = this;
20216
+ var _a = this.webViewerInstance, annotManager = _a.annotManager, docViewer = _a.docViewer, Annotations = _a.Annotations;
20217
+ var searchListener = function (searchPattern, options, results) {
20218
+ var _a;
20219
+ _this.mySearchStringResults = [];
20220
+ if (_this.savedAnotations.length > 0) {
20221
+ _this.savedAnotations.map(function (annotation) {
20222
+ annotation.Hidden = true;
20223
+ // Always redraw annotation if rendering was updated
20224
+ annotManager.redrawAnnotation(annotation);
20225
+ });
20226
+ }
20227
+ // don't do any search until there is a search pattern
20228
+ if (searchPattern.trim().length > 0) {
20229
+ // add redaction annotation for each search result
20230
+ _this.newAnnotations = results.map(function (result) {
20231
+ var annotation = new Annotations.TextHighlightAnnotation();
20232
+ annotation.Quads = result.quads.map(function (quad) { return quad.getPoints(); });
20233
+ annotation.PageNumber = result.pageNum;
20234
+ annotation.StrokeColor = new Annotations.Color(250, 206, 0, 0.50196);
20235
+ annotation.Author = _this.webViewerInstance.annotManager.getCurrentUser();
20236
+ return annotation;
20237
+ });
20238
+ (_a = _this.savedAnotations).push.apply(_a, __spreadArray([], __read(_this.newAnnotations)));
20239
+ annotManager.addAnnotations(_this.newAnnotations);
20240
+ annotManager.drawAnnotationsFromList(_this.newAnnotations);
20241
+ }
20242
+ else {
20243
+ docViewer.clearSearchResults();
20244
+ }
20245
+ };
20246
+ docViewer.on('documentLoaded', function () {
20247
+ _this.webViewerInstance.addSearchListener(searchListener);
20248
+ });
20249
+ };
20250
+ // perform automatic search when intering the page
20251
+ PdftronComponent.prototype.automaticSearch = function (searchTextArray) {
20252
+ var _this = this;
20253
+ var _a = this.webViewerInstance, annotManager = _a.annotManager, docViewer = _a.docViewer, Annotations = _a.Annotations;
20254
+ var searchOptions;
20255
+ this.webViewerInstance.openElements(['searchPanel']);
20256
+ docViewer.on('documentLoaded', function () {
20257
+ var mode = _this.webViewerInstance.CoreControls.Search.Mode.PAGE_STOP | _this.webViewerInstance.CoreControls.Search.Mode.HIGHLIGHT | _this.webViewerInstance.CoreControls.Search.Mode.AMBIENT_STRING;
20258
+ _this.mySearchStringResults = []; // empty my search result when starting new search
20259
+ if (_this.fileWithOcr) {
20260
+ // add redaction annotation for each search result
20261
+ var annotation = new Annotations.TextHighlightAnnotation();
20262
+ searchTextArray.map(function (searchText) {
20263
+ var mySearch = searchText.split(' ');
20264
+ if (mySearch.length > 1) {
20265
+ // then i am searching with more than one word
20266
+ _this.pages.pages.forEach(function (page, index) {
20267
+ _this.pageHeight = page.page_height;
20268
+ _this.pageWidth = page.page_width;
20269
+ _this.standardHeight = _this.webViewerInstance.docViewer.getPageHeight((index + 1));
20270
+ _this.standardWidth = _this.webViewerInstance.docViewer.getPageWidth((index + 1));
20271
+ page.zones.forEach(function (zone) {
20272
+ zone.paragraphs.forEach(function (paragraph) {
20273
+ paragraph.lines.forEach(function (line) {
20274
+ if (line.text.includes(searchText)) {
20275
+ _this.SearchForWordInLine(mySearch, line, (index + 1), page);
20276
+ }
20277
+ });
20278
+ });
20279
+ });
20280
+ });
20281
+ }
20282
+ else {
20283
+ // then i am searching with only one word
20284
+ _this.searchForWordInAllPages(searchText);
20285
+ }
20286
+ });
20287
+ docViewer.clearSearchResults();
20288
+ _this.dispalaySearchResults(docViewer);
20289
+ }
20290
+ else {
20291
+ searchOptions = {
20292
+ // If true, a search of the entire document will be performed. Otherwise, a single search will be performed.
20293
+ fullSearch: true,
20294
+ // The callback function that is called when the search returns a result.
20295
+ onResult: function (result) {
20296
+ // with 'PAGE_STOP' mode, the callback is invoked after each page has been searched.
20297
+ if (result.resultCode === _this.webViewerInstance.CoreControls.Search.ResultCode.FOUND) {
20298
+ var annotation = new Annotations.TextHighlightAnnotation();
20299
+ annotation.Quads = result.quads.map(function (quad) { return quad.getPoints(); });
20300
+ console.log(annotation.Quads);
20301
+ annotation.PageNumber = result.pageNum;
20302
+ annotation.StrokeColor = new Annotations.Color(250, 206, 0, 0.50196);
20303
+ annotation.Author = _this.webViewerInstance.annotManager.getCurrentUser();
20304
+ _this.savedAnotations.push(annotation);
20305
+ annotManager.addAnnotations([annotation]);
20306
+ annotManager.drawAnnotationsFromList([annotation]);
20307
+ docViewer.displayAdditionalSearchResults([result]);
20308
+ }
20309
+ }
20310
+ };
20311
+ searchTextArray.map(function (searchedText) {
20312
+ docViewer.textSearchInit(searchedText, mode, searchOptions);
20313
+ });
20314
+ }
20315
+ });
20316
+ };
20317
+ // search for single word in all pages
20318
+ PdftronComponent.prototype.searchForWordInAllPages = function (searchedWord) {
20319
+ var _this = this;
20320
+ this.pages.pages.forEach(function (page, index) {
20321
+ _this.pageHeight = page.page_height;
20322
+ _this.pageWidth = page.page_width;
20323
+ _this.standardHeight = _this.webViewerInstance.docViewer.getPageHeight((index + 1));
20324
+ _this.standardWidth = _this.webViewerInstance.docViewer.getPageWidth((index + 1));
20325
+ var x = (_this.pageWidth / _this.standardWidth); // width ratio
20326
+ var y = (_this.pageHeight / _this.standardHeight); // height ratio
20327
+ page.zones.forEach(function (zone) {
20328
+ zone.paragraphs.forEach(function (paragraph) {
20329
+ paragraph.lines.forEach(function (line) {
20330
+ line.words.forEach(function (word) {
20331
+ if (word.text.includes(searchedWord)) {
20332
+ // annotation.PageNumber = index+1;
20333
+ var quads = [{
20334
+ x1: (word.coordinates.upper_left.x / x),
20335
+ x2: (word.coordinates.bottom_right.x / x),
20336
+ x3: (word.coordinates.bottom_right.x / x),
20337
+ x4: (word.coordinates.upper_left.x / x),
20338
+ y1: (word.coordinates.upper_left.y / y),
20339
+ y2: (word.coordinates.upper_left.y / y),
20340
+ y3: (word.coordinates.bottom_right.y / y),
20341
+ y4: (word.coordinates.bottom_right.y / y),
20342
+ }];
20343
+ _this.higlightText(quads, index + 1);
20344
+ _this.constructSearchResult(searchedWord, index + 1, quads, line.text);
20345
+ }
20346
+ });
20347
+ });
20348
+ });
20349
+ });
20350
+ });
20351
+ };
20352
+ // search for word in single line
20353
+ PdftronComponent.prototype.SearchForWordInLine = function (listOfSearchedWords, line, pagenumber, page) {
20354
+ this.pageHeight = page.page_height;
20355
+ this.pageWidth = page.page_width;
20356
+ this.standardHeight = this.webViewerInstance.docViewer.getPageHeight((pagenumber));
20357
+ this.standardWidth = this.webViewerInstance.docViewer.getPageWidth((pagenumber));
20358
+ var x = (this.pageWidth / this.standardWidth); // width ratio
20359
+ var y = (this.pageHeight / this.standardHeight); // height ratio
20360
+ // find only words related to my search form the line
20361
+ var myFoundedResults = [];
20362
+ var correctResults = [];
20363
+ line.words.forEach(function (word, wordIndex) {
20364
+ if (listOfSearchedWords.indexOf(word.text) > -1) {
20365
+ myFoundedResults.push({ word: word, wordIndex: wordIndex });
20366
+ }
20367
+ });
20368
+ // find only words exist in my search sentence and not single and repeated word
20369
+ myFoundedResults.map(function (result, index) {
20370
+ if ((myFoundedResults[index]['wordIndex'] - 1 === (myFoundedResults[index - 1] && myFoundedResults[index - 1]['wordIndex'])) ||
20371
+ (myFoundedResults[index + 1] && (myFoundedResults[index + 1]['wordIndex'] - 1 === myFoundedResults[index]['wordIndex']))) {
20372
+ correctResults.push(result);
20373
+ }
20374
+ });
20375
+ // highliht these words after eleminating all repeated and related words
20376
+ // must be for loop sp i can control the step in each loop
20377
+ var quads = [];
20378
+ for (var i = 0; i < correctResults.length; (i = i + listOfSearchedWords.length)) {
20379
+ quads.push({
20380
+ x1: (correctResults[((i + listOfSearchedWords.length) - 1)].word.coordinates.upper_left.x / x),
20381
+ x2: (correctResults[i].word.coordinates.bottom_right.x / x),
20382
+ x3: (correctResults[i].word.coordinates.bottom_right.x / x),
20383
+ x4: (correctResults[((i + listOfSearchedWords.length) - 1)].word.coordinates.upper_left.x / x),
20384
+ y1: (correctResults[i].word.coordinates.upper_left.y / y),
20385
+ y2: (correctResults[((i + listOfSearchedWords.length) - 1)].word.coordinates.upper_left.y / y),
20386
+ y3: (correctResults[((i + listOfSearchedWords.length) - 1)].word.coordinates.bottom_right.y / y),
20387
+ y4: (correctResults[i].word.coordinates.bottom_right.y / y),
20388
+ });
20389
+ this.higlightText(quads, pagenumber);
20390
+ this.constructSearchResult(listOfSearchedWords.join(" "), pagenumber, quads, line.text);
20391
+ }
20392
+ };
20393
+ PdftronComponent.prototype.constructSearchResult = function (searchedText, pageNum, quads, line) {
20394
+ var mySearchStartTextIndex = line.indexOf(searchedText);
20395
+ var mySeearchedTextEndIndex = mySearchStartTextIndex + searchedText.length;
20396
+ var searchResultObject = {
20397
+ ambientStr: line,
20398
+ resultStr: searchedText,
20399
+ resultStrStart: mySearchStartTextIndex,
20400
+ resultStrEnd: mySeearchedTextEndIndex,
20401
+ pageNum: pageNum,
20402
+ resultCode: 2,
20403
+ quads: [{
20404
+ ea: quads[0]['y3'],
20405
+ fa: quads[0]['y4'],
20406
+ ha: quads[0]['x1'],
20407
+ ia: quads[0]['x2'],
20408
+ pB: quads[0]['x3'],
20409
+ qB: quads[0]['x4'],
20410
+ rB: quads[0]['y1'],
20411
+ sB: quads[0]['y2']
20412
+ }]
20413
+ };
20414
+ this.mySearchStringResults.push(searchResultObject);
20415
+ console.log(this.mySearchStringResults);
20416
+ };
20417
+ PdftronComponent.prototype.dispalaySearchResults = function (docViewer) {
20418
+ var _this = this;
20419
+ setTimeout(function () {
20420
+ docViewer.displayAdditionalSearchResults(_this.mySearchStringResults);
20421
+ }, 500);
20422
+ };
20423
+ // draw hiligthing around certain charatacters
20424
+ PdftronComponent.prototype.higlightText = function (quads, pageNumber) {
20425
+ var highlightingAnnot = new this.webViewerInstance.Annotations.TextHighlightAnnotation();
20426
+ highlightingAnnot.StrokeColor = new this.webViewerInstance.Annotations.Color(250, 206, 0, 0.50196);
20427
+ highlightingAnnot.Quads = quads;
20428
+ highlightingAnnot.PageNumber = pageNumber;
20429
+ highlightingAnnot.Author = this.webViewerInstance.annotManager.getCurrentUser();
20430
+ this.savedAnotations.push(highlightingAnnot);
20431
+ this.webViewerInstance.annotManager.addAnnotation(highlightingAnnot);
20432
+ // need to draw the annotation otherwise it won't show up until the page is refreshed
20433
+ this.webViewerInstance.annotManager.redrawAnnotation(highlightingAnnot);
20434
+ };
20435
+ // ------------------------------------------------------------------------ ------------------------------------------
20141
20436
  PdftronComponent.prototype.ngOnDestroy = function () {
20142
20437
  if (this.webViewerInstance) {
20143
20438
  this.webViewerInstance.closeDocument().then(function () {
@@ -20150,7 +20445,7 @@
20150
20445
  return PdftronComponent;
20151
20446
  }());
20152
20447
  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: [""] });
20448
+ 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
20449
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.4", ngImport: i0__namespace, type: PdftronComponent, decorators: [{
20155
20450
  type: i0.Component,
20156
20451
  args: [{
@@ -20196,6 +20491,8 @@
20196
20491
  type: i0.Input
20197
20492
  }], userSignatures: [{
20198
20493
  type: i0.Input
20494
+ }], searchString: [{
20495
+ type: i0.Input
20199
20496
  }], useOutsideAnotations: [{
20200
20497
  type: i0.Input
20201
20498
  }], importedAnotations: [{