Skip to content

Commit

Permalink
Chore: Document viewer tweaks (#114)
Browse files Browse the repository at this point in the history
- Add comment for why this.pdfViewer.update() is needed in presentation setPage()
- Force enable createObjectURL() in IE11 and iOS Chrome for performance gains
  • Loading branch information
tonyjin authored May 15, 2017
1 parent 27a908a commit 5d0f884
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,10 @@ class DocBaseViewer extends BaseViewer {

// Decrease mobile canvas size to ~3MP (1920x1536)
PDFJS.maxCanvasPixels = this.isMobile ? MOBILE_MAX_CANVAS_SIZE : PDFJS.maxCanvasPixels;

// Do not disable create object URL in IE11 or iOS Chrome - pdf.js issues #3977 and #8081 are
// not applicable to Box's use case and disabling causes performance issues
PDFJS.disableCreateObjectURL = false;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/lib/viewers/doc/PresentationViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class PresentationViewer extends DocBaseViewer {
const pageEl = this.docEl.querySelector(`[data-page-number="${this.pdfViewer.currentPageNumber}"]`);
pageEl.classList.remove(CLASS_INVISIBLE);

// Force page to be rendered - this is needed because the presentation
// DOM layout can trick pdf.js into thinking that this page is not visible
this.pdfViewer.update();
}

Expand Down
5 changes: 5 additions & 0 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,11 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
docBase.setupPdfjs();
expect(PDFJS.maxCanvasPixels).to.equal(MOBILE_MAX_CANVAS_SIZE);
});

it('should set disableCreateObjectURL to false', () => {
docBase.setupPdfjs();
expect(PDFJS.disableCreateObjectURL).to.equal(false);
});
});

describe('initPrint()', () => {
Expand Down

0 comments on commit 5d0f884

Please sign in to comment.