Skip to content

Commit

Permalink
Merge pull request #829 from LAlves91/master
Browse files Browse the repository at this point in the history
feat: upgrade to pdfjs-dist 2.11.338
  • Loading branch information
VadimDez authored Oct 29, 2021
2 parents 7d077c7 + 5c98dbd commit a236403
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
},
"homepage": "https://github.com/VadimDez/ng2-pdf-viewer#readme",
"dependencies": {
"pdfjs-dist": "~2.7.570",
"pdfjs-dist": "~2.11.338",
"tslib": "^2.0.0"
},
"peerDependencies": {
"pdfjs-dist": "~2.7.570"
"pdfjs-dist": "~2.11.338"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.1101.2",
Expand Down
21 changes: 12 additions & 9 deletions src/app/pdf-viewer/pdf-viewer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {
} from '@angular/core';
import { from, fromEvent, Subject } from 'rxjs';
import { debounceTime, filter, takeUntil } from 'rxjs/operators';
import * as PDFJS from 'pdfjs-dist/es5/build/pdf';
import * as PDFJSViewer from 'pdfjs-dist/es5/web/pdf_viewer';
import * as PDFJS from 'pdfjs-dist/legacy/build/pdf';
import * as PDFJSViewer from 'pdfjs-dist/legacy/web/pdf_viewer';

import { createEventBus } from '../utils/event-bus-utils';
import { assign, isSSR } from '../utils/helpers';
Expand All @@ -29,10 +29,11 @@ import type {
PDFProgressData,
PDFDocumentProxy,
PDFDocumentLoadingTask,
PDFViewerOptions
} from './typings';

if (!isSSR()) {
assign(PDFJS, "verbosity", PDFJS.VerbosityLevel.ERRORS);
assign(PDFJS, 'verbosity', PDFJS.VerbosityLevel.INFOS);
}

export enum RenderTextMode {
Expand Down Expand Up @@ -231,10 +232,10 @@ export class PdfViewerComponent
pdfWorkerSrc = (window as any).pdfWorkerSrc;
} else {
pdfWorkerSrc = `https://cdn.jsdelivr.net/npm/pdfjs-dist@${(PDFJS as any).version
}/es5/build/pdf.worker.js`;
}/legacy/build/pdf.worker.js`;
}

assign(PDFJS.GlobalWorkerOptions, "workerSrc", pdfWorkerSrc);
assign(PDFJS.GlobalWorkerOptions, 'workerSrc', pdfWorkerSrc);
}

ngAfterViewChecked(): void {
Expand Down Expand Up @@ -384,7 +385,7 @@ export class PdfViewerComponent
}

private setupMultiPageViewer() {
assign(PDFJS, "disableTextLayer", !this._renderText);
assign(PDFJS, 'disableTextLayer', !this._renderText);

const eventBus = createEventBus(PDFJSViewer, this.destroy$);

Expand Down Expand Up @@ -427,15 +428,17 @@ export class PdfViewerComponent
eventBus
});

const pdfOptions = {
const pdfOptions: PDFViewerOptions = {
eventBus,
container: this.element.nativeElement.querySelector('div'),
removePageBorders: !this._showBorders,
linkService: this.pdfMultiPageLinkService,
textLayerMode: this._renderText
? this._renderTextMode
: RenderTextMode.DISABLED,
findController: this.pdfMultiPageFindController
findController: this.pdfMultiPageFindController,
renderer: 'canvas',
l10n: undefined
};

this.pdfMultiPageViewer = new PDFJSViewer.PDFViewer(pdfOptions);
Expand All @@ -444,7 +447,7 @@ export class PdfViewerComponent
}

private setupSinglePageViewer() {
assign(PDFJS, "disableTextLayer", !this._renderText);
assign(PDFJS, 'disableTextLayer', !this._renderText);

const eventBus = createEventBus(PDFJSViewer, this.destroy$);

Expand Down
9 changes: 5 additions & 4 deletions src/app/pdf-viewer/typings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export type PDFPageProxy = import('pdfjs-dist/types/display/api').PDFPageProxy;
export type PDFSource = import('pdfjs-dist/types/display/api').DocumentInitParameters;
export type PDFDocumentProxy = import('pdfjs-dist/types/display/api').PDFDocumentProxy;
export type PDFDocumentLoadingTask = import('pdfjs-dist/types/display/api').PDFDocumentLoadingTask;
export type PDFPageProxy = import('pdfjs-dist/types/src/display/api').PDFPageProxy;
export type PDFSource = import('pdfjs-dist/types/src/display/api').DocumentInitParameters;
export type PDFDocumentProxy = import('pdfjs-dist/types/src/display/api').PDFDocumentProxy;
export type PDFDocumentLoadingTask = import('pdfjs-dist/types/src/display/api').PDFDocumentLoadingTask;
export type PDFViewerOptions = import('pdfjs-dist/types/web/base_viewer').PDFViewerOptions;

export interface PDFProgressData {
loaded: number;
Expand Down

0 comments on commit a236403

Please sign in to comment.