Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for broken search functionality when showPage=false #393

Merged
merged 10 commits into from
Oct 12, 2018
Merged
2 changes: 1 addition & 1 deletion docs/main.41a1d731912219655d31.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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