2017-10-06 02:49:59 +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';
|
|
|
|
|
2018-03-16 05:49:28 +09:00
|
|
|
if (!pdfjsLib.getDocument || !pdfjsViewer.PDFSinglePageViewer) {
|
2017-10-06 02:49:59 +09:00
|
|
|
alert('Please build the pdfjs-dist library using\n' +
|
|
|
|
' `gulp dist-install`');
|
|
|
|
}
|
|
|
|
|
|
|
|
// The workerSrc property shall be specified.
|
|
|
|
//
|
2018-03-16 05:49:28 +09:00
|
|
|
pdfjsLib.GlobalWorkerOptions.workerSrc =
|
2018-02-14 22:49:24 +09:00
|
|
|
'../../node_modules/pdfjs-dist/build/pdf.worker.js';
|
2017-10-06 02:49:59 +09:00
|
|
|
|
|
|
|
// Some PDFs need external cmaps.
|
|
|
|
//
|
2018-02-18 00:57:24 +09:00
|
|
|
var CMAP_URL = '../../node_modules/pdfjs-dist/cmaps/';
|
|
|
|
var CMAP_PACKED = true;
|
2017-10-06 02:49:59 +09:00
|
|
|
|
|
|
|
var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf';
|
|
|
|
var SEARCH_FOR = ''; // try 'Mozilla';
|
|
|
|
|
|
|
|
var container = document.getElementById('viewerContainer');
|
|
|
|
|
|
|
|
// (Optionally) enable hyperlinks within PDF files.
|
2018-03-16 05:49:28 +09:00
|
|
|
var pdfLinkService = new pdfjsViewer.PDFLinkService();
|
2017-10-06 02:49:59 +09:00
|
|
|
|
2018-03-16 05:49:28 +09:00
|
|
|
var pdfSinglePageViewer = new pdfjsViewer.PDFSinglePageViewer({
|
2017-10-06 02:49:59 +09:00
|
|
|
container: container,
|
|
|
|
linkService: pdfLinkService,
|
|
|
|
});
|
|
|
|
pdfLinkService.setViewer(pdfSinglePageViewer);
|
|
|
|
|
|
|
|
// (Optionally) enable find controller.
|
2018-03-16 05:49:28 +09:00
|
|
|
var pdfFindController = new pdfjsViewer.PDFFindController({
|
2018-02-18 07:51:24 +09:00
|
|
|
pdfViewer: pdfSinglePageViewer,
|
2017-10-06 02:49:59 +09:00
|
|
|
});
|
|
|
|
pdfSinglePageViewer.setFindController(pdfFindController);
|
|
|
|
|
|
|
|
container.addEventListener('pagesinit', function () {
|
|
|
|
// We can use pdfSinglePageViewer now, e.g. let's change default scale.
|
|
|
|
pdfSinglePageViewer.currentScaleValue = 'page-width';
|
|
|
|
|
|
|
|
if (SEARCH_FOR) { // We can try search for things
|
2018-09-22 00:19:33 +09:00
|
|
|
pdfFindController.executeCommand('find', { query: SEARCH_FOR, });
|
2017-10-06 02:49:59 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Loading document.
|
2018-03-16 05:49:28 +09:00
|
|
|
pdfjsLib.getDocument({
|
2018-02-18 00:57:24 +09:00
|
|
|
url: DEFAULT_URL,
|
|
|
|
cMapUrl: CMAP_URL,
|
|
|
|
cMapPacked: CMAP_PACKED,
|
|
|
|
}).then(function(pdfDocument) {
|
2017-10-06 02:49:59 +09:00
|
|
|
// Document loaded, specifying document for the viewer and
|
|
|
|
// the (optional) linkService.
|
|
|
|
pdfSinglePageViewer.setDocument(pdfDocument);
|
|
|
|
|
|
|
|
pdfLinkService.setDocument(pdfDocument, null);
|
2018-09-22 00:19:33 +09:00
|
|
|
pdfFindController.setDocument(pdfDocument);
|
2017-10-06 02:49:59 +09:00
|
|
|
});
|