Misc UI improvements for the SVG Viewer
This commit is contained in:
parent
6258ae61d5
commit
9a28b8a412
@ -7,10 +7,19 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Fetch the PDF document from the URL using promises
|
// Fetch the PDF document from the URL using promises
|
||||||
//
|
//
|
||||||
PDFJS.getDocument('../../test/pdfs/liveprogramming.pdf').then(function(pdf) {
|
PDFJS.getDocument(url).then(function(pdf) {
|
||||||
var numPages = pdf.numPages;
|
var numPages = pdf.numPages;
|
||||||
// Using promise to fetch the page
|
// Using promise to fetch the page
|
||||||
|
|
||||||
@ -20,10 +29,14 @@ PDFJS.getDocument('../../test/pdfs/liveprogramming.pdf').then(function(pdf) {
|
|||||||
|
|
||||||
var promise = Promise.resolve();
|
var promise = Promise.resolve();
|
||||||
for (var i = 1; i <= ii; i++) {
|
for (var i = 1; i <= ii; i++) {
|
||||||
// Using promise to fetch the page
|
var anchor = document.createElement('a');
|
||||||
promise = promise.then(function (pageNum) {
|
anchor.setAttribute('name', 'page=' + i);
|
||||||
|
anchor.setAttribute('title', 'Page ' + i);
|
||||||
|
document.body.appendChild(anchor);
|
||||||
|
|
||||||
|
// Using promise to fetch and render the next page
|
||||||
|
promise = promise.then(function (pageNum, anchor) {
|
||||||
return pdf.getPage(pageNum).then(function (page) {
|
return pdf.getPage(pageNum).then(function (page) {
|
||||||
var scale = 1.5;
|
|
||||||
var viewport = page.getViewport(scale);
|
var viewport = page.getViewport(scale);
|
||||||
|
|
||||||
var container = document.createElement('div');
|
var container = document.createElement('div');
|
||||||
@ -31,25 +44,23 @@ PDFJS.getDocument('../../test/pdfs/liveprogramming.pdf').then(function(pdf) {
|
|||||||
container.className = 'pageContainer';
|
container.className = 'pageContainer';
|
||||||
container.style.width = viewport.width + 'px';
|
container.style.width = viewport.width + 'px';
|
||||||
container.style.height = viewport.height + 'px';
|
container.style.height = viewport.height + 'px';
|
||||||
document.body.appendChild(container);
|
anchor.appendChild(container);
|
||||||
|
|
||||||
var renderContext = {
|
var renderContext = {
|
||||||
viewport: viewport,
|
viewport: viewport,
|
||||||
pageNum: pageNum,
|
pageNum: pageNum,
|
||||||
container: container
|
container: container
|
||||||
};
|
};
|
||||||
// run rendering only when all pages are loaded
|
// the next page fetch will start only after this page rendering is done
|
||||||
promise.then(function () {
|
return page.getOperatorList().then(function (opList) {
|
||||||
page.getOperatorList().then(function (opList) {
|
|
||||||
var svgGfx = new SVGGraphics(page.commonObjs);
|
var svgGfx = new SVGGraphics(page.commonObjs);
|
||||||
svgGfx.loadDependencies(opList).then(function (values) {
|
return svgGfx.loadDependencies(opList).then(function (values) {
|
||||||
svgGfx.beginDrawing(renderContext.viewport, renderContext.pageNum,
|
return svgGfx.beginDrawing(renderContext.viewport,
|
||||||
renderContext.container, opList);
|
renderContext.pageNum, renderContext.container, opList);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
}.bind(null, i, anchor));
|
||||||
}.bind(null, i));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user