2014-05-20 08:53:40 +09:00
|
|
|
'use strict';
|
|
|
|
|
2016-10-13 04:13:37 +09:00
|
|
|
var DEFAULT_SCALE = 1.5;
|
|
|
|
|
2014-06-20 12:20:55 +09:00
|
|
|
// 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(',') + '}') : {};
|
|
|
|
|
2016-10-13 04:13:37 +09:00
|
|
|
var url = queryParams.file || '../../web/compressed.tracemonkey-pldi-09.pdf';
|
2014-06-20 12:20:55 +09:00
|
|
|
|
2016-03-29 06:44:27 +09:00
|
|
|
function renderDocument(pdf, svgLib) {
|
2014-05-20 08:53:40 +09:00
|
|
|
var promise = Promise.resolve();
|
2016-10-13 04:13:37 +09:00
|
|
|
for (var i = 1; i <= pdf.numPages; i++) {
|
2014-06-20 12:20:55 +09:00
|
|
|
// Using promise to fetch and render the next page
|
2016-10-13 04:13:37 +09:00
|
|
|
promise = promise.then(function (pageNum) {
|
2014-05-20 08:53:40 +09:00
|
|
|
return pdf.getPage(pageNum).then(function (page) {
|
2016-10-13 04:13:37 +09:00
|
|
|
var viewport = page.getViewport(DEFAULT_SCALE);
|
2014-05-20 08:53:40 +09:00
|
|
|
|
|
|
|
var container = document.createElement('div');
|
|
|
|
container.id = 'pageContainer' + pageNum;
|
|
|
|
container.className = 'pageContainer';
|
|
|
|
container.style.width = viewport.width + 'px';
|
|
|
|
container.style.height = viewport.height + 'px';
|
2016-10-13 04:13:37 +09:00
|
|
|
document.body.appendChild(container);
|
2014-05-20 08:53:40 +09:00
|
|
|
|
2014-06-20 12:20:55 +09:00
|
|
|
return page.getOperatorList().then(function (opList) {
|
2016-03-29 06:44:27 +09:00
|
|
|
var svgGfx = new svgLib.SVGGraphics(page.commonObjs, page.objs);
|
2014-08-15 02:56:11 +09:00
|
|
|
return svgGfx.getSVG(opList, viewport).then(function (svg) {
|
|
|
|
container.appendChild(svg);
|
2014-05-20 08:53:40 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-10-13 04:13:37 +09:00
|
|
|
}.bind(null, i));
|
2014-05-20 08:53:40 +09:00
|
|
|
}
|
2015-12-17 06:03:06 +09:00
|
|
|
}
|
|
|
|
|
2017-05-11 08:28:18 +09:00
|
|
|
Promise.all([System.import('pdfjs/display/api'),
|
|
|
|
System.import('pdfjs/display/svg'),
|
|
|
|
System.import('pdfjs/display/global'),
|
2017-11-10 06:50:39 +09:00
|
|
|
System.import('pdfjs/display/network'),
|
2017-05-11 08:28:18 +09:00
|
|
|
System.resolve('pdfjs/worker_loader')])
|
2017-02-10 00:53:52 +09:00
|
|
|
.then(function (modules) {
|
2017-11-10 06:50:39 +09:00
|
|
|
var api = modules[0], svg = modules[1], global = modules[2], network = modules[3];
|
2018-02-05 03:32:47 +09:00
|
|
|
api.setPDFNetworkStreamFactory((params) => {
|
|
|
|
return new network.PDFNetworkStream(params);
|
|
|
|
});
|
|
|
|
|
2015-12-17 06:03:06 +09:00
|
|
|
// In production, change this to point to the built `pdf.worker.js` file.
|
2017-11-10 06:50:39 +09:00
|
|
|
global.PDFJS.workerSrc = modules[4];
|
2015-12-17 06:03:06 +09:00
|
|
|
|
2016-02-27 06:47:00 +09:00
|
|
|
// In production, change this to point to where the cMaps are placed.
|
2016-03-29 06:44:27 +09:00
|
|
|
global.PDFJS.cMapUrl = '../../external/bcmaps/';
|
|
|
|
global.PDFJS.cMapPacked = true;
|
2016-02-27 06:47:00 +09:00
|
|
|
|
2015-12-17 06:03:06 +09:00
|
|
|
// Fetch the PDF document from the URL using promises.
|
2016-03-29 06:44:27 +09:00
|
|
|
api.getDocument(url).then(function (doc) {
|
|
|
|
renderDocument(doc, svg);
|
|
|
|
});
|
2014-05-20 08:53:40 +09:00
|
|
|
});
|