Merge pull request #10337 from wojtekmaj/turn-on-eslint-in-examples
Turn on ESLint in examples
This commit is contained in:
		
						commit
						cad0e61262
					
				@ -2,7 +2,6 @@ build/
 | 
				
			|||||||
l10n/
 | 
					l10n/
 | 
				
			||||||
docs/
 | 
					docs/
 | 
				
			||||||
node_modules/
 | 
					node_modules/
 | 
				
			||||||
examples/
 | 
					 | 
				
			||||||
external/bcmaps/
 | 
					external/bcmaps/
 | 
				
			||||||
external/webL10n/
 | 
					external/webL10n/
 | 
				
			||||||
external/cmapscompress/
 | 
					external/cmapscompress/
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										24
									
								
								examples/.eslintrc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								examples/.eslintrc
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,24 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "extends": [
 | 
				
			||||||
 | 
					    "../.eslintrc"
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  "parserOptions": {
 | 
				
			||||||
 | 
					    "ecmaVersion": 5,
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  "env": {
 | 
				
			||||||
 | 
					    "es6": false,
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  "globals": {
 | 
				
			||||||
 | 
					    "pdfjsImageDecoders": false,
 | 
				
			||||||
 | 
					    "pdfjsLib": false,
 | 
				
			||||||
 | 
					    "pdfjsViewer": false,
 | 
				
			||||||
 | 
					    "Uint8Array": false,
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  "rules": {
 | 
				
			||||||
 | 
					    "object-shorthand": ["error", "never"]
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -38,7 +38,8 @@ loadingTask.promise.then(function(doc) {
 | 
				
			|||||||
          id: pageNum,
 | 
					          id: pageNum,
 | 
				
			||||||
          scale: DEFAULT_SCALE,
 | 
					          scale: DEFAULT_SCALE,
 | 
				
			||||||
          defaultViewport: pdfPage.getViewport(DEFAULT_SCALE),
 | 
					          defaultViewport: pdfPage.getViewport(DEFAULT_SCALE),
 | 
				
			||||||
          annotationLayerFactory: new pdfjsViewer.DefaultAnnotationLayerFactory(),
 | 
					          annotationLayerFactory:
 | 
				
			||||||
 | 
					            new pdfjsViewer.DefaultAnnotationLayerFactory(),
 | 
				
			||||||
          renderInteractiveForms: true,
 | 
					          renderInteractiveForms: true,
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -9,7 +9,7 @@ var OUTPUT_PATH = '../../build/browserify';
 | 
				
			|||||||
var TMP_FILE_PREFIX = '../../build/browserify_';
 | 
					var TMP_FILE_PREFIX = '../../build/browserify_';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
gulp.task('build-bundle', function() {
 | 
					gulp.task('build-bundle', function() {
 | 
				
			||||||
  return browserify('main.js', {output: TMP_FILE_PREFIX + 'main.tmp'})
 | 
					  return browserify('main.js', { output: TMP_FILE_PREFIX + 'main.tmp', })
 | 
				
			||||||
    .ignore(require.resolve('pdfjs-dist/build/pdf.worker')) // Reducing size
 | 
					    .ignore(require.resolve('pdfjs-dist/build/pdf.worker')) // Reducing size
 | 
				
			||||||
    .bundle()
 | 
					    .bundle()
 | 
				
			||||||
    .pipe(source(TMP_FILE_PREFIX + 'main.tmp'))
 | 
					    .pipe(source(TMP_FILE_PREFIX + 'main.tmp'))
 | 
				
			||||||
@ -21,12 +21,14 @@ gulp.task('build-bundle', function() {
 | 
				
			|||||||
gulp.task('build-worker', function() {
 | 
					gulp.task('build-worker', function() {
 | 
				
			||||||
  // We can create our own viewer (see worker.js) or use already defined one.
 | 
					  // We can create our own viewer (see worker.js) or use already defined one.
 | 
				
			||||||
  var workerSrc = require.resolve('pdfjs-dist/build/pdf.worker.entry');
 | 
					  var workerSrc = require.resolve('pdfjs-dist/build/pdf.worker.entry');
 | 
				
			||||||
  return browserify(workerSrc, {output: TMP_FILE_PREFIX + 'worker.tmp'})
 | 
					  return browserify(workerSrc, { output: TMP_FILE_PREFIX + 'worker.tmp', })
 | 
				
			||||||
    .bundle()
 | 
					    .bundle()
 | 
				
			||||||
    .pipe(source(TMP_FILE_PREFIX + 'worker.tmp'))
 | 
					    .pipe(source(TMP_FILE_PREFIX + 'worker.tmp'))
 | 
				
			||||||
    .pipe(streamify(uglify({compress:{
 | 
					    .pipe(streamify(uglify({
 | 
				
			||||||
      sequences: false // Chrome has issue with the generated code if true
 | 
					      compress: {
 | 
				
			||||||
    }})))
 | 
					        sequences: false, // Chrome has issue with the generated code if true
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    })))
 | 
				
			||||||
    .pipe(rename('pdf.worker.bundle.js'))
 | 
					    .pipe(rename('pdf.worker.bundle.js'))
 | 
				
			||||||
    .pipe(gulp.dest(OUTPUT_PATH));
 | 
					    .pipe(gulp.dest(OUTPUT_PATH));
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
				
			|||||||
@ -24,7 +24,7 @@ loadingTask.promise.then(function (pdfDocument) {
 | 
				
			|||||||
    var ctx = canvas.getContext('2d');
 | 
					    var ctx = canvas.getContext('2d');
 | 
				
			||||||
    var renderTask = pdfPage.render({
 | 
					    var renderTask = pdfPage.render({
 | 
				
			||||||
      canvasContext: ctx,
 | 
					      canvasContext: ctx,
 | 
				
			||||||
      viewport: viewport
 | 
					      viewport: viewport,
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    return renderTask.promise;
 | 
					    return renderTask.promise;
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
				
			|||||||
@ -59,8 +59,8 @@ jpegImage.parse(typedArrayImage);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
var width = jpegImage.width, height = jpegImage.height;
 | 
					var width = jpegImage.width, height = jpegImage.height;
 | 
				
			||||||
var jpegData = jpegImage.getData({
 | 
					var jpegData = jpegImage.getData({
 | 
				
			||||||
  width,
 | 
					  width: width,
 | 
				
			||||||
  height,
 | 
					  height: height,
 | 
				
			||||||
  forceRGB: true,
 | 
					  forceRGB: true,
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -68,12 +68,12 @@ var jpegData = jpegImage.getData({
 | 
				
			|||||||
//
 | 
					//
 | 
				
			||||||
var imageData = jpegCtx.createImageData(width, height);
 | 
					var imageData = jpegCtx.createImageData(width, height);
 | 
				
			||||||
var imageBytes = imageData.data;
 | 
					var imageBytes = imageData.data;
 | 
				
			||||||
for (var i = 0, j = 0, ii = width * height * 4; i < ii;) {
 | 
					for (var j = 0, k = 0, jj = width * height * 4; j < jj;) {
 | 
				
			||||||
  imageBytes[i++] = jpegData[j++];
 | 
					  imageBytes[j++] = jpegData[k++];
 | 
				
			||||||
  imageBytes[i++] = jpegData[j++];
 | 
					  imageBytes[j++] = jpegData[k++];
 | 
				
			||||||
  imageBytes[i++] = jpegData[j++];
 | 
					  imageBytes[j++] = jpegData[k++];
 | 
				
			||||||
  imageBytes[i++] = 255;
 | 
					  imageBytes[j++] = 255;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
jpegCanvas.width = width, jpegCanvas.height = height;
 | 
					jpegCanvas.width = width;
 | 
				
			||||||
 | 
					jpegCanvas.height = height;
 | 
				
			||||||
jpegCtx.putImageData(imageData, 0, 0);
 | 
					jpegCtx.putImageData(imageData, 0, 0);
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
				
			|||||||
@ -104,7 +104,7 @@ var PDFViewerApplication = {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      loadingErrorMessage.then(function (msg) {
 | 
					      loadingErrorMessage.then(function (msg) {
 | 
				
			||||||
        self.error(msg, {message: message});
 | 
					        self.error(msg, { message: message, });
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
      self.loadingBar.hide();
 | 
					      self.loadingBar.hide();
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
@ -196,26 +196,26 @@ var PDFViewerApplication = {
 | 
				
			|||||||
    var l10n = this.l10n;
 | 
					    var l10n = this.l10n;
 | 
				
			||||||
    var moreInfoText = [l10n.get('error_version_info',
 | 
					    var moreInfoText = [l10n.get('error_version_info',
 | 
				
			||||||
      { version: pdfjsLib.version || '?',
 | 
					      { version: pdfjsLib.version || '?',
 | 
				
			||||||
        build: pdfjsLib.build || '?' },
 | 
					        build: pdfjsLib.build || '?', },
 | 
				
			||||||
      'PDF.js v{{version}} (build: {{build}})')];
 | 
					      'PDF.js v{{version}} (build: {{build}})')];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (moreInfo) {
 | 
					    if (moreInfo) {
 | 
				
			||||||
      moreInfoText.push(
 | 
					      moreInfoText.push(
 | 
				
			||||||
        l10n.get('error_message', {message: moreInfo.message},
 | 
					        l10n.get('error_message', { message: moreInfo.message, },
 | 
				
			||||||
          'Message: {{message}}'));
 | 
					          'Message: {{message}}'));
 | 
				
			||||||
      if (moreInfo.stack) {
 | 
					      if (moreInfo.stack) {
 | 
				
			||||||
        moreInfoText.push(
 | 
					        moreInfoText.push(
 | 
				
			||||||
          l10n.get('error_stack', {stack: moreInfo.stack},
 | 
					          l10n.get('error_stack', { stack: moreInfo.stack, },
 | 
				
			||||||
            'Stack: {{stack}}'));
 | 
					            'Stack: {{stack}}'));
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        if (moreInfo.filename) {
 | 
					        if (moreInfo.filename) {
 | 
				
			||||||
          moreInfoText.push(
 | 
					          moreInfoText.push(
 | 
				
			||||||
            l10n.get('error_file', {file: moreInfo.filename},
 | 
					            l10n.get('error_file', { file: moreInfo.filename, },
 | 
				
			||||||
              'File: {{file}}'));
 | 
					              'File: {{file}}'));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (moreInfo.lineNumber) {
 | 
					        if (moreInfo.lineNumber) {
 | 
				
			||||||
          moreInfoText.push(
 | 
					          moreInfoText.push(
 | 
				
			||||||
            l10n.get('error_line', {line: moreInfo.lineNumber},
 | 
					            l10n.get('error_line', { line: moreInfo.lineNumber, },
 | 
				
			||||||
              'Line: {{line}}'));
 | 
					              'Line: {{line}}'));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@ -311,7 +311,7 @@ var PDFViewerApplication = {
 | 
				
			|||||||
    linkService.setViewer(pdfViewer);
 | 
					    linkService.setViewer(pdfViewer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.pdfHistory = new pdfjsViewer.PDFHistory({
 | 
					    this.pdfHistory = new pdfjsViewer.PDFHistory({
 | 
				
			||||||
      linkService: linkService
 | 
					      linkService: linkService,
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    linkService.setHistory(this.pdfHistory);
 | 
					    linkService.setHistory(this.pdfHistory);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -339,8 +339,9 @@ var PDFViewerApplication = {
 | 
				
			|||||||
        function() {
 | 
					        function() {
 | 
				
			||||||
      PDFViewerApplication.page = (this.value | 0);
 | 
					      PDFViewerApplication.page = (this.value | 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // Ensure that the page number input displays the correct value, even if the
 | 
					      // Ensure that the page number input displays the correct value,
 | 
				
			||||||
      // value entered by the user was invalid (e.g. a floating point number).
 | 
					      // even if the value entered by the user was invalid
 | 
				
			||||||
 | 
					      // (e.g. a floating point number).
 | 
				
			||||||
      if (this.value !== PDFViewerApplication.page.toString()) {
 | 
					      if (this.value !== PDFViewerApplication.page.toString()) {
 | 
				
			||||||
        this.value = PDFViewerApplication.page;
 | 
					        this.value = PDFViewerApplication.page;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@ -359,7 +360,7 @@ var PDFViewerApplication = {
 | 
				
			|||||||
      document.getElementById('previous').disabled = (page <= 1);
 | 
					      document.getElementById('previous').disabled = (page <= 1);
 | 
				
			||||||
      document.getElementById('next').disabled = (page >= numPages);
 | 
					      document.getElementById('next').disabled = (page >= numPages);
 | 
				
			||||||
    }, true);
 | 
					    }, true);
 | 
				
			||||||
  }
 | 
					  },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
document.addEventListener('DOMContentLoaded', function () {
 | 
					document.addEventListener('DOMContentLoaded', function () {
 | 
				
			||||||
@ -378,6 +379,6 @@ document.addEventListener('DOMContentLoaded', function () {
 | 
				
			|||||||
// We need to delay opening until all HTML is loaded.
 | 
					// We need to delay opening until all HTML is loaded.
 | 
				
			||||||
PDFViewerApplication.animationStartedPromise.then(function () {
 | 
					PDFViewerApplication.animationStartedPromise.then(function () {
 | 
				
			||||||
  PDFViewerApplication.open({
 | 
					  PDFViewerApplication.open({
 | 
				
			||||||
    url: DEFAULT_URL
 | 
					    url: DEFAULT_URL,
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										9
									
								
								examples/node/.eslintrc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								examples/node/.eslintrc
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "extends": [
 | 
				
			||||||
 | 
					    "../.eslintrc"
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  "env": {
 | 
				
			||||||
 | 
					    "node": true,
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -96,7 +96,7 @@ DOMElement.prototype = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  appendChild: function DOMElement_appendChild(element) {
 | 
					  appendChild: function DOMElement_appendChild(element) {
 | 
				
			||||||
    var childNodes = this.childNodes;
 | 
					    var childNodes = this.childNodes;
 | 
				
			||||||
    if (childNodes.indexOf(element) === -1) {
 | 
					    if (!childNodes.includes(element)) {
 | 
				
			||||||
      childNodes.push(element);
 | 
					      childNodes.push(element);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
@ -124,8 +124,8 @@ DOMElement.prototype = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  getSerializer: function DOMElement_getSerializer() {
 | 
					  getSerializer: function DOMElement_getSerializer() {
 | 
				
			||||||
    return new DOMElementSerializer(this);
 | 
					    return new DOMElementSerializer(this);
 | 
				
			||||||
  }
 | 
					  },
 | 
				
			||||||
}
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function DOMElementSerializer(node) {
 | 
					function DOMElementSerializer(node) {
 | 
				
			||||||
  this._node = node;
 | 
					  this._node = node;
 | 
				
			||||||
@ -152,10 +152,12 @@ DOMElementSerializer.prototype = {
 | 
				
			|||||||
          return ' xmlns:xlink="http://www.w3.org/1999/xlink"' +
 | 
					          return ' xmlns:xlink="http://www.w3.org/1999/xlink"' +
 | 
				
			||||||
                 ' xmlns:svg="http://www.w3.org/2000/svg"';
 | 
					                 ' xmlns:svg="http://www.w3.org/2000/svg"';
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        /* falls through */
 | 
				
			||||||
      case 2:  // Initialize variables for looping over attributes.
 | 
					      case 2:  // Initialize variables for looping over attributes.
 | 
				
			||||||
        ++this._state;
 | 
					        ++this._state;
 | 
				
			||||||
        this._loopIndex = 0;
 | 
					        this._loopIndex = 0;
 | 
				
			||||||
        this._attributeKeys = Object.keys(node.attributes);
 | 
					        this._attributeKeys = Object.keys(node.attributes);
 | 
				
			||||||
 | 
					        /* falls through */
 | 
				
			||||||
      case 3:  // Serialize any attributes and end opening tag.
 | 
					      case 3:  // Serialize any attributes and end opening tag.
 | 
				
			||||||
        if (this._loopIndex < this._attributeKeys.length) {
 | 
					        if (this._loopIndex < this._attributeKeys.length) {
 | 
				
			||||||
          var name = this._attributeKeys[this._loopIndex++];
 | 
					          var name = this._attributeKeys[this._loopIndex++];
 | 
				
			||||||
@ -170,6 +172,7 @@ DOMElementSerializer.prototype = {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        ++this._state;
 | 
					        ++this._state;
 | 
				
			||||||
        this._loopIndex = 0;
 | 
					        this._loopIndex = 0;
 | 
				
			||||||
 | 
					        /* falls through */
 | 
				
			||||||
      case 5:  // Serialize child nodes (only for non-tspan/style elements).
 | 
					      case 5:  // Serialize child nodes (only for non-tspan/style elements).
 | 
				
			||||||
        var value;
 | 
					        var value;
 | 
				
			||||||
        while (true) {
 | 
					        while (true) {
 | 
				
			||||||
@ -186,6 +189,7 @@ DOMElementSerializer.prototype = {
 | 
				
			|||||||
            break;
 | 
					            break;
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        /* falls through */
 | 
				
			||||||
      case 6:  // Ending tag.
 | 
					      case 6:  // Ending tag.
 | 
				
			||||||
        ++this._state;
 | 
					        ++this._state;
 | 
				
			||||||
        return '</' + node.nodeName + '>';
 | 
					        return '</' + node.nodeName + '>';
 | 
				
			||||||
@ -201,7 +205,7 @@ const document = {
 | 
				
			|||||||
  childNodes: [],
 | 
					  childNodes: [],
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  get currentScript() {
 | 
					  get currentScript() {
 | 
				
			||||||
    return { src: '' };
 | 
					    return { src: '', };
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  get documentElement() {
 | 
					  get documentElement() {
 | 
				
			||||||
@ -222,7 +226,7 @@ const document = {
 | 
				
			|||||||
      return [this.head || (this.head = new DOMElement('head'))];
 | 
					      return [this.head || (this.head = new DOMElement('head'))];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return [];
 | 
					    return [];
 | 
				
			||||||
  }
 | 
					  },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function Image() {
 | 
					function Image() {
 | 
				
			||||||
@ -238,8 +242,8 @@ Image.prototype = {
 | 
				
			|||||||
    if (this.onload) {
 | 
					    if (this.onload) {
 | 
				
			||||||
      this.onload();
 | 
					      this.onload();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  },
 | 
				
			||||||
}
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.document = document;
 | 
					exports.document = document;
 | 
				
			||||||
exports.Image = Image;
 | 
					exports.Image = Image;
 | 
				
			||||||
 | 
				
			|||||||
@ -52,7 +52,7 @@ loadingTask.promise.then(function(doc) {
 | 
				
			|||||||
      }).then(function () {
 | 
					      }).then(function () {
 | 
				
			||||||
        console.log();
 | 
					        console.log();
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
    })
 | 
					    });
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
  // Loading of the first page will wait on metadata and subsequent loadings
 | 
					  // Loading of the first page will wait on metadata and subsequent loadings
 | 
				
			||||||
  // will wait on the previous pages.
 | 
					  // will wait on the previous pages.
 | 
				
			||||||
 | 
				
			|||||||
@ -66,11 +66,12 @@ loadingTask.promise.then(function(pdfDocument) {
 | 
				
			|||||||
    // Render the page on a Node canvas with 100% scale.
 | 
					    // Render the page on a Node canvas with 100% scale.
 | 
				
			||||||
    var viewport = page.getViewport(1.0);
 | 
					    var viewport = page.getViewport(1.0);
 | 
				
			||||||
    var canvasFactory = new NodeCanvasFactory();
 | 
					    var canvasFactory = new NodeCanvasFactory();
 | 
				
			||||||
    var canvasAndContext = canvasFactory.create(viewport.width, viewport.height);
 | 
					    var canvasAndContext =
 | 
				
			||||||
 | 
					      canvasFactory.create(viewport.width, viewport.height);
 | 
				
			||||||
    var renderContext = {
 | 
					    var renderContext = {
 | 
				
			||||||
      canvasContext: canvasAndContext.context,
 | 
					      canvasContext: canvasAndContext.context,
 | 
				
			||||||
      viewport: viewport,
 | 
					      viewport: viewport,
 | 
				
			||||||
      canvasFactory: canvasFactory
 | 
					      canvasFactory: canvasFactory,
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    var renderTask = page.render(renderContext);
 | 
					    var renderTask = page.render(renderContext);
 | 
				
			||||||
@ -81,7 +82,8 @@ loadingTask.promise.then(function(pdfDocument) {
 | 
				
			|||||||
        if (error) {
 | 
					        if (error) {
 | 
				
			||||||
          console.error('Error: ' + error);
 | 
					          console.error('Error: ' + error);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
          console.log('Finished converting first page of PDF file to a PNG image.');
 | 
					          console.log(
 | 
				
			||||||
 | 
					            'Finished converting first page of PDF file to a PNG image.');
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
				
			|||||||
@ -86,8 +86,9 @@ function writeSvgToFile(svgElement, filePath) {
 | 
				
			|||||||
// callback.
 | 
					// callback.
 | 
				
			||||||
var loadingTask = pdfjsLib.getDocument({
 | 
					var loadingTask = pdfjsLib.getDocument({
 | 
				
			||||||
  data: data,
 | 
					  data: data,
 | 
				
			||||||
  // Try to export JPEG images directly if they don't need any further processing.
 | 
					  // Try to export JPEG images directly if they don't need any further
 | 
				
			||||||
  nativeImageDecoderSupport: pdfjsLib.NativeImageDecoding.DISPLAY
 | 
					  // processing.
 | 
				
			||||||
 | 
					  nativeImageDecoderSupport: pdfjsLib.NativeImageDecoding.DISPLAY,
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
loadingTask.promise.then(function(doc) {
 | 
					loadingTask.promise.then(function(doc) {
 | 
				
			||||||
  var numPages = doc.numPages;
 | 
					  var numPages = doc.numPages;
 | 
				
			||||||
@ -107,7 +108,8 @@ loadingTask.promise.then(function(doc) {
 | 
				
			|||||||
        var svgGfx = new pdfjsLib.SVGGraphics(page.commonObjs, page.objs);
 | 
					        var svgGfx = new pdfjsLib.SVGGraphics(page.commonObjs, page.objs);
 | 
				
			||||||
        svgGfx.embedFonts = true;
 | 
					        svgGfx.embedFonts = true;
 | 
				
			||||||
        return svgGfx.getSVG(opList, viewport).then(function (svg) {
 | 
					        return svgGfx.getSVG(opList, viewport).then(function (svg) {
 | 
				
			||||||
          return writeSvgToFile(svg, getFilePathForPage(pageNum)).then(function () {
 | 
					          return writeSvgToFile(svg, getFilePathForPage(pageNum))
 | 
				
			||||||
 | 
					            .then(function () {
 | 
				
			||||||
              console.log('Page: ' + pageNum);
 | 
					              console.log('Page: ' + pageNum);
 | 
				
			||||||
            }, function(err) {
 | 
					            }, function(err) {
 | 
				
			||||||
              console.log('Error: ' + err);
 | 
					              console.log('Error: ' + err);
 | 
				
			||||||
 | 
				
			|||||||
@ -49,7 +49,7 @@ function buildSVG(viewport, textContent) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
function pageLoaded() {
 | 
					function pageLoaded() {
 | 
				
			||||||
  // Loading document and page text content
 | 
					  // Loading document and page text content
 | 
				
			||||||
  var loadingTask = pdfjsLib.getDocument({url: PDF_PATH});
 | 
					  var loadingTask = pdfjsLib.getDocument({ url: PDF_PATH, });
 | 
				
			||||||
  loadingTask.promise.then(function(pdfDocument) {
 | 
					  loadingTask.promise.then(function(pdfDocument) {
 | 
				
			||||||
    pdfDocument.getPage(PAGE_NUMBER).then(function (page) {
 | 
					    pdfDocument.getPage(PAGE_NUMBER).then(function (page) {
 | 
				
			||||||
      var viewport = page.getViewport(PAGE_SCALE);
 | 
					      var viewport = page.getViewport(PAGE_SCALE);
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										9
									
								
								examples/webpack/.eslintrc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								examples/webpack/.eslintrc
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "extends": [
 | 
				
			||||||
 | 
					    "../.eslintrc"
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  "env": {
 | 
				
			||||||
 | 
					    "node": true,
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -24,7 +24,7 @@ loadingTask.promise.then(function (pdfDocument) {
 | 
				
			|||||||
    var ctx = canvas.getContext('2d');
 | 
					    var ctx = canvas.getContext('2d');
 | 
				
			||||||
    var renderTask = pdfPage.render({
 | 
					    var renderTask = pdfPage.render({
 | 
				
			||||||
      canvasContext: ctx,
 | 
					      canvasContext: ctx,
 | 
				
			||||||
      viewport: viewport
 | 
					      viewport: viewport,
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    return renderTask.promise;
 | 
					    return renderTask.promise;
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
				
			|||||||
@ -1,16 +1,16 @@
 | 
				
			|||||||
var webpack = require('webpack');
 | 
					var webpack = require('webpack'); // eslint-disable-line no-unused-vars
 | 
				
			||||||
var path = require('path');
 | 
					var path = require('path');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = {
 | 
					module.exports = {
 | 
				
			||||||
  context: __dirname,
 | 
					  context: __dirname,
 | 
				
			||||||
  entry: {
 | 
					  entry: {
 | 
				
			||||||
    'main': './main.js',
 | 
					    'main': './main.js',
 | 
				
			||||||
    'pdf.worker': 'pdfjs-dist/build/pdf.worker.entry'
 | 
					    'pdf.worker': 'pdfjs-dist/build/pdf.worker.entry',
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  mode: 'none',
 | 
					  mode: 'none',
 | 
				
			||||||
  output: {
 | 
					  output: {
 | 
				
			||||||
    path: path.join(__dirname, '../../build/webpack'),
 | 
					    path: path.join(__dirname, '../../build/webpack'),
 | 
				
			||||||
    publicPath: '../../build/webpack/',
 | 
					    publicPath: '../../build/webpack/',
 | 
				
			||||||
    filename: '[name].bundle.js'
 | 
					    filename: '[name].bundle.js',
 | 
				
			||||||
  }
 | 
					  },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user