diff --git a/src/lib/viewers/doc/DocBaseViewer.js b/src/lib/viewers/doc/DocBaseViewer.js index 42fd64c82..c9bbba934 100644 --- a/src/lib/viewers/doc/DocBaseViewer.js +++ b/src/lib/viewers/doc/DocBaseViewer.js @@ -497,12 +497,7 @@ class DocBaseViewer extends BaseViewer { this.bindDOMListeners(); // Initialize pdf.js in container - this.pdfViewer = new PDFJS.PDFViewer({ - container: this.docEl, - linkService: new PDFJS.PDFLinkService(), - // Enhanced text selection uses more memory, so disable on mobile - enhanceTextSelection: !this.isMobile - }); + this.pdfViewer = this.initPdfViewer(); // Use chunk size set in viewer options if available let rangeChunkSize = this.getViewerOption('rangeChunkSize'); @@ -558,6 +553,22 @@ class DocBaseViewer extends BaseViewer { }); } + /** + * Initialize pdf.js viewer. + * + * @protected + * @override + * @return {PDFJS.PDFViewer} PDF viewer type + */ + initPdfViewer() { + return new PDFJS.PDFViewer({ + container: this.docEl, + linkService: new PDFJS.PDFLinkService(), + // Enhanced text selection uses more memory, so disable on mobile + enhanceTextSelection: !this.isMobile + }); + } + /** * Re-sizing logic. * diff --git a/src/lib/viewers/doc/DocLoader.js b/src/lib/viewers/doc/DocLoader.js index 895fc2619..a132d10ba 100644 --- a/src/lib/viewers/doc/DocLoader.js +++ b/src/lib/viewers/doc/DocLoader.js @@ -2,6 +2,7 @@ import AssetLoader from '../AssetLoader'; import { getRepresentation } from '../../file'; import DocumentViewer from './DocumentViewer'; import PresentationViewer from './PresentationViewer'; +import SinglePageViewer from './SinglePageViewer'; import RepStatus from '../../RepStatus'; import { ORIGINAL_REP_NAME, STATUS_SUCCESS } from '../../constants'; import { DOCUMENT_EXTENSIONS } from '../../extensions'; @@ -29,6 +30,12 @@ const VIEWERS = [ REP: 'pdf', EXT: DOCUMENT_EXTENSIONS }, + { + NAME: 'SinglePage', + CONSTRUCTOR: SinglePageViewer, + REP: 'pdf', + EXT: DOCUMENT_EXTENSIONS + }, { NAME: 'Document', CONSTRUCTOR: DocumentViewer, @@ -42,6 +49,12 @@ const VIEWERS = [ CONSTRUCTOR: PresentationViewer, REP: ORIGINAL_REP_NAME, EXT: ['pdf', 'lcdpdf'] + }, + { + NAME: 'SinglePage', + CONSTRUCTOR: SinglePageViewer, + REP: ORIGINAL_REP_NAME, + EXT: ['pdf', 'lcdpdf'] } ]; diff --git a/src/lib/viewers/doc/SinglePageViewer.js b/src/lib/viewers/doc/SinglePageViewer.js new file mode 100644 index 000000000..7a21512d7 --- /dev/null +++ b/src/lib/viewers/doc/SinglePageViewer.js @@ -0,0 +1,25 @@ +import DocumentViewer from './DocumentViewer'; + +class SinglePageViewer extends DocumentViewer { + //-------------------------------------------------------------------------- + // Protected + //-------------------------------------------------------------------------- + + /** + * Initialize pdf.js viewer. + * + * @protected + * @override + * @return {PDFJS.PDFViewer} PDF viewer type + */ + initPdfViewer() { + return new PDFJS.PDFSinglePageViewer({ + container: this.docEl, + linkService: new PDFJS.PDFLinkService(), + // Enhanced text selection uses more memory, so disable on mobile + enhanceTextSelection: !this.isMobile + }); + } +} + +export default SinglePageViewer; diff --git a/src/lib/viewers/doc/__tests__/SinglePageViewer-test.html b/src/lib/viewers/doc/__tests__/SinglePageViewer-test.html new file mode 100644 index 000000000..7dd9073c1 --- /dev/null +++ b/src/lib/viewers/doc/__tests__/SinglePageViewer-test.html @@ -0,0 +1 @@ +