Skip to content

Commit

Permalink
Merge pull request #927 from VadimDez/fix/find
Browse files Browse the repository at this point in the history
Fix search
  • Loading branch information
VadimDez authored Sep 11, 2022
2 parents c7bd79f + 68d4136 commit 7e9273e
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 175 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -520,19 +520,19 @@ In your code update `path` to the worker to be for example `/pdf.worker.js`

## Search in the PDF

Use `pdfFindController` for search functionality.
Use `eventBus` for the search functionality.

In your component's ts file:

* Add reference to `pdf-viewer`,
* then when needed execute search()
* Add reference to `pdf-viewer` component,
* then when needed execute `search()` linke this:

```typescript
@ViewChild(PdfViewerComponent) private pdfComponent: PdfViewerComponent;

search(stringToSearch: string) {
this.pdfComponent.pdfFindController.executeCommand('find', {
caseSensitive: false, findPrevious: undefined, highlightAll: true, phraseSearch: true, query: stringToSearch
this.pdfComponent.eventBus.dispatch('find', {
query: stringToSearch, type: 'again', caseSensitive: false, findPrevious: undefined, highlightAll: true, phraseSearch: true
});
}
```
Expand Down
23 changes: 11 additions & 12 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,17 @@ export class AppComponent implements OnInit {
}

searchQueryChanged(newQuery: string) {
if (newQuery !== this.pdfQuery) {
this.pdfQuery = newQuery;
this.pdfComponent.pdfFindController.executeCommand('find', {
query: this.pdfQuery,
highlightAll: true
});
} else {
this.pdfComponent.pdfFindController.executeCommand('findagain', {
query: this.pdfQuery,
highlightAll: true
});
}
const type = newQuery !== this.pdfQuery ? '' : 'again';
this.pdfQuery = newQuery;

this.pdfComponent.eventBus.dispatch('find', {
type,
query: this.pdfQuery,
highlightAll: true,
caseSensitive: false,
phraseSearch: true,
// findPrevious: undefined,
});
}

@HostListener('window:resize', ['$event'])
Expand Down
9 changes: 6 additions & 3 deletions src/app/pdf-viewer/pdf-viewer.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ describe('AppComponent', () => {
expect((pdfViewer as any).getDocumentParams()).toEqual({
url: src,
cMapUrl,
cMapPacked: true
cMapPacked: true,
enableXfa: true
});
});

Expand All @@ -121,7 +122,8 @@ describe('AppComponent', () => {
expect((pdfViewer as any).getDocumentParams()).toEqual({
url: src,
cMapUrl,
cMapPacked: true
cMapPacked: true,
enableXfa: true
});
});

Expand All @@ -133,7 +135,8 @@ describe('AppComponent', () => {
expect((pdfViewer as any).getDocumentParams()).toEqual({
url: srcUrl,
cMapUrl,
cMapPacked: true
cMapPacked: true,
enableXfa: true
});
});
});
Expand Down
Loading

0 comments on commit 7e9273e

Please sign in to comment.