Skip to content

Commit

Permalink
Rename the globals to shorter names.
Browse files Browse the repository at this point in the history
pdfjsDistBuildPdf=pdfjsLib
pdfjsDistWebPdfViewer=pdfjsViewer
pdfjsDistBuildPdfWorker=pdfjsLibWorker
  • Loading branch information
brendandahl committed Mar 15, 2018
1 parent 6662985 commit 2bb2c6f
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 68 deletions.
8 changes: 4 additions & 4 deletions examples/acroforms/acroforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

'use strict';

pdfjsDistBuildPdf.GlobalWorkerOptions.workerSrc =
pdfjsLib.GlobalWorkerOptions.workerSrc =
'../../node_modules/pdfjs-dist/build/pdf.worker.js';

var DEFAULT_URL = '../../test/pdfs/f1040.pdf';
Expand All @@ -24,20 +24,20 @@ var DEFAULT_SCALE = 1.0;
var container = document.getElementById('pageContainer');

// Fetch the PDF document from the URL using promises.
pdfjsDistBuildPdf.getDocument(DEFAULT_URL).then(function (doc) {
pdfjsLib.getDocument(DEFAULT_URL).then(function (doc) {
// Use a promise to fetch and render the next page.
var promise = Promise.resolve();

for (var i = 1; i <= doc.numPages; i++) {
promise = promise.then(function (pageNum) {
return doc.getPage(pageNum).then(function (pdfPage) {
// Create the page view.
var pdfPageView = new pdfjsDistWebPdfViewer.PDFPageView({
var pdfPageView = new pdfjsViewer.PDFPageView({
container: container,
id: pageNum,
scale: DEFAULT_SCALE,
defaultViewport: pdfPage.getViewport(DEFAULT_SCALE),
annotationLayerFactory: new pdfjsDistWebPdfViewer.DefaultAnnotationLayerFactory(),
annotationLayerFactory: new pdfjsViewer.DefaultAnnotationLayerFactory(),
renderInteractiveForms: true,
});

Expand Down
2 changes: 1 addition & 1 deletion examples/browserify/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

// Hello world example for browserify: worker bundle.

(typeof window !== 'undefined' ? window : {}).pdfjsDistBuildPdfWorker =
(typeof window !== 'undefined' ? window : {}).pdfjsLibWorker =
require('pdfjs-dist/build/pdf.worker');
12 changes: 6 additions & 6 deletions examples/components/pageviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

'use strict';

if (!pdfjsDistBuildPdf.getDocument || !pdfjsDistWebPdfViewer.PDFPageView) {
if (!pdfjsLib.getDocument || !pdfjsViewer.PDFPageView) {
alert('Please build the pdfjs-dist library using\n' +
' `gulp dist-install`');
}

// The workerSrc property shall be specified.
//
pdfjsDistBuildPdf.GlobalWorkerOptions.workerSrc =
pdfjsLib.GlobalWorkerOptions.workerSrc =
'../../node_modules/pdfjs-dist/build/pdf.worker.js';

// Some PDFs need external cmaps.
Expand All @@ -37,22 +37,22 @@ var SCALE = 1.0;
var container = document.getElementById('pageContainer');

// Loading document.
pdfjsDistBuildPdf.getDocument({
pdfjsLib.getDocument({
url: DEFAULT_URL,
cMapUrl: CMAP_URL,
cMapPacked: CMAP_PACKED,
}).then(function(pdfDocument) {
// Document loaded, retrieving the page.
return pdfDocument.getPage(PAGE_TO_VIEW).then(function (pdfPage) {
// Creating the page view with default parameters.
var pdfPageView = new pdfjsDistWebPdfViewer.PDFPageView({
var pdfPageView = new pdfjsViewer.PDFPageView({
container: container,
id: PAGE_TO_VIEW,
scale: SCALE,
defaultViewport: pdfPage.getViewport(SCALE),
// We can enable text/annotations layers, if needed
textLayerFactory: new pdfjsDistWebPdfViewer.DefaultTextLayerFactory(),
annotationLayerFactory: new pdfjsDistWebPdfViewer.DefaultAnnotationLayerFactory(),
textLayerFactory: new pdfjsViewer.DefaultTextLayerFactory(),
annotationLayerFactory: new pdfjsViewer.DefaultAnnotationLayerFactory(),
});
// Associates the actual page with the view, and drawing it
pdfPageView.setPdfPage(pdfPage);
Expand Down
12 changes: 6 additions & 6 deletions examples/components/simpleviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

'use strict';

if (!pdfjsDistBuildPdf.getDocument || !pdfjsDistWebPdfViewer.PDFViewer) {
if (!pdfjsLib.getDocument || !pdfjsViewer.PDFViewer) {
alert('Please build the pdfjs-dist library using\n' +
' `gulp dist-install`');
}

// The workerSrc property shall be specified.
//
pdfjsDistBuildPdf.GlobalWorkerOptions.workerSrc =
pdfjsLib.GlobalWorkerOptions.workerSrc =
'../../node_modules/pdfjs-dist/build/pdf.worker.js';

// Some PDFs need external cmaps.
Expand All @@ -36,16 +36,16 @@ var SEARCH_FOR = ''; // try 'Mozilla';
var container = document.getElementById('viewerContainer');

// (Optionally) enable hyperlinks within PDF files.
var pdfLinkService = new pdfjsDistWebPdfViewer.PDFLinkService();
var pdfLinkService = new pdfjsViewer.PDFLinkService();

var pdfViewer = new pdfjsDistWebPdfViewer.PDFViewer({
var pdfViewer = new pdfjsViewer.PDFViewer({
container: container,
linkService: pdfLinkService,
});
pdfLinkService.setViewer(pdfViewer);

// (Optionally) enable find controller.
var pdfFindController = new pdfjsDistWebPdfViewer.PDFFindController({
var pdfFindController = new pdfjsViewer.PDFFindController({
pdfViewer: pdfViewer,
});
pdfViewer.setFindController(pdfFindController);
Expand All @@ -60,7 +60,7 @@ container.addEventListener('pagesinit', function () {
});

// Loading document.
pdfjsDistBuildPdf.getDocument({
pdfjsLib.getDocument({
url: DEFAULT_URL,
cMapUrl: CMAP_URL,
cMapPacked: CMAP_PACKED,
Expand Down
12 changes: 6 additions & 6 deletions examples/components/singlepageviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

'use strict';

if (!pdfjsDistBuildPdf.getDocument || !pdfjsDistWebPdfViewer.PDFSinglePageViewer) {
if (!pdfjsLib.getDocument || !pdfjsViewer.PDFSinglePageViewer) {
alert('Please build the pdfjs-dist library using\n' +
' `gulp dist-install`');
}

// The workerSrc property shall be specified.
//
pdfjsDistBuildPdf.GlobalWorkerOptions.workerSrc =
pdfjsLib.GlobalWorkerOptions.workerSrc =
'../../node_modules/pdfjs-dist/build/pdf.worker.js';

// Some PDFs need external cmaps.
Expand All @@ -36,16 +36,16 @@ var SEARCH_FOR = ''; // try 'Mozilla';
var container = document.getElementById('viewerContainer');

// (Optionally) enable hyperlinks within PDF files.
var pdfLinkService = new pdfjsDistWebPdfViewer.PDFLinkService();
var pdfLinkService = new pdfjsViewer.PDFLinkService();

var pdfSinglePageViewer = new pdfjsDistWebPdfViewer.PDFSinglePageViewer({
var pdfSinglePageViewer = new pdfjsViewer.PDFSinglePageViewer({
container: container,
linkService: pdfLinkService,
});
pdfLinkService.setViewer(pdfSinglePageViewer);

// (Optionally) enable find controller.
var pdfFindController = new pdfjsDistWebPdfViewer.PDFFindController({
var pdfFindController = new pdfjsViewer.PDFFindController({
pdfViewer: pdfSinglePageViewer,
});
pdfSinglePageViewer.setFindController(pdfFindController);
Expand All @@ -60,7 +60,7 @@ container.addEventListener('pagesinit', function () {
});

// Loading document.
pdfjsDistBuildPdf.getDocument({
pdfjsLib.getDocument({
url: DEFAULT_URL,
cMapUrl: CMAP_URL,
cMapPacked: CMAP_PACKED,
Expand Down
4 changes: 2 additions & 2 deletions examples/learning/helloworld.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ <h1>'Hello, world!' example</h1>
//
// The workerSrc property shall be specified.
//
pdfjsDistBuildPdf.GlobalWorkerOptions.workerSrc =
pdfjsLib.GlobalWorkerOptions.workerSrc =
'../../node_modules/pdfjs-dist/build/pdf.worker.js';

//
// Asynchronous download PDF
//
pdfjsDistBuildPdf.getDocument(url).then(function getPdfHelloWorld(pdf) {
pdfjsLib.getDocument(url).then(function getPdfHelloWorld(pdf) {
//
// Fetch the first page
//
Expand Down
4 changes: 2 additions & 2 deletions examples/learning/helloworld64.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ <h1>'Hello, world!' example</h1>
//
// The workerSrc property shall be specified.
//
pdfjsDistBuildPdf.GlobalWorkerOptions.workerSrc =
pdfjsLib.GlobalWorkerOptions.workerSrc =
'../../node_modules/pdfjs-dist/build/pdf.worker.js';

// Opening PDF by passing its binary data as a string. It is still preferable
// to use Uint8Array, but string or array-like structure will work too.
pdfjsDistBuildPdf.getDocument({data: pdfData}).then(function getPdfHelloWorld(pdf) {
pdfjsLib.getDocument({data: pdfData}).then(function getPdfHelloWorld(pdf) {
// Fetch the first page.
pdf.getPage(1).then(function getPageHelloWorld(page) {
var scale = 1.5;
Expand Down
4 changes: 2 additions & 2 deletions examples/learning/prevnext.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h1>'Previous/Next' example</h1>
// pdf.js's one, or the pdf.js is executed via eval(), the workerSrc property
// shall be specified.
//
pdfjsDistBuildPdf.GlobalWorkerOptions.workerSrc =
pdfjsLib.GlobalWorkerOptions.workerSrc =
'../../node_modules/pdfjs-dist/build/pdf.worker.js';

var pdfDoc = null,
Expand Down Expand Up @@ -117,7 +117,7 @@ <h1>'Previous/Next' example</h1>
/**
* Asynchronously downloads PDF.
*/
pdfjsDistBuildPdf.getDocument(url).then(function (pdfDoc_) {
pdfjsLib.getDocument(url).then(function (pdfDoc_) {
pdfDoc = pdfDoc_;
document.getElementById('page_count').textContent = pdfDoc.numPages;

Expand Down
34 changes: 17 additions & 17 deletions examples/mobile-viewer/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals pdfjsDistBuildPdf, pdfjsDistWebPdfViewer */
/* globals pdfjsLib, pdfjsViewer */

'use strict';

if (!pdfjsDistBuildPdf.getDocument || !pdfjsDistWebPdfViewer.PDFViewer) {
if (!pdfjsLib.getDocument || !pdfjsViewer.PDFViewer) {
alert('Please build the pdfjs-dist library using\n `gulp dist-install`');
}

Expand All @@ -26,7 +26,7 @@ var MAX_IMAGE_SIZE = 1024 * 1024;
var CMAP_URL = '../../node_modules/pdfjs-dist/cmaps/';
var CMAP_PACKED = true;

pdfjsDistBuildPdf.GlobalWorkerOptions.workerSrc =
pdfjsLib.GlobalWorkerOptions.workerSrc =
'../../node_modules/pdfjs-dist/build/pdf.worker.js';

var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf';
Expand Down Expand Up @@ -61,7 +61,7 @@ var PDFViewerApplication = {
this.setTitleUsingUrl(url);

// Loading document.
var loadingTask = pdfjsDistBuildPdf.getDocument({
var loadingTask = pdfjsLib.getDocument({
url: url,
maxImageSize: MAX_IMAGE_SIZE,
cMapUrl: CMAP_URL,
Expand All @@ -87,15 +87,15 @@ var PDFViewerApplication = {
var l10n = self.l10n;
var loadingErrorMessage;

if (exception instanceof pdfjsDistBuildPdf.InvalidPDFException) {
if (exception instanceof pdfjsLib.InvalidPDFException) {
// change error message also for other builds
loadingErrorMessage = l10n.get('invalid_file_error', null,
'Invalid or corrupted PDF file.');
} else if (exception instanceof pdfjsDistBuildPdf.MissingPDFException) {
} else if (exception instanceof pdfjsLib.MissingPDFException) {
// special message for missing PDFs
loadingErrorMessage = l10n.get('missing_file_error', null,
'Missing PDF file.');
} else if (exception instanceof pdfjsDistBuildPdf.UnexpectedResponseException) {
} else if (exception instanceof pdfjsLib.UnexpectedResponseException) {
loadingErrorMessage = l10n.get('unexpected_response_error', null,
'Unexpected server response.');
} else {
Expand Down Expand Up @@ -137,14 +137,14 @@ var PDFViewerApplication = {
},

get loadingBar() {
var bar = new pdfjsDistWebPdfViewer.ProgressBar('#loadingBar', {});
var bar = new pdfjsViewer.ProgressBar('#loadingBar', {});

return pdfjsDistBuildPdf.shadow(this, 'loadingBar', bar);
return pdfjsLib.shadow(this, 'loadingBar', bar);
},

setTitleUsingUrl: function pdfViewSetTitleUsingUrl(url) {
this.url = url;
var title = pdfjsDistBuildPdf.getFilenameFromUrl(url) || url;
var title = pdfjsLib.getFilenameFromUrl(url) || url;
try {
title = decodeURIComponent(title);
} catch (e) {
Expand All @@ -165,7 +165,7 @@ var PDFViewerApplication = {
console.log('PDF ' + pdfDocument.fingerprint + ' [' +
info.PDFFormatVersion + ' ' + (info.Producer || '-').trim() +
' / ' + (info.Creator || '-').trim() + ']' +
' (PDF.js: ' + (pdfjsDistBuildPdf.version || '-') + ')');
' (PDF.js: ' + (pdfjsLib.version || '-') + ')');

var pdfTitle;
if (metadata && metadata.has('dc:title')) {
Expand Down Expand Up @@ -195,8 +195,8 @@ var PDFViewerApplication = {
error: function pdfViewError(message, moreInfo) {
var l10n = this.l10n;
var moreInfoText = [l10n.get('error_version_info',
{ version: pdfjsDistBuildPdf.version || '?',
build: pdfjsDistBuildPdf.build || '?' },
{ version: pdfjsLib.version || '?',
build: pdfjsLib.build || '?' },
'PDF.js v{{version}} (build: {{build}})')];

if (moreInfo) {
Expand Down Expand Up @@ -294,13 +294,13 @@ var PDFViewerApplication = {
},

initUI: function pdfViewInitUI() {
var linkService = new pdfjsDistWebPdfViewer.PDFLinkService();
var linkService = new pdfjsViewer.PDFLinkService();
this.pdfLinkService = linkService;

this.l10n = pdfjsDistWebPdfViewer.NullL10n;
this.l10n = pdfjsViewer.NullL10n;

var container = document.getElementById('viewerContainer');
var pdfViewer = new pdfjsDistWebPdfViewer.PDFViewer({
var pdfViewer = new pdfjsViewer.PDFViewer({
container: container,
linkService: linkService,
l10n: this.l10n,
Expand All @@ -310,7 +310,7 @@ var PDFViewerApplication = {
this.pdfViewer = pdfViewer;
linkService.setViewer(pdfViewer);

this.pdfHistory = new pdfjsDistWebPdfViewer.PDFHistory({
this.pdfHistory = new pdfjsViewer.PDFHistory({
linkService: linkService
});
linkService.setHistory(this.pdfHistory);
Expand Down
10 changes: 5 additions & 5 deletions examples/text-only/pdf2svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var PAGE_NUMBER = 1;
var PAGE_SCALE = 1.5;
var SVG_NS = 'http://www.w3.org/2000/svg';

pdfjsDistBuildPdf.GlobalWorkerOptions.workerSrc =
pdfjsLib.GlobalWorkerOptions.workerSrc =
'../../node_modules/pdfjs-dist/build/pdf.worker.js';

function buildSVG(viewport, textContent) {
Expand All @@ -33,8 +33,8 @@ function buildSVG(viewport, textContent) {
textContent.items.forEach(function (textItem) {
// we have to take in account viewport transform, which includes scale,
// rotation and Y-axis flip, and not forgetting to flip text.
var tx = pdfjsDistBuildPdf.Util.transform(
pdfjsDistBuildPdf.Util.transform(viewport.transform, textItem.transform),
var tx = pdfjsLib.Util.transform(
pdfjsLib.Util.transform(viewport.transform, textItem.transform),
[1, 0, 0, -1, 0, 0]);
var style = textContent.styles[textItem.fontName];
// adding text element
Expand All @@ -49,7 +49,7 @@ function buildSVG(viewport, textContent) {

function pageLoaded() {
// Loading document and page text content
pdfjsDistBuildPdf.getDocument({url: PDF_PATH}).then(function (pdfDocument) {
pdfjsLib.getDocument({url: PDF_PATH}).then(function (pdfDocument) {
pdfDocument.getPage(PAGE_NUMBER).then(function (page) {
var viewport = page.getViewport(PAGE_SCALE);
page.getTextContent().then(function (textContent) {
Expand All @@ -62,7 +62,7 @@ function pageLoaded() {
}

document.addEventListener('DOMContentLoaded', function () {
if (typeof pdfjsDistBuildPdf === 'undefined') {
if (typeof pdfjsLib === 'undefined') {
alert('Built version of PDF.js was not found.\n' +
'Please run `gulp dist-install`.');
return;
Expand Down
Loading

0 comments on commit 2bb2c6f

Please sign in to comment.