Skip to content

Commit

Permalink
Merge pull request #393 from AntonioDell/master
Browse files Browse the repository at this point in the history
Fix for broken search functionality when showPage=false
  • Loading branch information
VadimDez authored Oct 12, 2018
2 parents 408b446 + b10ca3a commit 3143ecd
Show file tree
Hide file tree
Showing 5 changed files with 354 additions and 201 deletions.
2 changes: 1 addition & 1 deletion docs/main.41a1d731912219655d31.bundle.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ <h2>Angular 5+ PDF Viewer</h2>
</mat-slide-toggle>
</div>

<div class="mb">
<input #queryInp id="pdfQueryInput" type="text" placeholder="Search" [value]="pdfQuery"
(change)="searchQueryChanged($event.target.value)" (keyup.enter)="searchQueryChanged(queryInp.value)">
</div>

<div class="mb">
<button (click)="incrementZoom(-0.1)" mat-button type="button">
-
Expand Down
30 changes: 23 additions & 7 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* Created by vadimdez on 21/06/16.
*/
import { Component, ViewChild } from '@angular/core';
import { PDFProgressData, PDFDocumentProxy, PDFSource } from './pdf-viewer/pdf-viewer.module';
import {Component, OnChanges, ViewChild} from '@angular/core';
import {PDFProgressData, PDFDocumentProxy, PDFSource} from './pdf-viewer/pdf-viewer.module';

import { PdfViewerComponent } from './pdf-viewer/pdf-viewer.component';
import {PdfViewerComponent} from './pdf-viewer/pdf-viewer.component';

@Component({
moduleId: module.id,
Expand Down Expand Up @@ -41,6 +41,7 @@ export class AppComponent {
fitToPage = false;
outline: any[];
isOutlineShown = false;
pdfQuery = '';

@ViewChild(PdfViewerComponent) private pdfComponent: PdfViewerComponent;

Expand All @@ -53,7 +54,7 @@ export class AppComponent {
xhr.onload = (e: any) => {
console.log(xhr);
if (xhr.status === 200) {
const blob = new Blob([xhr.response], { type: 'application/pdf' });
const blob = new Blob([xhr.response], {type: 'application/pdf'});
this.pdfSrc = URL.createObjectURL(blob);
}
};
Expand Down Expand Up @@ -139,11 +140,11 @@ export class AppComponent {
let newSrc;

if (this.pdfSrc instanceof ArrayBuffer) {
newSrc = { data: this.pdfSrc };
newSrc = {data: this.pdfSrc};
} else if (typeof this.pdfSrc === 'string') {
newSrc = { url: this.pdfSrc };
newSrc = {url: this.pdfSrc};
} else {
newSrc = { ...this.pdfSrc };
newSrc = {...this.pdfSrc};
}

newSrc.password = password;
Expand Down Expand Up @@ -191,4 +192,19 @@ export class AppComponent {
pageRendered(e: CustomEvent) {
console.log('(page-rendered)', e);
}

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
});
}
}
}
Loading

0 comments on commit 3143ecd

Please sign in to comment.