Skip to content

Commit

Permalink
Exposes all functional members via lib exports and use them in viewer.
Browse files Browse the repository at this point in the history
  • Loading branch information
yurydelendik committed Mar 29, 2016
1 parent d142f5d commit d7a9d3c
Show file tree
Hide file tree
Showing 24 changed files with 166 additions and 98 deletions.
4 changes: 2 additions & 2 deletions examples/acroforms/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions examples/helloworld/hello.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions examples/node/getinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ 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';
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);
Expand Down
6 changes: 3 additions & 3 deletions examples/node/pdf2svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down
17 changes: 10 additions & 7 deletions examples/svgviewer/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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);
});
Expand All @@ -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);
});
});
4 changes: 2 additions & 2 deletions examples/webpack/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

// Hello world example for webpack.

require('pdfjs-dist');
var pdfjsLib = require('pdfjs-dist');

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

// It is also possible to disable workers via `PDFJS.disableWorker = true`,
// 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) {
Expand Down
9 changes: 8 additions & 1 deletion src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals pdfjsFilePath */
/* globals pdfjsFilePath, pdfjsVersion, pdfjsBuild */

'use strict';

Expand Down Expand Up @@ -2015,6 +2015,13 @@ var _UnsupportedManager = (function UnsupportedManagerClosure() {
};
})();

if (typeof pdfjsVersion !== 'undefined') {
exports.version = pdfjsVersion;
}
if (typeof pdfjsBuild !== 'undefined') {
exports.build = pdfjsBuild;
}

exports.getDocument = getDocument;
exports.PDFDataRangeTransport = PDFDataRangeTransport;
exports.PDFWorker = PDFWorker;
Expand Down
14 changes: 13 additions & 1 deletion src/main_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@

// Sync the exports below with ./pdf.js file/template.
exports.PDFJS = displayGlobal.PDFJS;

exports.build = displayAPI.build;
exports.version = displayAPI.version;
exports.getDocument = displayAPI.getDocument;
exports.PDFDataRangeTransport = displayAPI.PDFDataRangeTransport;
exports.PDFWorker = displayAPI.PDFWorker;
exports.renderTextLayer = displayTextLayer.renderTextLayer;
exports.AnnotationLayer = displayAnnotationLayer.AnnotationLayer;
exports.CustomStyle = displayDOMUtils.CustomStyle;
Expand All @@ -51,4 +53,14 @@
exports.MissingPDFException = sharedUtil.MissingPDFException;
exports.SVGGraphics = displaySVG.SVGGraphics;
exports.UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
exports.OPS = sharedUtil.OPS;
exports.UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
exports.isValidUrl = sharedUtil.isValidUrl;
exports.createObjectURL = sharedUtil.createObjectURL;
exports.removeNullCharacters = sharedUtil.removeNullCharacters;
exports.shadow = sharedUtil.shadow;
exports.createBlob = sharedUtil.createBlob;
exports.getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
exports.addLinkAttributes = displayDOMUtils.addLinkAttributes;

}));
13 changes: 13 additions & 0 deletions src/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@

//#if MAIN_FILE
exports.PDFJS = pdfjsLibs.pdfjsDisplayGlobal.PDFJS;
exports.build = pdfjsLibs.pdfjsDisplayAPI.build;
exports.version = pdfjsLibs.pdfjsDisplayAPI.version;
exports.getDocument = pdfjsLibs.pdfjsDisplayAPI.getDocument;
exports.PDFDataRangeTransport =
pdfjsLibs.pdfjsDisplayAPI.PDFDataRangeTransport;
exports.PDFWorker = pdfjsLibs.pdfjsDisplayAPI.PDFWorker;
exports.renderTextLayer = pdfjsLibs.pdfjsDisplayTextLayer.renderTextLayer;
exports.AnnotationLayer =
pdfjsLibs.pdfjsDisplayAnnotationLayer.AnnotationLayer;
Expand All @@ -58,6 +61,16 @@
exports.SVGGraphics = pdfjsLibs.pdfjsDisplaySVG.SVGGraphics;
exports.UnexpectedResponseException =
pdfjsLibs.pdfjsSharedUtil.UnexpectedResponseException;
exports.OPS = pdfjsLibs.pdfjsSharedUtil.OPS;
exports.UNSUPPORTED_FEATURES = pdfjsLibs.pdfjsSharedUtil.UNSUPPORTED_FEATURES;
exports.isValidUrl = pdfjsLibs.pdfjsSharedUtil.isValidUrl;
exports.createObjectURL = pdfjsLibs.pdfjsSharedUtil.createObjectURL;
exports.removeNullCharacters = pdfjsLibs.pdfjsSharedUtil.removeNullCharacters;
exports.shadow = pdfjsLibs.pdfjsSharedUtil.shadow;
exports.createBlob = pdfjsLibs.pdfjsSharedUtil.createBlob;
exports.getFilenameFromUrl =
pdfjsLibs.pdfjsDisplayDOMUtils.getFilenameFromUrl;
exports.addLinkAttributes = pdfjsLibs.pdfjsDisplayDOMUtils.addLinkAttributes;
//#else
exports.WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
//#endif
Expand Down
6 changes: 3 additions & 3 deletions web/annotation_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*globals PDFJS, mozL10n, SimpleLinkService */
/*globals pdfjsLib, mozL10n, SimpleLinkService */

'use strict';

Expand Down Expand Up @@ -68,7 +68,7 @@ var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
if (self.div) {
// If an annotationLayer already exists, refresh its children's
// transformation matrices.
PDFJS.AnnotationLayer.update(parameters);
pdfjsLib.AnnotationLayer.update(parameters);
} else {
// Create an annotation layer div and render the annotations
// if there is at least one annotation.
Expand All @@ -81,7 +81,7 @@ var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
self.pageDiv.appendChild(self.div);
parameters.div = self.div;

PDFJS.AnnotationLayer.render(parameters);
pdfjsLib.AnnotationLayer.render(parameters);
if (typeof mozL10n !== 'undefined') {
mozL10n.translate(self.div);
}
Expand Down
4 changes: 2 additions & 2 deletions web/chromecom.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

/* globals chrome, PDFJS, PDFViewerApplication, OverlayManager */
/* globals chrome, pdfjsLib, PDFViewerApplication, OverlayManager */
'use strict';

var ChromeCom = (function ChromeComClosure() {
Expand Down Expand Up @@ -81,7 +81,7 @@ var ChromeCom = (function ChromeComClosure() {
return;
}
}
if (/^filesystem:/.test(file) && !PDFJS.disableWorker) {
if (/^filesystem:/.test(file) && !pdfjsLib.PDFJS.disableWorker) {
// The security origin of filesystem:-URLs are not preserved when the
// URL is passed to a Web worker, (http://crbug.com/362061), so we have
// to create an intermediate blob:-URL as a work-around.
Expand Down
8 changes: 4 additions & 4 deletions web/debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals PDFJS */
/* globals pdfjsLib */

'use strict';

Expand Down Expand Up @@ -307,8 +307,8 @@ var Stepper = (function StepperClosure() {
this.table = table;
if (!opMap) {
opMap = Object.create(null);
for (var key in PDFJS.OPS) {
opMap[PDFJS.OPS[key]] = key;
for (var key in pdfjsLib.OPS) {
opMap[pdfjsLib.OPS[key]] = key;
}
}
},
Expand Down Expand Up @@ -460,7 +460,7 @@ var Stats = (function Stats() {
manager: null,
init: function init() {
this.panel.setAttribute('style', 'padding: 5px;');
PDFJS.enableStats = true;
pdfjsLib.PDFJS.enableStats = true;
},
enabled: false,
active: false,
Expand Down
7 changes: 4 additions & 3 deletions web/download_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals URL, PDFJS */
/* globals URL, pdfjsLib */

'use strict';

Expand Down Expand Up @@ -58,7 +58,7 @@ var DownloadManager = (function DownloadManagerClosure() {

DownloadManager.prototype = {
downloadUrl: function DownloadManager_downloadUrl(url, filename) {
if (!PDFJS.isValidUrl(url, true)) {
if (!pdfjsLib.isValidUrl(url, true)) {
return; // restricted/invalid URL
}

Expand All @@ -72,7 +72,8 @@ var DownloadManager = (function DownloadManagerClosure() {
filename);
}

var blobUrl = PDFJS.createObjectURL(data, contentType);
var blobUrl = pdfjsLib.createObjectURL(data, contentType,
pdfjsLib.PDFJS.disableCreateObjectURL);
download(blobUrl, filename);
},

Expand Down
4 changes: 2 additions & 2 deletions web/firefoxcom.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals Preferences, PDFJS, Promise */
/* globals Preferences, pdfjsLib, Promise */

'use strict';

Expand Down Expand Up @@ -87,7 +87,7 @@ var DownloadManager = (function DownloadManagerClosure() {

downloadData: function DownloadManager_downloadData(data, filename,
contentType) {
var blobUrl = PDFJS.createObjectURL(data, contentType);
var blobUrl = pdfjsLib.createObjectURL(data, contentType, false);

FirefoxCom.request('download', {
blobUrl: blobUrl,
Expand Down
4 changes: 2 additions & 2 deletions web/password_prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals PDFJS, mozL10n, OverlayManager */
/* globals pdfjsLib, mozL10n, OverlayManager */

'use strict';

Expand Down Expand Up @@ -55,7 +55,7 @@ var PasswordPrompt = {
var promptString = mozL10n.get('password_label', null,
'Enter the password to open this PDF file.');

if (this.reason === PDFJS.PasswordResponses.INCORRECT_PASSWORD) {
if (this.reason === pdfjsLib.PasswordResponses.INCORRECT_PASSWORD) {
promptString = mozL10n.get('password_invalid', null,
'Invalid password. Please try again.');
}
Expand Down
6 changes: 3 additions & 3 deletions web/pdf_attachment_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals PDFJS */
/* globals pdfjsLib */

'use strict';

Expand Down Expand Up @@ -98,12 +98,12 @@ var PDFAttachmentViewer = (function PDFAttachmentViewerClosure() {

for (var i = 0; i < attachmentsCount; i++) {
var item = attachments[names[i]];
var filename = PDFJS.getFilenameFromUrl(item.filename);
var filename = pdfjsLib.getFilenameFromUrl(item.filename);
var div = document.createElement('div');
div.className = 'attachmentsItem';
var button = document.createElement('button');
this._bindLink(button, item.content, filename);
button.textContent = PDFJS.removeNullCharacters(filename);
button.textContent = pdfjsLib.removeNullCharacters(filename);
div.appendChild(button);
this.container.appendChild(div);
}
Expand Down
2 changes: 1 addition & 1 deletion web/pdf_find_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals PDFJS, FirefoxCom, Promise, scrollIntoView */
/* globals FirefoxCom, Promise, scrollIntoView */

'use strict';

Expand Down
Loading

0 comments on commit d7a9d3c

Please sign in to comment.