Skip to content

Commit

Permalink
Update: Decrease mobile web max pdf.js canvas size to 3MP (#66)
Browse files Browse the repository at this point in the history
- This should help prevent memory issues on mobile web
  • Loading branch information
tonyjin authored Apr 11, 2017
1 parent 82d582e commit 88304c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const MAX_SCALE = 10.0;
const MIN_SCALE = 0.1;
const DEFAULT_RANGE_REQUEST_CHUNK_SIZE = 393216; // 384KB
const LARGE_RANGE_REQUEST_CHUNK_SIZE = 1048576; // 1MB
const MOBILE_MAX_CANVAS_SIZE = 2949120; // ~3MP 1920x1536
const SHOW_PAGE_NUM_INPUT_CLASS = 'show-page-number-input';
const IS_SAFARI_CLASS = 'is-safari';
const SCROLL_EVENT_THROTTLE_INTERVAL = 200;
Expand Down Expand Up @@ -661,6 +662,9 @@ class DocBaseViewer extends BaseViewer {

// Disable text layer if user doesn't have download permissions
PDFJS.disableTextLayer = !checkPermission(file, PERMISSION_DOWNLOAD);

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

/**
Expand Down
8 changes: 7 additions & 1 deletion src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const DEFAULT_SCALE_DELTA = 1.1;
const MAX_SCALE = 10.0;
const MIN_SCALE = 0.1;
const SCROLL_END_TIMEOUT = 500;
const MOBILE_MAX_CANVAS_SIZE = 2949120; // ~3MP 1920x1536

const sandbox = sinon.sandbox.create();
let docBase;
Expand Down Expand Up @@ -1055,7 +1056,6 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {

it('should enable range requests if the file and browser meet the conditions', () => {
stubs.browser.returns('Chrome');

docBase.setupPdfjs();
expect(PDFJS.disableRange).to.be.false;
});
Expand All @@ -1069,6 +1069,12 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
docBase.setupPdfjs();
expect(PDFJS.disableTextLayer).to.be.true;
});

it('should decrease max canvas size to 3MP if on mobile', () => {
sandbox.stub(Browser, 'isMobile').returns(true);
docBase.setupPdfjs();
expect(PDFJS.maxCanvasPixels).to.equal(MOBILE_MAX_CANVAS_SIZE);
});
});

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

0 comments on commit 88304c9

Please sign in to comment.