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.
@@ -18403,6 +18403,7 @@ class PdftronComponent {
18403
18403
  this.actionClicked = false; // used to know if there is action clicked outside to start edit mode or not
18404
18404
  this.DOCUMENT_TYPE = 'application/pdf';
18405
18405
  this.fitMode = 'FitWidth';
18406
+ this.searchString = ''; // string to search for it in the document
18406
18407
  this.useOutsideAnotations = false; // flage to indicat if using out side anotations or not
18407
18408
  this.onAddingAnotation = new EventEmitter(); // used to export all anotations to outside
18408
18409
  this.events = new EventEmitter();
@@ -18410,6 +18411,55 @@ class PdftronComponent {
18410
18411
  this.firstTimeLoad = true; //flage to control importing signatures in the first time load only
18411
18412
  this.firstSignatureLoad = true; // flage to pass first load of imported signatures without emitting the event
18412
18413
  this.newSignCreation = false; // flage to indicate signature creation is created or choosed from stored ones
18414
+ this.savedAnotations = [];
18415
+ this.fileWithOcr = false;
18416
+ this.newAnnotations = [];
18417
+ this.mySearchStringResults = [];
18418
+ this.searchFn = (searchValue, options) => {
18419
+ this.mySearchStringResults = [];
18420
+ if (this.savedAnotations.length > 0) {
18421
+ this.savedAnotations.map(annotation => {
18422
+ annotation.Hidden = true;
18423
+ // Always redraw annotation if rendering was updated
18424
+ this.webViewerInstance.annotManager.redrawAnnotation(annotation);
18425
+ });
18426
+ }
18427
+ // don't do any search until there is a search pattern
18428
+ if (searchValue.trim().length > 0) {
18429
+ if (this.fileWithOcr) {
18430
+ // add redaction annotation for each search result
18431
+ // const annotation = new Annotations.TextHighlightAnnotation();
18432
+ let mySearch = searchValue.split(' ');
18433
+ if (mySearch.length > 1) {
18434
+ // then i am searching with more than one word
18435
+ this.pages.pages.forEach((page, index) => {
18436
+ this.pageHeight = page.page_height;
18437
+ this.pageWidth = page.page_width;
18438
+ this.standardHeight = this.webViewerInstance.docViewer.getPageHeight((index + 1));
18439
+ this.standardWidth = this.webViewerInstance.docViewer.getPageWidth((index + 1));
18440
+ page.zones.forEach(zone => {
18441
+ zone.paragraphs.forEach(paragraph => {
18442
+ paragraph.lines.forEach(line => {
18443
+ if (line.text.includes(searchValue)) {
18444
+ this.SearchForWordInLine(mySearch, line, (index + 1), page);
18445
+ }
18446
+ });
18447
+ });
18448
+ });
18449
+ });
18450
+ }
18451
+ else {
18452
+ // then i am searching with only one word
18453
+ this.searchForWordInAllPages(searchValue);
18454
+ }
18455
+ this.webViewerInstance.docViewer.clearSearchResults();
18456
+ this.dispalaySearchResults(this.webViewerInstance.docViewer);
18457
+ }
18458
+ }
18459
+ else {
18460
+ this.webViewerInstance.docViewer.clearSearchResults();
18461
+ }
18462
+ };
18413
18463
  }
18414
18464
  ngOnInit() {
18415
18465
  return __awaiter(this, void 0, void 0, function* () {
@@ -18439,11 +18489,22 @@ class PdftronComponent {
18439
18489
  forceClientSideInit: true,
18440
18490
  streaming: true,
18441
18491
  licenseKey: this.environment.pdftronLicenceKey,
18492
+ css: this.isArabic ? (this.baseHref + '/assets/styles/ar-mypdftron.css') : (this.baseHref + '/assets/styles/en-mypdftron.css'),
18442
18493
  annotationUser: this.nuxeo.nuxeoClient.user.properties.firstName + ' ' + this.nuxeo.nuxeoClient.user.properties.lastName,
18443
18494
  disabledElements: ['downloadButton', 'printButton'],
18444
18495
  }, this.viewerRef.nativeElement).then((instance) => __awaiter(this, void 0, void 0, function* () {
18445
18496
  this.isArabic ? instance.setLanguage('ar') : instance.setLanguage('en');
18446
18497
  this.pdftronService.instance = this.webViewerInstance = instance;
18498
+ if (this.correspondance.facets.indexOf('ctocr') > -1) {
18499
+ this.fileWithOcr = true;
18500
+ this.pages = JSON.parse(this.correspondance.properties['ctocr:recognizedJson']);
18501
+ // override search funtion to use our search in ocr not defult search
18502
+ instance.overrideSearchExecution(this.searchFn);
18503
+ }
18504
+ else {
18505
+ // if no ocr then add search lisner to lisne to internal search and catch results
18506
+ this.addSearchListner();
18507
+ }
18447
18508
  this.addPrintButton();
18448
18509
  this.addDownloadButton();
18449
18510
  this.importSignature();
@@ -18454,6 +18515,14 @@ class PdftronComponent {
18454
18515
  this.importAnotationsFromOutside();
18455
18516
  this.exportAnotationsToOutside();
18456
18517
  }
18518
+ this.webViewerInstance.docViewer.setSearchHighlightColors({
18519
+ // setSearchHighlightColors accepts both Annotations.Color objects or 'rgba' strings
18520
+ searchResult: new this.webViewerInstance.Annotations.Color(250, 206, 0, 0.50196),
18521
+ activeSearchResult: new this.webViewerInstance.Annotations.Color(250, 206, 0, 0.50196),
18522
+ });
18523
+ if (this.searchString.trim().length !== 0) {
18524
+ this.automaticSearch(this.searchString);
18525
+ }
18457
18526
  this.loadDocument();
18458
18527
  }));
18459
18528
  });
@@ -18745,6 +18814,220 @@ class PdftronComponent {
18745
18814
  // this[event.action](event.params); // call it
18746
18815
  }
18747
18816
  }
18817
+ // adding search lisner to lisen to internal search from ui and without ocr
18818
+ addSearchListner() {
18819
+ const { annotManager, docViewer, Annotations } = this.webViewerInstance;
18820
+ const searchListener = (searchPattern, options, results) => {
18821
+ this.mySearchStringResults = [];
18822
+ if (this.savedAnotations.length > 0) {
18823
+ this.savedAnotations.map(annotation => {
18824
+ annotation.Hidden = true;
18825
+ // Always redraw annotation if rendering was updated
18826
+ annotManager.redrawAnnotation(annotation);
18827
+ });
18828
+ }
18829
+ // don't do any search until there is a search pattern
18830
+ if (searchPattern.trim().length > 0) {
18831
+ // add redaction annotation for each search result
18832
+ this.newAnnotations = results.map(result => {
18833
+ const annotation = new Annotations.TextHighlightAnnotation();
18834
+ annotation.Quads = result.quads.map(quad => quad.getPoints());
18835
+ annotation.PageNumber = result.pageNum;
18836
+ annotation.StrokeColor = new Annotations.Color(250, 206, 0, 0.50196);
18837
+ annotation.Author = this.webViewerInstance.annotManager.getCurrentUser();
18838
+ return annotation;
18839
+ });
18840
+ this.savedAnotations.push(...this.newAnnotations);
18841
+ annotManager.addAnnotations(this.newAnnotations);
18842
+ annotManager.drawAnnotationsFromList(this.newAnnotations);
18843
+ }
18844
+ else {
18845
+ docViewer.clearSearchResults();
18846
+ }
18847
+ };
18848
+ docViewer.on('documentLoaded', () => {
18849
+ this.webViewerInstance.addSearchListener(searchListener);
18850
+ });
18851
+ }
18852
+ // perform automatic search when intering the page
18853
+ automaticSearch(searchText) {
18854
+ const { annotManager, docViewer, Annotations } = this.webViewerInstance;
18855
+ let searchOptions;
18856
+ this.webViewerInstance.openElements(['searchPanel']);
18857
+ docViewer.on('documentLoaded', () => {
18858
+ const mode = this.webViewerInstance.CoreControls.Search.Mode.PAGE_STOP | this.webViewerInstance.CoreControls.Search.Mode.HIGHLIGHT | this.webViewerInstance.CoreControls.Search.Mode.AMBIENT_STRING;
18859
+ this.mySearchStringResults = []; // empty my search result when starting new search
18860
+ if (this.fileWithOcr) {
18861
+ // add redaction annotation for each search result
18862
+ const annotation = new Annotations.TextHighlightAnnotation();
18863
+ let mySearch = searchText.split(' ');
18864
+ if (mySearch.length > 1) {
18865
+ // then i am searching with more than one word
18866
+ this.pages.pages.forEach((page, index) => {
18867
+ this.pageHeight = page.page_height;
18868
+ this.pageWidth = page.page_width;
18869
+ this.standardHeight = this.webViewerInstance.docViewer.getPageHeight((index + 1));
18870
+ this.standardWidth = this.webViewerInstance.docViewer.getPageWidth((index + 1));
18871
+ page.zones.forEach(zone => {
18872
+ zone.paragraphs.forEach(paragraph => {
18873
+ paragraph.lines.forEach(line => {
18874
+ if (line.text.includes(searchText)) {
18875
+ this.SearchForWordInLine(mySearch, line, (index + 1), page);
18876
+ }
18877
+ });
18878
+ });
18879
+ });
18880
+ });
18881
+ }
18882
+ else {
18883
+ // then i am searching with only one word
18884
+ this.searchForWordInAllPages(searchText);
18885
+ }
18886
+ docViewer.clearSearchResults();
18887
+ this.dispalaySearchResults(docViewer);
18888
+ }
18889
+ else {
18890
+ searchOptions = {
18891
+ // If true, a search of the entire document will be performed. Otherwise, a single search will be performed.
18892
+ fullSearch: true,
18893
+ // The callback function that is called when the search returns a result.
18894
+ onResult: result => {
18895
+ // with 'PAGE_STOP' mode, the callback is invoked after each page has been searched.
18896
+ if (result.resultCode === this.webViewerInstance.CoreControls.Search.ResultCode.FOUND) {
18897
+ const annotation = new Annotations.TextHighlightAnnotation();
18898
+ annotation.Quads = result.quads.map(quad => quad.getPoints());
18899
+ console.log(annotation.Quads);
18900
+ annotation.PageNumber = result.pageNum;
18901
+ annotation.StrokeColor = new Annotations.Color(250, 206, 0, 0.50196);
18902
+ annotation.Author = this.webViewerInstance.annotManager.getCurrentUser();
18903
+ this.savedAnotations.push(annotation);
18904
+ annotManager.addAnnotations([annotation]);
18905
+ annotManager.drawAnnotationsFromList([annotation]);
18906
+ docViewer.displayAdditionalSearchResults([result]);
18907
+ }
18908
+ }
18909
+ };
18910
+ docViewer.textSearchInit(searchText, mode, searchOptions);
18911
+ }
18912
+ });
18913
+ }
18914
+ // search for single word in all pages
18915
+ searchForWordInAllPages(searchedWord) {
18916
+ this.pages.pages.forEach((page, index) => {
18917
+ this.pageHeight = page.page_height;
18918
+ this.pageWidth = page.page_width;
18919
+ this.standardHeight = this.webViewerInstance.docViewer.getPageHeight((index + 1));
18920
+ this.standardWidth = this.webViewerInstance.docViewer.getPageWidth((index + 1));
18921
+ const x = (this.pageWidth / this.standardWidth); // width ratio
18922
+ const y = (this.pageHeight / this.standardHeight); // height ratio
18923
+ page.zones.forEach(zone => {
18924
+ zone.paragraphs.forEach(paragraph => {
18925
+ paragraph.lines.forEach(line => {
18926
+ line.words.forEach(word => {
18927
+ if (word.text.includes(searchedWord)) {
18928
+ // annotation.PageNumber = index+1;
18929
+ let quads = [{
18930
+ x1: (word.coordinates.upper_left.x / x),
18931
+ x2: (word.coordinates.bottom_right.x / x),
18932
+ x3: (word.coordinates.bottom_right.x / x),
18933
+ x4: (word.coordinates.upper_left.x / x),
18934
+ y1: (word.coordinates.upper_left.y / y),
18935
+ y2: (word.coordinates.upper_left.y / y),
18936
+ y3: (word.coordinates.bottom_right.y / y),
18937
+ y4: (word.coordinates.bottom_right.y / y),
18938
+ }];
18939
+ this.higlightText(quads, index + 1);
18940
+ this.constructSearchResult(searchedWord, index + 1, quads, line.text);
18941
+ }
18942
+ });
18943
+ });
18944
+ });
18945
+ });
18946
+ });
18947
+ }
18948
+ // search for word in single line
18949
+ SearchForWordInLine(listOfSearchedWords, line, pagenumber, page) {
18950
+ this.pageHeight = page.page_height;
18951
+ this.pageWidth = page.page_width;
18952
+ this.standardHeight = this.webViewerInstance.docViewer.getPageHeight((pagenumber));
18953
+ this.standardWidth = this.webViewerInstance.docViewer.getPageWidth((pagenumber));
18954
+ const x = (this.pageWidth / this.standardWidth); // width ratio
18955
+ const y = (this.pageHeight / this.standardHeight); // height ratio
18956
+ // find only words related to my search form the line
18957
+ let myFoundedResults = [];
18958
+ let correctResults = [];
18959
+ line.words.forEach((word, wordIndex) => {
18960
+ if (listOfSearchedWords.indexOf(word.text) > -1) {
18961
+ myFoundedResults.push({ word: word, wordIndex: wordIndex });
18962
+ }
18963
+ });
18964
+ // find only words exist in my search sentence and not single and repeated word
18965
+ myFoundedResults.map((result, index) => {
18966
+ if ((myFoundedResults[index]['wordIndex'] - 1 === (myFoundedResults[index - 1] && myFoundedResults[index - 1]['wordIndex'])) ||
18967
+ (myFoundedResults[index + 1] && (myFoundedResults[index + 1]['wordIndex'] - 1 === myFoundedResults[index]['wordIndex']))) {
18968
+ correctResults.push(result);
18969
+ }
18970
+ });
18971
+ // highliht these words after eleminating all repeated and related words
18972
+ // must be for loop sp i can control the step in each loop
18973
+ let quads = [];
18974
+ for (let i = 0; i < correctResults.length; (i = i + listOfSearchedWords.length)) {
18975
+ quads.push({
18976
+ x1: (correctResults[((i + listOfSearchedWords.length) - 1)].word.coordinates.upper_left.x / x),
18977
+ x2: (correctResults[i].word.coordinates.bottom_right.x / x),
18978
+ x3: (correctResults[i].word.coordinates.bottom_right.x / x),
18979
+ x4: (correctResults[((i + listOfSearchedWords.length) - 1)].word.coordinates.upper_left.x / x),
18980
+ y1: (correctResults[i].word.coordinates.upper_left.y / y),
18981
+ y2: (correctResults[((i + listOfSearchedWords.length) - 1)].word.coordinates.upper_left.y / y),
18982
+ y3: (correctResults[((i + listOfSearchedWords.length) - 1)].word.coordinates.bottom_right.y / y),
18983
+ y4: (correctResults[i].word.coordinates.bottom_right.y / y),
18984
+ });
18985
+ this.higlightText(quads, pagenumber);
18986
+ this.constructSearchResult(listOfSearchedWords.join(" "), pagenumber, quads, line.text);
18987
+ }
18988
+ }
18989
+ constructSearchResult(searchedText, pageNum, quads, line) {
18990
+ let mySearchStartTextIndex = line.indexOf(searchedText);
18991
+ let mySeearchedTextEndIndex = mySearchStartTextIndex + searchedText.length;
18992
+ let searchResultObject = {
18993
+ ambientStr: line,
18994
+ resultStr: searchedText,
18995
+ resultStrStart: mySearchStartTextIndex,
18996
+ resultStrEnd: mySeearchedTextEndIndex,
18997
+ pageNum: pageNum,
18998
+ resultCode: 2,
18999
+ quads: [{
19000
+ ea: quads[0]['y3'],
19001
+ fa: quads[0]['y4'],
19002
+ ha: quads[0]['x1'],
19003
+ ia: quads[0]['x2'],
19004
+ pB: quads[0]['x3'],
19005
+ qB: quads[0]['x4'],
19006
+ rB: quads[0]['y1'],
19007
+ sB: quads[0]['y2']
19008
+ }]
19009
+ };
19010
+ this.mySearchStringResults.push(searchResultObject);
19011
+ console.log(this.mySearchStringResults);
19012
+ }
19013
+ dispalaySearchResults(docViewer) {
19014
+ setTimeout(() => {
19015
+ docViewer.displayAdditionalSearchResults(this.mySearchStringResults);
19016
+ }, 500);
19017
+ }
19018
+ // draw hiligthing around certain charatacters
19019
+ higlightText(quads, pageNumber) {
19020
+ const highlightingAnnot = new this.webViewerInstance.Annotations.TextHighlightAnnotation();
19021
+ highlightingAnnot.StrokeColor = new this.webViewerInstance.Annotations.Color(250, 206, 0, 0.50196);
19022
+ highlightingAnnot.Quads = quads;
19023
+ highlightingAnnot.PageNumber = pageNumber;
19024
+ highlightingAnnot.Author = this.webViewerInstance.annotManager.getCurrentUser();
19025
+ this.savedAnotations.push(highlightingAnnot);
19026
+ this.webViewerInstance.annotManager.addAnnotation(highlightingAnnot);
19027
+ // need to draw the annotation otherwise it won't show up until the page is refreshed
19028
+ this.webViewerInstance.annotManager.redrawAnnotation(highlightingAnnot);
19029
+ }
19030
+ // ------------------------------------------------------------------------ ------------------------------------------
18748
19031
  ngOnDestroy() {
18749
19032
  if (this.webViewerInstance) {
18750
19033
  this.webViewerInstance.closeDocument().then(() => {
@@ -18756,7 +19039,7 @@ class PdftronComponent {
18756
19039
  }
18757
19040
  }
18758
19041
  PdftronComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.4", ngImport: i0, type: PdftronComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: PdftronService }, { token: NuxeoService$1 }, { token: APP_BASE_HREF }, { token: SecurePipe }, { token: TranslationService$1 }, { token: 'environment' }], target: i0.ɵɵFactoryTarget.Component });
18759
- PdftronComponent.ɵcmp = i0.ɵɵ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, template: "<div #fileViewer style=\"width: 100%; height: 100%;\"></div>\r\n", styles: [""] });
19042
+ PdftronComponent.ɵcmp = i0.ɵɵ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, template: "<div #fileViewer style=\"width: 100%; height: 100%;\"></div>\r\n", styles: [""] });
18760
19043
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.4", ngImport: i0, type: PdftronComponent, decorators: [{
18761
19044
  type: Component,
18762
19045
  args: [{
@@ -18800,6 +19083,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.4", ngImpor
18800
19083
  type: Input
18801
19084
  }], userSignatures: [{
18802
19085
  type: Input
19086
+ }], searchString: [{
19087
+ type: Input
18803
19088
  }], useOutsideAnotations: [{
18804
19089
  type: Input
18805
19090
  }], importedAnotations: [{