From 77a38a0974204046de6d88916df202ad29c7fc23 Mon Sep 17 00:00:00 2001 From: Tony Jin Date: Tue, 29 Aug 2017 18:41:29 -0700 Subject: [PATCH] New: Turn on rendering of interactive forms (#349) This enables rendering of content within interactive forms --- src/lib/viewers/doc/DocBaseViewer.js | 5 +-- .../doc/__tests__/DocBaseViewer-test.js | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/lib/viewers/doc/DocBaseViewer.js b/src/lib/viewers/doc/DocBaseViewer.js index 8c43f91cc..edfa7c273 100644 --- a/src/lib/viewers/doc/DocBaseViewer.js +++ b/src/lib/viewers/doc/DocBaseViewer.js @@ -444,12 +444,13 @@ class DocBaseViewer extends BaseViewer { initViewer(pdfUrl) { this.bindDOMListeners(); - // Initialize PDF.js in container + // 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 + enhanceTextSelection: !this.isMobile, + renderInteractiveForms: true }); // Use chunk size set in viewer options if available diff --git a/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js b/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js index 5c49891f5..98aaf9a5e 100644 --- a/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js +++ b/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js @@ -674,6 +674,40 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => { stubs.emit = sandbox.stub(docBase, 'emit'); }); + it('should turn on enhanced text selection if not on mobile and turn on rendering of interactive forms', () => { + docBase.options.location = { + locale: 'en-US' + }; + docBase.isMobile = false; + sandbox.stub(PDFJS, 'getDocument').returns(Promise.resolve({})); + + docBase.initViewer(''); + + expect(stubs.pdfViewerStub).to.be.calledWith({ + container: sinon.match.any, + linkService: sinon.match.any, + enhanceTextSelection: true, + renderInteractiveForms: true + }); + }); + + it('should turn off enhanced text selection if on mobile', () => { + docBase.options.location = { + locale: 'en-US' + }; + docBase.isMobile = true; + sandbox.stub(PDFJS, 'getDocument').returns(Promise.resolve({})); + + docBase.initViewer(''); + + expect(stubs.pdfViewerStub).to.be.calledWith({ + container: sinon.match.any, + linkService: sinon.match.any, + enhanceTextSelection: false, + renderInteractiveForms: true + }); + }); + it('should set a chunk size based on viewer options if available', () => { const url = 'url'; const rangeChunkSize = 100;