Exposes all functional members via lib exports and use them in viewer.

This commit is contained in:
Yury Delendik 2016-03-28 16:44:27 -05:00
parent 1d12aed5ca
commit 1e3e14e6b2
25 changed files with 174 additions and 102 deletions

View file

@ -140,9 +140,9 @@ function renderPage(div, pdf, pageNumber, callback) {
// In production, the bundled pdf.js shall be used instead of RequireJS.
require.config({paths: {'pdfjs': '../../src'}});
require(['pdfjs/display/api'], function (api) {
require(['pdfjs/display/api', 'pdfjs/display/global'], function (api, global) {
// In production, change this to point to the built `pdf.worker.js` file.
PDFJS.workerSrc = '../../src/worker_loader.js';
global.PDFJS.workerSrc = '../../src/worker_loader.js';
// Fetch the PDF document from the URL using promises.
api.getDocument(pdfWithFormsPath).then(function getPdfForm(pdf) {

View file

@ -2,9 +2,9 @@
// In production, the bundled pdf.js shall be used instead of RequireJS.
require.config({paths: {'pdfjs': '../../src'}});
require(['pdfjs/display/api'], function (api) {
require(['pdfjs/display/api', 'pdfjs/display/global'], function (api, global) {
// In production, change this to point to the built `pdf.worker.js` file.
PDFJS.workerSrc = '../../src/worker_loader.js';
global.PDFJS.workerSrc = '../../src/worker_loader.js';
// Fetch the PDF document from the URL using promises.
api.getDocument('helloworld.pdf').then(function (pdf) {

View file

@ -13,7 +13,7 @@ var fs = require('fs');
global.DOMParser = require('./domparsermock.js').DOMParserMock;
// Run `gulp dist` to generate 'pdfjs-dist' npm package files.
require('../../build/dist');
var pdfjsLib = require('../../build/dist');
// Loading file from file system into typed array
var pdfPath = process.argv[2] || '../../web/compressed.tracemonkey-pldi-09.pdf';
@ -21,7 +21,7 @@ var data = new Uint8Array(fs.readFileSync(pdfPath));
// Will be using promises to load document, pages and misc data instead of
// callback.
PDFJS.getDocument(data).then(function (doc) {
pdfjsLib.getDocument(data).then(function (doc) {
var numPages = doc.numPages;
console.log('# Document Loaded');
console.log('Number of Pages: ' + numPages);

View file

@ -11,7 +11,7 @@ var fs = require('fs');
require('./domstubs.js');
// Run `gulp dist` to generate 'pdfjs-dist' npm package files.
require('../../build/dist');
var pdfjsLib = require('../../build/dist');
// Loading file from file system into typed array
var pdfPath = process.argv[2] || '../../web/compressed.tracemonkey-pldi-09.pdf';
@ -44,7 +44,7 @@ function getFileNameFromPath(path) {
// Will be using promises to load document, pages and misc data instead of
// callback.
PDFJS.getDocument(data).then(function (doc) {
pdfjsLib.getDocument(data).then(function (doc) {
var numPages = doc.numPages;
console.log('# Document Loaded');
console.log('Number of Pages: ' + numPages);
@ -59,7 +59,7 @@ PDFJS.getDocument(data).then(function (doc) {
console.log();
return page.getOperatorList().then(function (opList) {
var svgGfx = new PDFJS.SVGGraphics(page.commonObjs, page.objs);
var svgGfx = new pdfjsLib.SVGGraphics(page.commonObjs, page.objs);
svgGfx.embedFonts = true;
return svgGfx.getSVG(opList, viewport).then(function (svg) {
var svgDump = svg.toString();

View file

@ -9,7 +9,7 @@ var queryParams = query ? JSON.parse('{' + query.split('&').map(function (a) {
var url = queryParams.file || '../../test/pdfs/liveprogramming.pdf';
var scale = +queryParams.scale || 1.5;
function renderDocument(pdf) {
function renderDocument(pdf, svgLib) {
var numPages = pdf.numPages;
// Using promise to fetch the page
@ -37,7 +37,7 @@ function renderDocument(pdf) {
anchor.appendChild(container);
return page.getOperatorList().then(function (opList) {
var svgGfx = new PDFJS.SVGGraphics(page.commonObjs, page.objs);
var svgGfx = new svgLib.SVGGraphics(page.commonObjs, page.objs);
return svgGfx.getSVG(opList, viewport).then(function (svg) {
container.appendChild(svg);
});
@ -49,14 +49,17 @@ function renderDocument(pdf) {
// In production, the bundled pdf.js shall be used instead of RequireJS.
require.config({paths: {'pdfjs': '../../src'}});
require(['pdfjs/display/api', 'pdfjs/display/svg'], function (api, svg) {
require(['pdfjs/display/api', 'pdfjs/display/svg', 'pdfjs/display/global'],
function (api, svg, global) {
// In production, change this to point to the built `pdf.worker.js` file.
PDFJS.workerSrc = '../../src/worker_loader.js';
global.PDFJS.workerSrc = '../../src/worker_loader.js';
// In production, change this to point to where the cMaps are placed.
PDFJS.cMapUrl = '../../external/bcmaps/';
PDFJS.cMapPacked = true;
global.PDFJS.cMapUrl = '../../external/bcmaps/';
global.PDFJS.cMapPacked = true;
// Fetch the PDF document from the URL using promises.
api.getDocument(url).then(renderDocument);
api.getDocument(url).then(function (doc) {
renderDocument(doc, svg);
});
});

View file

@ -3,7 +3,7 @@
// Hello world example for webpack.
require('pdfjs-dist');
var pdfjsLib = require('pdfjs-dist');
var pdfPath = '../helloworld/helloworld.pdf';
@ -11,7 +11,7 @@ var pdfPath = '../helloworld/helloworld.pdf';
// however that might degrade the UI performance in web browsers.
// Loading a document.
var loadingTask = PDFJS.getDocument(pdfPath);
var loadingTask = pdfjsLib.getDocument(pdfPath);
loadingTask.promise.then(function (pdfDocument) {
// Request a first page
return pdfDocument.getPage(1).then(function (pdfPage) {