1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Examples: improve SVG viewer

This patch:

- resolves a warning in the console about missing character encoding;
- makes the viewer use the same background color and PDF file as the
  regular viewer;
- simplifies the example to bring it more in line with the other
  examples.
This commit is contained in:
Tim van der Meij 2016-10-12 21:13:37 +02:00
parent 8c5b925547
commit de6c92a96d
2 changed files with 18 additions and 26 deletions

View file

@ -1,40 +1,29 @@
'use strict';
var DEFAULT_SCALE = 1.5;
// Parse query string to extract some parameters (it can fail for some input)
var query = document.location.href.replace(/^[^?]*(\?([^#]*))?(#.*)?/, '$2');
var queryParams = query ? JSON.parse('{' + query.split('&').map(function (a) {
return a.split('=').map(decodeURIComponent).map(JSON.stringify).join(': ');
}).join(',') + '}') : {};
var url = queryParams.file || '../../test/pdfs/liveprogramming.pdf';
var scale = +queryParams.scale || 1.5;
var url = queryParams.file || '../../web/compressed.tracemonkey-pldi-09.pdf';
function renderDocument(pdf, svgLib) {
var numPages = pdf.numPages;
// Using promise to fetch the page
// For testing only.
var MAX_NUM_PAGES = 50;
var ii = Math.min(MAX_NUM_PAGES, numPages);
var promise = Promise.resolve();
for (var i = 1; i <= ii; i++) {
var anchor = document.createElement('a');
anchor.setAttribute('name', 'page=' + i);
anchor.setAttribute('title', 'Page ' + i);
document.body.appendChild(anchor);
for (var i = 1; i <= pdf.numPages; i++) {
// Using promise to fetch and render the next page
promise = promise.then(function (pageNum, anchor) {
promise = promise.then(function (pageNum) {
return pdf.getPage(pageNum).then(function (page) {
var viewport = page.getViewport(scale);
var viewport = page.getViewport(DEFAULT_SCALE);
var container = document.createElement('div');
container.id = 'pageContainer' + pageNum;
container.className = 'pageContainer';
container.style.width = viewport.width + 'px';
container.style.height = viewport.height + 'px';
anchor.appendChild(container);
document.body.appendChild(container);
return page.getOperatorList().then(function (opList) {
var svgGfx = new svgLib.SVGGraphics(page.commonObjs, page.objs);
@ -43,7 +32,7 @@ function renderDocument(pdf, svgLib) {
});
});
});
}.bind(null, i, anchor));
}.bind(null, i));
}
}