2014-10-01 02:22:38 +09:00
|
|
|
/* Copyright 2014 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
if (!PDFJS.PDFViewer || !PDFJS.getDocument) {
|
2016-04-29 03:30:03 +09:00
|
|
|
alert('Please build the pdfjs-dist library using\n' +
|
2017-05-11 08:28:18 +09:00
|
|
|
' `gulp dist-install`');
|
2014-10-01 02:22:38 +09:00
|
|
|
}
|
|
|
|
|
2015-11-06 22:39:13 +09:00
|
|
|
// The workerSrc property shall be specified.
|
2014-10-01 02:22:38 +09:00
|
|
|
//
|
2017-05-11 08:28:18 +09:00
|
|
|
PDFJS.workerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.js';
|
2014-10-01 02:22:38 +09:00
|
|
|
|
2014-10-01 05:42:28 +09:00
|
|
|
// Some PDFs need external cmaps.
|
2014-10-01 02:22:38 +09:00
|
|
|
//
|
2017-05-11 08:28:18 +09:00
|
|
|
// PDFJS.cMapUrl = '../../node_modules/pdfjs-dist/cmaps/';
|
2014-10-01 02:22:38 +09:00
|
|
|
// PDFJS.cMapPacked = true;
|
|
|
|
|
|
|
|
var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf';
|
2016-04-14 04:39:29 +09:00
|
|
|
var SEARCH_FOR = ''; // try 'Mozilla';
|
2014-10-01 02:22:38 +09:00
|
|
|
|
2014-10-01 02:31:58 +09:00
|
|
|
var container = document.getElementById('viewerContainer');
|
2015-06-25 19:24:29 +09:00
|
|
|
|
|
|
|
// (Optionally) enable hyperlinks within PDF files.
|
|
|
|
var pdfLinkService = new PDFJS.PDFLinkService();
|
|
|
|
|
2014-10-01 02:22:38 +09:00
|
|
|
var pdfViewer = new PDFJS.PDFViewer({
|
2015-06-25 19:24:29 +09:00
|
|
|
container: container,
|
|
|
|
linkService: pdfLinkService,
|
2014-10-01 02:31:58 +09:00
|
|
|
});
|
2015-06-25 19:24:29 +09:00
|
|
|
pdfLinkService.setViewer(pdfViewer);
|
2014-10-01 02:31:58 +09:00
|
|
|
|
2016-04-14 04:39:29 +09:00
|
|
|
// (Optionally) enable find controller.
|
|
|
|
var pdfFindController = new PDFJS.PDFFindController({
|
|
|
|
pdfViewer: pdfViewer
|
|
|
|
});
|
|
|
|
pdfViewer.setFindController(pdfFindController);
|
|
|
|
|
2014-10-01 02:31:58 +09:00
|
|
|
container.addEventListener('pagesinit', function () {
|
2015-06-25 19:24:29 +09:00
|
|
|
// We can use pdfViewer now, e.g. let's change default scale.
|
2014-10-01 02:31:58 +09:00
|
|
|
pdfViewer.currentScaleValue = 'page-width';
|
2016-04-14 04:39:29 +09:00
|
|
|
|
|
|
|
if (SEARCH_FOR) { // We can try search for things
|
|
|
|
pdfFindController.executeCommand('find', {query: SEARCH_FOR});
|
|
|
|
}
|
2014-10-01 02:22:38 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
// Loading document.
|
|
|
|
PDFJS.getDocument(DEFAULT_URL).then(function (pdfDocument) {
|
2015-06-25 19:24:29 +09:00
|
|
|
// Document loaded, specifying document for the viewer and
|
|
|
|
// the (optional) linkService.
|
2014-10-01 02:22:38 +09:00
|
|
|
pdfViewer.setDocument(pdfDocument);
|
2015-06-25 19:24:29 +09:00
|
|
|
|
|
|
|
pdfLinkService.setDocument(pdfDocument, null);
|
2014-10-01 02:22:38 +09:00
|
|
|
});
|