Skip to content

Commit

Permalink
Modified Examples to work without systemjs
Browse files Browse the repository at this point in the history
  • Loading branch information
RonLek committed Jul 20, 2018
1 parent 7e13977 commit 676c326
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 97 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ You can play with the PDF.js API directly from your browser using the live demos

The repository contains a hello world example that you can run locally:

+ [examples/helloworld/](https://github.com/mozilla/pdf.js/blob/master/examples/helloworld/)
+ [examples/learning/helloworld](https://github.com/mozilla/pdf.js/blob/master/examples/learning/helloworld.html)

More examples can be found in the examples folder. Some of them are using the pdfjs-dist package, which can be built and installed in this repo directory via `gulp dist-install` command.

Expand Down
16 changes: 0 additions & 16 deletions examples/helloworld/README.md

This file was deleted.

40 changes: 0 additions & 40 deletions examples/helloworld/hello.js

This file was deleted.

Binary file removed examples/helloworld/helloworld.pdf
Binary file not shown.
14 changes: 0 additions & 14 deletions examples/helloworld/index.html

This file was deleted.

4 changes: 2 additions & 2 deletions examples/svgviewer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

<title>PDF.js SVG viewer example</title>

<script src="../../node_modules/systemjs/dist/system.js"></script>
<script src="../../systemjs.config.js"></script>
<script src="../../node_modules/pdfjs-dist/build/pdf.js"></script>
<script src="../../node_modules/pdfjs-dist/web/pdf_viewer.js"></script>
<script src="viewer.js"></script>

<style>
Expand Down
41 changes: 17 additions & 24 deletions examples/svgviewer/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

var DEFAULT_SCALE = 1.5;

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

// Parse query string to extract some parameters (it can fail for some input)
var query = document.location.href.replace(/^[^?]*(\?([^#]*))?(#.*)?/, '$2');
var queryParams = query ? JSON.parse('{' + query.split('&').map(function (a) {
Expand All @@ -10,7 +15,7 @@ var queryParams = query ? JSON.parse('{' + query.split('&').map(function (a) {

var url = queryParams.file || '../../web/compressed.tracemonkey-pldi-09.pdf';

function renderDocument(pdf, svgLib) {
function renderDocument(pdf) {
var promise = Promise.resolve();
for (var i = 1; i <= pdf.numPages; i++) {
// Using promise to fetch and render the next page
Expand All @@ -26,7 +31,7 @@ function renderDocument(pdf, svgLib) {
document.body.appendChild(container);

return page.getOperatorList().then(function (opList) {
var svgGfx = new svgLib.SVGGraphics(page.commonObjs, page.objs);
var svgGfx = new pdfjsLib.SVGGraphics(page.commonObjs, page.objs);
return svgGfx.getSVG(opList, viewport).then(function (svg) {
container.appendChild(svg);
});
Expand All @@ -36,33 +41,21 @@ function renderDocument(pdf, svgLib) {
}
}

Promise.all([System.import('pdfjs/display/api'),
System.import('pdfjs/display/svg'),
System.import('pdfjs/display/worker_options'),
System.import('pdfjs/display/network'),
System.resolve('pdfjs/worker_loader')])
.then(function (modules) {
var api = modules[0];
var svg = modules[1];
var GlobalWorkerOptions = modules[2].GlobalWorkerOptions;
var network = modules[3];
api.setPDFNetworkStreamFactory((params) => {
return new network.PDFNetworkStream(params);
});

// In production, change this to point to the built `pdf.worker.js` file.
GlobalWorkerOptions.workerSrc = modules[4];
// The workerSrc property shall be specified.
//
pdfjsLib.GlobalWorkerOptions.workerSrc =
'../../node_modules/pdfjs-dist/build/pdf.worker.js';

// In production, change this to point to where the cMaps are placed.
var CMAP_URL = '../../external/bcmaps/';
var CMAP_PACKED = true;
// Some PDFs need external cmaps.
//
var CMAP_URL = '../../node_modules/pdfjs-dist/cmaps/';
var CMAP_PACKED = true;

// Fetch the PDF document from the URL using promises.
api.getDocument({
pdfjsLib.getDocument({
url: url,
cMapUrl: CMAP_URL,
cMapPacked: CMAP_PACKED,
}).then(function(doc) {
renderDocument(doc, svg);
renderDocument(doc);
});
});

0 comments on commit 676c326

Please sign in to comment.