1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Use RequireJS in the viewer, examples and tests.

This commit is contained in:
Yury Delendik 2015-12-16 15:03:06 -06:00
parent 05b9d3730a
commit 85e95d34ed
17 changed files with 201 additions and 331 deletions

View file

@ -5,6 +5,9 @@
'use strict';
// Specify the PDF with AcroForm here
var pdfWithFormsPath = '../../test/pdfs/f1040.pdf';
var formFields = {};
function setupForm(div, content, viewport) {
@ -135,16 +138,23 @@ function renderPage(div, pdf, pageNumber, callback) {
});
}
// Fetch the PDF document from the URL using promices
PDFJS.getDocument(pdfWithFormsPath).then(function getPdfForm(pdf) {
// Rendering all pages starting from first
var viewer = document.getElementById('viewer');
var pageNumber = 1;
renderPage(viewer, pdf, pageNumber++, function pageRenderingComplete() {
if (pageNumber > pdf.numPages) {
return; // All pages rendered
}
// Continue rendering of the next page
renderPage(viewer, pdf, pageNumber++, pageRenderingComplete);
// In production, the bundled pdf.js shall be used instead of RequireJS.
require.config({paths: {'pdfjs': '../../src'}});
require(['pdfjs/display/api'], function (api) {
// In production, change this to point to the built `pdf.worker.js` file.
PDFJS.workerSrc = '../../src/worker_loader.js';
// Fetch the PDF document from the URL using promises.
api.getDocument(pdfWithFormsPath).then(function getPdfForm(pdf) {
// Rendering all pages starting from first
var viewer = document.getElementById('viewer');
var pageNumber = 1;
renderPage(viewer, pdf, pageNumber++, function pageRenderingComplete() {
if (pageNumber > pdf.numPages) {
return; // All pages rendered
}
// Continue rendering of the next page
renderPage(viewer, pdf, pageNumber++, pageRenderingComplete);
});
});
});