pdf.js/examples/components/simpleviewer.js

60 lines
1.9 KiB
JavaScript
Raw Normal View History

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) {
2014-10-01 05:42:28 +09:00
alert('Please build the library and components using\n' +
' `node make generic components`');
2014-10-01 02:22:38 +09:00
}
2014-10-01 05:42:28 +09:00
// In cases when the pdf.worker.js is located at the different folder than the
// pdf.js's one, or the pdf.js is executed via eval(), the workerSrc property
// shall be specified.
2014-10-01 02:22:38 +09:00
//
// PDFJS.workerSrc = '../../build/pdf.worker.js';
2014-10-01 05:42:28 +09:00
// Some PDFs need external cmaps.
2014-10-01 02:22:38 +09:00
//
// PDFJS.cMapUrl = '../../external/bcmaps/';
// PDFJS.cMapPacked = true;
var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf';
2014-10-01 02:31:58 +09:00
var container = document.getElementById('viewerContainer');
// (Optionally) enable hyperlinks within PDF files.
var pdfLinkService = new PDFJS.PDFLinkService();
2014-10-01 02:22:38 +09:00
var pdfViewer = new PDFJS.PDFViewer({
container: container,
linkService: pdfLinkService,
2014-10-01 02:31:58 +09:00
});
pdfLinkService.setViewer(pdfViewer);
2014-10-01 02:31:58 +09:00
container.addEventListener('pagesinit', function () {
// We can use pdfViewer now, e.g. let's change default scale.
2014-10-01 02:31:58 +09:00
pdfViewer.currentScaleValue = 'page-width';
2014-10-01 02:22:38 +09:00
});
// Loading document.
PDFJS.getDocument(DEFAULT_URL).then(function (pdfDocument) {
// Document loaded, specifying document for the viewer and
// the (optional) linkService.
2014-10-01 02:22:38 +09:00
pdfViewer.setDocument(pdfDocument);
pdfLinkService.setDocument(pdfDocument, null);
2014-10-01 02:22:38 +09:00
});