Skip to content

Commit 409658f

Browse files
committed
Exposes all functional members via lib exports and use them in viewer.
1 parent 52d8732 commit 409658f

24 files changed

+166
-98
lines changed

examples/acroforms/forms.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ function renderPage(div, pdf, pageNumber, callback) {
140140

141141
// In production, the bundled pdf.js shall be used instead of RequireJS.
142142
require.config({paths: {'pdfjs': '../../src'}});
143-
require(['pdfjs/display/api'], function (api) {
143+
require(['pdfjs/display/api', 'pdfjs/display/global'], function (api, global) {
144144
// In production, change this to point to the built `pdf.worker.js` file.
145-
PDFJS.workerSrc = '../../src/worker_loader.js';
145+
global.PDFJS.workerSrc = '../../src/worker_loader.js';
146146

147147
// Fetch the PDF document from the URL using promises.
148148
api.getDocument(pdfWithFormsPath).then(function getPdfForm(pdf) {

examples/helloworld/hello.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
// In production, the bundled pdf.js shall be used instead of RequireJS.
44
require.config({paths: {'pdfjs': '../../src'}});
5-
require(['pdfjs/display/api'], function (api) {
5+
require(['pdfjs/display/api', 'pdfjs/display/global'], function (api, global) {
66
// In production, change this to point to the built `pdf.worker.js` file.
7-
PDFJS.workerSrc = '../../src/worker_loader.js';
7+
global.PDFJS.workerSrc = '../../src/worker_loader.js';
88

99
// Fetch the PDF document from the URL using promises.
1010
api.getDocument('helloworld.pdf').then(function (pdf) {

examples/node/getinfo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ var fs = require('fs');
1313
global.DOMParser = require('./domparsermock.js').DOMParserMock;
1414

1515
// Run `gulp dist` to generate 'pdfjs-dist' npm package files.
16-
require('../../build/dist');
16+
var pdfjsLib = require('../../build/dist');
1717

1818
// Loading file from file system into typed array
1919
var pdfPath = process.argv[2] || '../../web/compressed.tracemonkey-pldi-09.pdf';
2020
var data = new Uint8Array(fs.readFileSync(pdfPath));
2121

2222
// Will be using promises to load document, pages and misc data instead of
2323
// callback.
24-
PDFJS.getDocument(data).then(function (doc) {
24+
pdfjsLib.getDocument(data).then(function (doc) {
2525
var numPages = doc.numPages;
2626
console.log('# Document Loaded');
2727
console.log('Number of Pages: ' + numPages);

examples/node/pdf2svg.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var fs = require('fs');
1111
require('./domstubs.js');
1212

1313
// Run `gulp dist` to generate 'pdfjs-dist' npm package files.
14-
require('../../build/dist');
14+
var pdfjsLib = require('../../build/dist');
1515

1616
// Loading file from file system into typed array
1717
var pdfPath = process.argv[2] || '../../web/compressed.tracemonkey-pldi-09.pdf';
@@ -44,7 +44,7 @@ function getFileNameFromPath(path) {
4444

4545
// Will be using promises to load document, pages and misc data instead of
4646
// callback.
47-
PDFJS.getDocument(data).then(function (doc) {
47+
pdfjsLib.getDocument(data).then(function (doc) {
4848
var numPages = doc.numPages;
4949
console.log('# Document Loaded');
5050
console.log('Number of Pages: ' + numPages);
@@ -59,7 +59,7 @@ PDFJS.getDocument(data).then(function (doc) {
5959
console.log();
6060

6161
return page.getOperatorList().then(function (opList) {
62-
var svgGfx = new PDFJS.SVGGraphics(page.commonObjs, page.objs);
62+
var svgGfx = new pdfjsLib.SVGGraphics(page.commonObjs, page.objs);
6363
svgGfx.embedFonts = true;
6464
return svgGfx.getSVG(opList, viewport).then(function (svg) {
6565
var svgDump = svg.toString();

examples/svgviewer/viewer.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var queryParams = query ? JSON.parse('{' + query.split('&').map(function (a) {
99
var url = queryParams.file || '../../test/pdfs/liveprogramming.pdf';
1010
var scale = +queryParams.scale || 1.5;
1111

12-
function renderDocument(pdf) {
12+
function renderDocument(pdf, svgLib) {
1313
var numPages = pdf.numPages;
1414
// Using promise to fetch the page
1515

@@ -37,7 +37,7 @@ function renderDocument(pdf) {
3737
anchor.appendChild(container);
3838

3939
return page.getOperatorList().then(function (opList) {
40-
var svgGfx = new PDFJS.SVGGraphics(page.commonObjs, page.objs);
40+
var svgGfx = new svgLib.SVGGraphics(page.commonObjs, page.objs);
4141
return svgGfx.getSVG(opList, viewport).then(function (svg) {
4242
container.appendChild(svg);
4343
});
@@ -49,14 +49,17 @@ function renderDocument(pdf) {
4949

5050
// In production, the bundled pdf.js shall be used instead of RequireJS.
5151
require.config({paths: {'pdfjs': '../../src'}});
52-
require(['pdfjs/display/api', 'pdfjs/display/svg'], function (api, svg) {
52+
require(['pdfjs/display/api', 'pdfjs/display/svg', 'pdfjs/display/global'],
53+
function (api, svg, global) {
5354
// In production, change this to point to the built `pdf.worker.js` file.
54-
PDFJS.workerSrc = '../../src/worker_loader.js';
55+
global.PDFJS.workerSrc = '../../src/worker_loader.js';
5556

5657
// In production, change this to point to where the cMaps are placed.
57-
PDFJS.cMapUrl = '../../external/bcmaps/';
58-
PDFJS.cMapPacked = true;
58+
global.PDFJS.cMapUrl = '../../external/bcmaps/';
59+
global.PDFJS.cMapPacked = true;
5960

6061
// Fetch the PDF document from the URL using promises.
61-
api.getDocument(url).then(renderDocument);
62+
api.getDocument(url).then(function (doc) {
63+
renderDocument(doc, svg);
64+
});
6265
});

examples/webpack/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
// Hello world example for webpack.
55

6-
require('pdfjs-dist');
6+
var pdfjsLib = require('pdfjs-dist');
77

88
var pdfPath = '../helloworld/helloworld.pdf';
99

1010
// It is also possible to disable workers via `PDFJS.disableWorker = true`,
1111
// however that might degrade the UI performance in web browsers.
1212

1313
// Loading a document.
14-
var loadingTask = PDFJS.getDocument(pdfPath);
14+
var loadingTask = pdfjsLib.getDocument(pdfPath);
1515
loadingTask.promise.then(function (pdfDocument) {
1616
// Request a first page
1717
return pdfDocument.getPage(1).then(function (pdfPage) {

src/display/api.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* See the License for the specific language governing permissions and
1313
* limitations under the License.
1414
*/
15-
/* globals pdfjsFilePath */
15+
/* globals pdfjsFilePath, pdfjsVersion, pdfjsBuild */
1616

1717
'use strict';
1818

@@ -2015,6 +2015,13 @@ var _UnsupportedManager = (function UnsupportedManagerClosure() {
20152015
};
20162016
})();
20172017

2018+
if (typeof pdfjsVersion !== 'undefined') {
2019+
exports.version = pdfjsVersion;
2020+
}
2021+
if (typeof pdfjsBuild !== 'undefined') {
2022+
exports.build = pdfjsBuild;
2023+
}
2024+
20182025
exports.getDocument = getDocument;
20192026
exports.PDFDataRangeTransport = PDFDataRangeTransport;
20202027
exports.PDFWorker = PDFWorker;

src/main_loader.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@
4040

4141
// Sync the exports below with ./pdf.js file/template.
4242
exports.PDFJS = displayGlobal.PDFJS;
43-
43+
exports.build = displayAPI.build;
44+
exports.version = displayAPI.version;
4445
exports.getDocument = displayAPI.getDocument;
4546
exports.PDFDataRangeTransport = displayAPI.PDFDataRangeTransport;
47+
exports.PDFWorker = displayAPI.PDFWorker;
4648
exports.renderTextLayer = displayTextLayer.renderTextLayer;
4749
exports.AnnotationLayer = displayAnnotationLayer.AnnotationLayer;
4850
exports.CustomStyle = displayDOMUtils.CustomStyle;
@@ -51,4 +53,14 @@
5153
exports.MissingPDFException = sharedUtil.MissingPDFException;
5254
exports.SVGGraphics = displaySVG.SVGGraphics;
5355
exports.UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
56+
exports.OPS = sharedUtil.OPS;
57+
exports.UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
58+
exports.isValidUrl = sharedUtil.isValidUrl;
59+
exports.createObjectURL = sharedUtil.createObjectURL;
60+
exports.removeNullCharacters = sharedUtil.removeNullCharacters;
61+
exports.shadow = sharedUtil.shadow;
62+
exports.createBlob = sharedUtil.createBlob;
63+
exports.getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
64+
exports.addLinkAttributes = displayDOMUtils.addLinkAttributes;
65+
5466
}));

src/pdf.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@
4545

4646
//#if MAIN_FILE
4747
exports.PDFJS = pdfjsLibs.pdfjsDisplayGlobal.PDFJS;
48+
exports.build = pdfjsLibs.pdfjsDisplayAPI.build;
49+
exports.version = pdfjsLibs.pdfjsDisplayAPI.version;
4850
exports.getDocument = pdfjsLibs.pdfjsDisplayAPI.getDocument;
4951
exports.PDFDataRangeTransport =
5052
pdfjsLibs.pdfjsDisplayAPI.PDFDataRangeTransport;
53+
exports.PDFWorker = pdfjsLibs.pdfjsDisplayAPI.PDFWorker;
5154
exports.renderTextLayer = pdfjsLibs.pdfjsDisplayTextLayer.renderTextLayer;
5255
exports.AnnotationLayer =
5356
pdfjsLibs.pdfjsDisplayAnnotationLayer.AnnotationLayer;
@@ -58,6 +61,16 @@
5861
exports.SVGGraphics = pdfjsLibs.pdfjsDisplaySVG.SVGGraphics;
5962
exports.UnexpectedResponseException =
6063
pdfjsLibs.pdfjsSharedUtil.UnexpectedResponseException;
64+
exports.OPS = pdfjsLibs.pdfjsSharedUtil.OPS;
65+
exports.UNSUPPORTED_FEATURES = pdfjsLibs.pdfjsSharedUtil.UNSUPPORTED_FEATURES;
66+
exports.isValidUrl = pdfjsLibs.pdfjsSharedUtil.isValidUrl;
67+
exports.createObjectURL = pdfjsLibs.pdfjsSharedUtil.createObjectURL;
68+
exports.removeNullCharacters = pdfjsLibs.pdfjsSharedUtil.removeNullCharacters;
69+
exports.shadow = pdfjsLibs.pdfjsSharedUtil.shadow;
70+
exports.createBlob = pdfjsLibs.pdfjsSharedUtil.createBlob;
71+
exports.getFilenameFromUrl =
72+
pdfjsLibs.pdfjsDisplayDOMUtils.getFilenameFromUrl;
73+
exports.addLinkAttributes = pdfjsLibs.pdfjsDisplayDOMUtils.addLinkAttributes;
6174
//#else
6275
exports.WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
6376
//#endif

web/annotation_layer_builder.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* See the License for the specific language governing permissions and
1313
* limitations under the License.
1414
*/
15-
/*globals PDFJS, mozL10n, SimpleLinkService */
15+
/*globals pdfjsLib, mozL10n, SimpleLinkService */
1616

1717
'use strict';
1818

@@ -68,7 +68,7 @@ var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
6868
if (self.div) {
6969
// If an annotationLayer already exists, refresh its children's
7070
// transformation matrices.
71-
PDFJS.AnnotationLayer.update(parameters);
71+
pdfjsLib.AnnotationLayer.update(parameters);
7272
} else {
7373
// Create an annotation layer div and render the annotations
7474
// if there is at least one annotation.
@@ -81,7 +81,7 @@ var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
8181
self.pageDiv.appendChild(self.div);
8282
parameters.div = self.div;
8383

84-
PDFJS.AnnotationLayer.render(parameters);
84+
pdfjsLib.AnnotationLayer.render(parameters);
8585
if (typeof mozL10n !== 'undefined') {
8686
mozL10n.translate(self.div);
8787
}

0 commit comments

Comments
 (0)