Skip to content

Commit 68e8f5f

Browse files
committed
Merge pull request #7126 from yurydelendik/rm-pdfjs-display
Move all PDFJS display/ usages into global.js file.
2 parents bc8df67 + 1e4886a commit 68e8f5f

39 files changed

+720
-517
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/domstubs.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,6 @@ DOMElement.prototype = {
120120
},
121121
}
122122

123-
global.window = global;
124-
125-
global.navigator = { userAgent: 'node' };
126-
127123
global.document = {
128124
childNodes : [],
129125

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) {

make.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ target.jsdoc = function() {
198198
var JSDOC_FILES = [
199199
'src/doc_helper.js',
200200
'src/display/api.js',
201+
'src/display/global.js',
201202
'src/shared/util.js',
202203
'src/core/annotation.js'
203204
];
@@ -527,9 +528,7 @@ target.bundle = function(args) {
527528

528529
var umd = require('./external/umdutils/verifier.js');
529530
var MAIN_SRC_FILES = [
530-
SRC_DIR + 'display/annotation_layer.js',
531-
SRC_DIR + 'display/text_layer.js',
532-
SRC_DIR + 'display/api.js'
531+
SRC_DIR + 'display/global.js'
533532
];
534533

535534
var WORKER_SRC_FILES = [
@@ -539,9 +538,8 @@ target.bundle = function(args) {
539538
var mainFileName = 'pdf.js';
540539
var workerFileName = 'pdf.worker.js';
541540

542-
// Extension does not need svg.js and network.js files.
541+
// Extension does not need network.js file.
543542
if (!defines.FIREFOX && !defines.MOZCENTRAL) {
544-
MAIN_SRC_FILES.push(SRC_DIR + 'display/svg.js');
545543
WORKER_SRC_FILES.push(SRC_DIR + 'core/network.js');
546544
}
547545

src/display/annotation_layer.js

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

1716
'use strict';
1817

@@ -35,6 +34,7 @@ var addLinkAttributes = displayDOMUtils.addLinkAttributes;
3534
var getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
3635
var warn = sharedUtil.warn;
3736
var CustomStyle = displayDOMUtils.CustomStyle;
37+
var getDefaultSetting = displayDOMUtils.getDefaultSetting;
3838

3939
/**
4040
* @typedef {Object} AnnotationElementParameters
@@ -107,6 +107,7 @@ var AnnotationElement = (function AnnotationElementClosure() {
107107
this.viewport = parameters.viewport;
108108
this.linkService = parameters.linkService;
109109
this.downloadManager = parameters.downloadManager;
110+
this.imageResourcesPath = parameters.imageResourcesPath;
110111

111112
if (isRenderable) {
112113
this.container = this._createContainer();
@@ -363,7 +364,7 @@ var TextAnnotationElement = (function TextAnnotationElementClosure() {
363364
var image = document.createElement('img');
364365
image.style.height = this.container.style.height;
365366
image.style.width = this.container.style.width;
366-
image.src = PDFJS.imageResourcesPath + 'annotation-' +
367+
image.src = this.imageResourcesPath + 'annotation-' +
367368
this.data.name.toLowerCase() + '.svg';
368369
image.alt = '[{{type}} Annotation]';
369370
image.dataset.l10nId = 'text_annotation_type';
@@ -838,6 +839,7 @@ var FileAttachmentAnnotationElement = (
838839
* @property {Array} annotations
839840
* @property {PDFPage} page
840841
* @property {IPDFLinkService} linkService
842+
* @property {string} imageResourcesPath
841843
*/
842844

843845
/**
@@ -868,7 +870,9 @@ var AnnotationLayer = (function AnnotationLayerClosure() {
868870
page: parameters.page,
869871
viewport: parameters.viewport,
870872
linkService: parameters.linkService,
871-
downloadManager: parameters.downloadManager
873+
downloadManager: parameters.downloadManager,
874+
imageResourcesPath: parameters.imageResourcesPath ||
875+
getDefaultSetting('imageResourcesPath')
872876
};
873877
var element = annotationElementFactory.create(properties);
874878
if (element.isRenderable) {
@@ -899,7 +903,5 @@ var AnnotationLayer = (function AnnotationLayerClosure() {
899903
};
900904
})();
901905

902-
PDFJS.AnnotationLayer = AnnotationLayer;
903-
904906
exports.AnnotationLayer = AnnotationLayer;
905907
}));

0 commit comments

Comments
 (0)