root 2 vuotta sitten
vanhempi
commit
86e0e24ddc
100 muutettua tiedostoa jossa 4967 lisäystä ja 0 poistoa
  1. 20 0
      pdf.js/.editorconfig
  2. 14 0
      pdf.js/.eslintignore
  3. 247 0
      pdf.js/.eslintrc
  4. 23 0
      pdf.js/.gitattributes
  5. 16 0
      pdf.js/.github/CONTRIBUTING.md
  6. 17 0
      pdf.js/.github/ISSUE_TEMPLATE.md
  7. 8 0
      pdf.js/.github/dependabot.yml
  8. 27 0
      pdf.js/.github/workflows/ci.yml
  9. 33 0
      pdf.js/.github/workflows/codeql.yml
  10. 9 0
      pdf.js/.gitignore
  11. 3 0
      pdf.js/.gitmodules
  12. 7 0
      pdf.js/.gitpod.Dockerfile
  13. 13 0
      pdf.js/.gitpod.yml
  14. 1 0
      pdf.js/.mailmap
  15. 9 0
      pdf.js/.prettierrc
  16. 14 0
      pdf.js/.stylelintignore
  17. 18 0
      pdf.js/.stylelintrc
  18. 28 0
      pdf.js/AUTHORS
  19. 15 0
      pdf.js/CODE_OF_CONDUCT.md
  20. 5 0
      pdf.js/EXPORT
  21. 177 0
      pdf.js/LICENSE
  22. 144 0
      pdf.js/README.md
  23. 20 0
      pdf.js/docs/config.json
  24. 8 0
      pdf.js/docs/contents/api/index.md
  25. 6 0
      pdf.js/docs/contents/css/bootstrap.min.css
  26. 119 0
      pdf.js/docs/contents/css/main.css
  27. 99 0
      pdf.js/docs/contents/examples/index.md
  28. 128 0
      pdf.js/docs/contents/getting_started/index.md
  29. BIN
      pdf.js/docs/contents/images/favicon.ico
  30. 41 0
      pdf.js/docs/contents/images/logo.svg
  31. 14 0
      pdf.js/docs/contents/index.md
  32. 5 0
      pdf.js/docs/contents/js/bootstrap.min.js
  33. 1 0
      pdf.js/docs/contents/js/jquery-2.1.0.min.js
  34. 15 0
      pdf.js/docs/plugins/wintersmith-makerelative.coffee
  35. 52 0
      pdf.js/docs/templates/layout.jade
  36. 11 0
      pdf.js/examples/.eslintrc
  37. 43 0
      pdf.js/examples/components/pageviewer.html
  38. 89 0
      pdf.js/examples/components/pageviewer.js
  39. 51 0
      pdf.js/examples/components/simpleviewer.html
  40. 97 0
      pdf.js/examples/components/simpleviewer.js
  41. 51 0
      pdf.js/examples/components/singlepageviewer.html
  42. 96 0
      pdf.js/examples/components/singlepageviewer.js
  43. BIN
      pdf.js/examples/image_decoders/fish.jpg
  44. 40 0
      pdf.js/examples/image_decoders/jpeg_viewer.html
  45. 63 0
      pdf.js/examples/image_decoders/jpeg_viewer.js
  46. 78 0
      pdf.js/examples/learning/helloworld.html
  47. 68 0
      pdf.js/examples/learning/helloworld.pdf
  48. 83 0
      pdf.js/examples/learning/helloworld64.html
  49. 141 0
      pdf.js/examples/learning/prevnext.html
  50. 11 0
      pdf.js/examples/mobile-viewer/README.md
  51. BIN
      pdf.js/examples/mobile-viewer/images/div_line_left.png
  52. BIN
      pdf.js/examples/mobile-viewer/images/div_line_left@1.5x.png
  53. BIN
      pdf.js/examples/mobile-viewer/images/div_line_left@2x.png
  54. BIN
      pdf.js/examples/mobile-viewer/images/div_line_right.png
  55. BIN
      pdf.js/examples/mobile-viewer/images/div_line_right@1.5x.png
  56. BIN
      pdf.js/examples/mobile-viewer/images/div_line_right@2x.png
  57. BIN
      pdf.js/examples/mobile-viewer/images/document_bg.png
  58. BIN
      pdf.js/examples/mobile-viewer/images/icon_next_page.png
  59. BIN
      pdf.js/examples/mobile-viewer/images/icon_next_page@1.5x.png
  60. BIN
      pdf.js/examples/mobile-viewer/images/icon_previous_page.png
  61. BIN
      pdf.js/examples/mobile-viewer/images/icon_previous_page@1.5x.png
  62. BIN
      pdf.js/examples/mobile-viewer/images/icon_zoom_in.png
  63. BIN
      pdf.js/examples/mobile-viewer/images/icon_zoom_in@1.5x.png
  64. BIN
      pdf.js/examples/mobile-viewer/images/icon_zoom_out.png
  65. BIN
      pdf.js/examples/mobile-viewer/images/icon_zoom_out@1.5x.png
  66. BIN
      pdf.js/examples/mobile-viewer/images/spinner.png
  67. BIN
      pdf.js/examples/mobile-viewer/images/toolbar_background.png
  68. 273 0
      pdf.js/examples/mobile-viewer/viewer.css
  69. 76 0
      pdf.js/examples/mobile-viewer/viewer.html
  70. 454 0
      pdf.js/examples/mobile-viewer/viewer.js
  71. 9 0
      pdf.js/examples/node/.eslintrc
  72. 285 0
      pdf.js/examples/node/domstubs.js
  73. 76 0
      pdf.js/examples/node/getinfo.js
  74. 17 0
      pdf.js/examples/node/pdf2png/README.md
  75. 111 0
      pdf.js/examples/node/pdf2png/pdf2png.js
  76. 128 0
      pdf.js/examples/node/pdf2svg.js
  77. 14 0
      pdf.js/examples/text-only/index.html
  78. 72 0
      pdf.js/examples/text-only/pdf2svg.js
  79. 9 0
      pdf.js/examples/webpack/.eslintrc
  80. 1 0
      pdf.js/examples/webpack/.gitignore
  81. 35 0
      pdf.js/examples/webpack/README.md
  82. 11 0
      pdf.js/examples/webpack/index.html
  83. 35 0
      pdf.js/examples/webpack/main.js
  84. 12 0
      pdf.js/examples/webpack/package.json
  85. 16 0
      pdf.js/examples/webpack/webpack.config.js
  86. 22 0
      pdf.js/extensions/chromium/.eslintrc
  87. 1 0
      pdf.js/extensions/chromium/.gitignore
  88. 223 0
      pdf.js/extensions/chromium/contentscript.js
  89. 22 0
      pdf.js/extensions/chromium/contentstyle.css
  90. 128 0
      pdf.js/extensions/chromium/extension-router.js
  91. BIN
      pdf.js/extensions/chromium/icon128.png
  92. BIN
      pdf.js/extensions/chromium/icon16.png
  93. BIN
      pdf.js/extensions/chromium/icon19.png
  94. BIN
      pdf.js/extensions/chromium/icon38.png
  95. BIN
      pdf.js/extensions/chromium/icon48.png
  96. 71 0
      pdf.js/extensions/chromium/manifest.json
  97. 153 0
      pdf.js/extensions/chromium/options/migration.js
  98. 180 0
      pdf.js/extensions/chromium/options/options.html
  99. 210 0
      pdf.js/extensions/chromium/options/options.js
  100. 45 0
      pdf.js/extensions/chromium/pageAction/background.js

+ 20 - 0
pdf.js/.editorconfig

@@ -0,0 +1,20 @@
+root = true
+
+[*.{js,jsm,json,html,css,pdf.link}]
+charset = utf-8
+end_of_line = lf
+indent_size = 2
+indent_style = space
+insert_final_newline = true
+max_line_length = 80
+trim_trailing_whitespace = true
+
+[*.{json,pdf.link}]
+max_line_length = off
+
+[*.md]
+max_line_length = off
+trim_trailing_whitespace = false
+
+[COMMIT_EDITMSG]
+max_line_length = off

+ 14 - 0
pdf.js/.eslintignore

@@ -0,0 +1,14 @@
+build/
+l10n/
+docs/
+node_modules/
+external/bcmaps/
+external/webL10n/
+external/builder/fixtures/
+external/builder/fixtures_esprima/
+external/quickjs/
+src/shared/cffStandardStrings.js
+src/shared/fonts_utils.js
+test/tmp/
+test/pdfs/
+*~/

+ 247 - 0
pdf.js/.eslintrc

@@ -0,0 +1,247 @@
+{
+  "parserOptions": {
+    "ecmaVersion": 2022,
+    "sourceType": "module",
+  },
+
+  "plugins": [
+    "import",
+    "json",
+    "mozilla",
+    "no-unsanitized",
+    "sort-exports",
+    "unicorn",
+  ],
+
+  "extends": [
+    "plugin:json/recommended",
+    "plugin:prettier/recommended"
+  ],
+
+  "env": {
+    "browser": true,
+    "es2022": true,
+    "worker": true,
+    "amd": true,
+  },
+
+  "globals": {
+    "PDFJSDev": false,
+    "exports": false,
+    "SystemJS": false,
+  },
+
+  "rules": {
+    // Plugins
+    "import/extensions": ["error", "always", { "ignorePackages": true, }],
+    "import/no-unresolved": ["error", {
+      "ignore": ["pdfjs", "pdfjs-lib", "pdfjs-web", "pdfjs-fitCurve"]
+    }],
+    "mozilla/avoid-removeChild": "error",
+    "mozilla/use-includes-instead-of-indexOf": "error",
+    "no-unsanitized/method": "error",
+    "no-unsanitized/property": "error",
+    "sort-exports/sort-exports": ["error", {
+      "ignoreCase": true,
+    }],
+    "unicorn/no-abusive-eslint-disable": "error",
+    "unicorn/no-array-push-push": "error",
+    "unicorn/no-instanceof-array": "error",
+    "unicorn/no-new-buffer": "error",
+    "unicorn/no-useless-spread": "error",
+    "unicorn/prefer-array-find": "error",
+    "unicorn/prefer-array-flat": "error",
+    "unicorn/prefer-array-flat-map": "error",
+    "unicorn/prefer-array-index-of": "error",
+    "unicorn/prefer-at": "error",
+    "unicorn/prefer-date-now": "error",
+    "unicorn/prefer-dom-node-append": "error",
+    "unicorn/prefer-dom-node-remove": "error",
+    "unicorn/prefer-logical-operator-over-ternary": "error",
+    "unicorn/prefer-modern-dom-apis": "error",
+    "unicorn/prefer-regexp-test": "error",
+    "unicorn/prefer-string-starts-ends-with": "error",
+    "unicorn/no-typeof-undefined": ["error", { "checkGlobalVariables": false, }],
+
+    // Possible errors
+    "for-direction": "error",
+    "getter-return": "error",
+    "no-async-promise-executor": "error",
+    "no-cond-assign": ["error", "except-parens"],
+    "no-constant-condition": ["error", { "checkLoops": false, }],
+    "no-debugger": "error",
+    "no-dupe-args": "error",
+    "no-dupe-else-if": "error",
+    "no-dupe-keys": "error",
+    "no-duplicate-case": "error",
+    "no-empty": ["error", { "allowEmptyCatch": true, }],
+    "no-empty-character-class": "error",
+    "no-ex-assign": "error",
+    "no-extra-boolean-cast": "error",
+    "no-func-assign": "error",
+    "no-inner-declarations": ["error", "functions"],
+    "no-invalid-regexp": "error",
+    "no-irregular-whitespace": "error",
+    "no-loss-of-precision": "error",
+    "no-obj-calls": "error",
+    "no-promise-executor-return": "error",
+    "no-regex-spaces": "error",
+    "no-setter-return": "error",
+    "no-sparse-arrays": "error",
+    "no-template-curly-in-string": "error",
+    "no-unexpected-multiline": "error",
+    "no-unreachable": "error",
+    "no-unsafe-finally": "error",
+    "no-unsafe-negation": "error",
+    "no-unsafe-optional-chaining": ["error", { "disallowArithmeticOperators": true }],
+    "no-unused-private-class-members": "error",
+    "use-isnan": ["error", { "enforceForIndexOf": true, }],
+    "valid-typeof": ["error", { "requireStringLiterals": true, }],
+
+    // Best Practices
+    "accessor-pairs": ["error", {
+      "setWithoutGet": true,
+      "enforceForClassMembers": true,
+    }],
+    "consistent-return": "error",
+    "curly": ["error", "all"],
+    "default-case-last": "error",
+    "dot-notation": "error",
+    "eqeqeq": ["error", "always"],
+    "grouped-accessor-pairs": ["error", "getBeforeSet"],
+    "no-alert": "error",
+    "no-caller": "error",
+    "no-else-return": "error",
+    "no-empty-pattern": "error",
+    "no-eval": "error",
+    "no-extend-native": "error",
+    "no-extra-bind": "error",
+    "no-extra-label": "error",
+    "no-fallthrough": "error",
+    "no-floating-decimal": "error",
+    "no-global-assign": "error",
+    "no-implied-eval": "error",
+    "no-iterator": "error",
+    "no-lone-blocks": "error",
+    "no-multi-str": "error",
+    "no-new-func": "error",
+    "no-new-wrappers": "error",
+    "no-new": "error",
+    "no-octal-escape": "error",
+    "no-octal": "error",
+    "no-redeclare": "error",
+    "no-return-await": "error",
+    "no-self-assign": "error",
+    "no-self-compare": "error",
+    "no-throw-literal": "error",
+    "no-unused-expressions": "error",
+    "no-unused-labels": "error",
+    "no-useless-call": "error",
+    "no-useless-catch": "error",
+    "no-useless-concat": "error",
+    "no-useless-escape": "error",
+    "no-useless-return": "error",
+    "prefer-promise-reject-errors": "error",
+    "prefer-spread": "error",
+    "wrap-iife": ["error", "any"],
+    "yoda": ["error", "never", {
+      "exceptRange": true,
+    }],
+
+    // Strict Mode
+    "strict": ["off", "global"],
+
+    // Variables
+    "no-delete-var": "error",
+    "no-label-var": "error",
+    "no-shadow": "error",
+    "no-shadow-restricted-names": "error",
+    "no-undef-init": "error",
+    "no-undef": ["error", { "typeof": true, }],
+    "no-unused-vars": ["error", {
+      "vars": "all",
+      "args": "none",
+    }],
+    "no-use-before-define": ["error", {
+      "functions": false,
+      "classes": false,
+      "variables": false,
+    }],
+
+    // Stylistic Issues
+    "lines-between-class-members": ["error", "always"],
+    "max-len": ["error", {
+      "code": 1000,
+      "comments": 80,
+      "ignoreUrls": true
+    }],
+    "new-cap": ["error", { "newIsCap": true, "capIsNew": false, }],
+    "no-array-constructor": "error",
+    "no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 0, "maxBOF": 1, }],
+    "no-nested-ternary": "error",
+    "no-new-object": "error",
+    "no-restricted-syntax": ["error",
+      {
+        "selector": "BinaryExpression[operator='instanceof'][right.name='Object']",
+        "message": "Use `typeof` rather than `instanceof Object`.",
+      },
+      {
+        "selector": "CallExpression[callee.name='assert'][arguments.length!=2]",
+        "message": "`assert()` must always be invoked with two arguments.",
+      },
+      {
+        "selector": "CallExpression[callee.name='isCmd'][arguments.length<2]",
+        "message": "Use `instanceof Cmd` rather than `isCmd()` with one argument.",
+      },
+      {
+        "selector": "CallExpression[callee.name='isDict'][arguments.length<2]",
+        "message": "Use `instanceof Dict` rather than `isDict()` with one argument.",
+      },
+      {
+        "selector": "CallExpression[callee.name='isName'][arguments.length<2]",
+        "message": "Use `instanceof Name` rather than `isName()` with one argument.",
+      },
+      {
+        "selector": "NewExpression[callee.name='Cmd']",
+        "message": "Use `Cmd.get()` rather than `new Cmd()`.",
+      },
+      {
+        "selector": "NewExpression[callee.name='Name']",
+        "message": "Use `Name.get()` rather than `new Name()`.",
+      },
+      {
+        "selector": "NewExpression[callee.name='Ref']",
+        "message": "Use `Ref.get()` rather than `new Ref()`.",
+      },
+    ],
+    "no-unneeded-ternary": "error",
+    "operator-assignment": "error",
+    "prefer-exponentiation-operator": "error",
+    "spaced-comment": ["error", "always", {
+      "block": {
+        "balanced": true,
+      }
+    }],
+
+    // ECMAScript 6
+    "constructor-super": "error",
+    "no-class-assign": "error",
+    "no-confusing-arrow": "error",
+    "no-const-assign": "error",
+    "no-dupe-class-members": "error",
+    "no-duplicate-imports": "error",
+    "no-this-before-super": "error",
+    "no-useless-computed-key": "error",
+    "no-useless-constructor": "error",
+    "no-useless-rename": "error",
+    "no-var": "error",
+    "object-shorthand": ["error", "always", {
+      "avoidQuotes": true,
+    }],
+    "prefer-const": "error",
+    "sort-imports": ["error", {
+      "ignoreCase": true,
+    }],
+    "template-curly-spacing": ["error", "never"],
+  },
+}

+ 23 - 0
pdf.js/.gitattributes

@@ -0,0 +1,23 @@
+# Force Unix line endings for most file formats (except binary files)
+*.js         text eol=lf
+*.jsm        text eol=lf
+*.css        text eol=lf
+*.html       text eol=lf
+*.md         text eol=lf
+*.properties text eol=lf
+*.yml        text eol=lf
+*.json       text eol=lf
+*.config     text eol=lf
+*.inc        text eol=lf
+*.manifest   text eol=lf
+*.rdf        text eol=lf
+*.jade       text eol=lf
+*.coffee     text eol=lf
+
+# PDF files shall not modify CRLF line endings
+*.pdf -crlf
+
+# Linguist language overrides
+*.js linguist-language=JavaScript
+*.jsm linguist-language=JavaScript
+*.inc linguist-language=XML

+ 16 - 0
pdf.js/.github/CONTRIBUTING.md

@@ -0,0 +1,16 @@
+# PDF.js issue reporting
+
+The issues are used to track both bugs filed by users and specific work items for developers. Try to file one issue per problem observed. Please specify a valid title (e.g. "Glyph spacing is incorrect" instead of "PDF.js does not work") and provide more details about the issue: link to the PDF, location in the PDF, screenshot, browser version, operating system, PDF.js version and JavaScript console warning/error messages. Issues that do not have enough details provided will be closed as invalid/incomplete.
+
+If the issue is related to errors produced by a specific PDF, please always include the PDF by providing a URL where contributors can download it. Without a PDF for reproduction, such issues will be closed. We understand that many PDFs contain sensitive information, however having a PDF is essential to resolving the issue and building our regression testing suite. If possible, try creating a reduced example exhibiting the problem but not containing sensitive data. Also small PDFs are best suited for our regression testing. If an important issue only shows on sensitive PDFs, contributors might be willing to accept these PDFs via a secure exchange.
+
+The issue tracking system is designed to record a single technical problem. A bug report is something where a developer/contributor can work on. The GitHub issue tracker is not a good place for general, not well thought out or unworkable ideas. Most likely a discussion-type issue will not be addressed for a long time or closed as invalid. The best place for general discussions is our Matrix room at https://chat.mozilla.org/#/room/#pdfjs:mozilla.org.
+
+If you are developing a custom solution, first check the examples at https://github.com/mozilla/pdf.js#learning and search existing issues. If this does not help, please prepare a short well-documented example that demonstrates the problem and make it accessible online on your website, JS Bin, GitHub, etc. before opening a new issue or contacting us in the Matrix room -- keep in mind that just code snippets won't help us troubleshoot the problem.
+
+Note that the translations for PDF.js in the `l10n` folder are imported from the Nightly channel of Mozilla Firefox, such that we don't have to maintain them ourselves. This means that we will not accept pull requests that add new languages and/or modify existing translations, unless the corresponding changes have been made in Mozilla Firefox first.
+
+See also:
+- https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions
+- https://github.com/mozilla/pdf.js/wiki/Contributing
+- https://github.com/mozilla/pdf.js/blob/master/README.md

+ 17 - 0
pdf.js/.github/ISSUE_TEMPLATE.md

@@ -0,0 +1,17 @@
+Attach (recommended) or Link to PDF file here:
+
+Configuration:
+- Web browser and its version:
+- Operating system and its version:
+- PDF.js version:
+- Is a browser extension:
+
+Steps to reproduce the problem:
+1. 
+2.
+
+What is the expected behavior? (add screenshot)
+
+What went wrong? (add screenshot)
+
+Link to a viewer (if hosted on a site other than mozilla.github.io/pdf.js or as Firefox/Chrome extension):

+ 8 - 0
pdf.js/.github/dependabot.yml

@@ -0,0 +1,8 @@
+version: 2
+updates:
+  - package-ecosystem: "github-actions"
+    directory: "/"
+    schedule:
+      interval: "weekly"
+    labels:
+      - "dependencies"

+ 27 - 0
pdf.js/.github/workflows/ci.yml

@@ -0,0 +1,27 @@
+name: CI
+on: [push, pull_request]
+permissions:
+  contents: read
+
+jobs:
+  test:
+    name: Test
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Checkout repository
+        uses: actions/checkout@v3
+
+      - name: Use Node.js 16 LTS
+        uses: actions/setup-node@v3
+        with:
+          node-version: '16'
+
+      - name: Install Gulp
+        run: npm install -g gulp-cli
+
+      - name: Install other dependencies
+        run: npm install -f
+
+      - name: Run tests
+        run: gulp ci-test

+ 33 - 0
pdf.js/.github/workflows/codeql.yml

@@ -0,0 +1,33 @@
+name: CodeQL
+on: [push, pull_request]
+permissions:
+  contents: read
+
+jobs:
+  analyze:
+    name: Analyze
+    runs-on: ubuntu-latest
+
+    permissions:
+      security-events: write
+
+    strategy:
+      fail-fast: false
+      matrix:
+        language: [javascript]
+
+    steps:
+      - name: Checkout repository
+        uses: actions/checkout@v3
+
+      - name: Initialize CodeQL
+        uses: github/codeql-action/init@v2
+        with:
+          languages: ${{ matrix.language }}
+          queries: security-and-quality
+
+      - name: Autobuild CodeQL
+        uses: github/codeql-action/autobuild@v2
+
+      - name: Perform CodeQL analysis
+        uses: github/codeql-action/analyze@v2

+ 9 - 0
pdf.js/.gitignore

@@ -0,0 +1,9 @@
+*~
+local.mk
+build/
+tags
+.DS_Store
+Makefile
+node_modules/
+examples/node/svgdump/
+examples/node/pdf2png/*.png

+ 3 - 0
pdf.js/.gitmodules

@@ -0,0 +1,3 @@
+[submodule "test/ttx/fonttools-code"]
+	path = test/ttx/fonttools-code
+	url = https://github.com/behdad/fonttools.git

+ 7 - 0
pdf.js/.gitpod.Dockerfile

@@ -0,0 +1,7 @@
+FROM gitpod/workspace-full-vnc
+
+USER gitpod
+
+RUN sudo apt-get update && \
+    sudo apt-get install -yq firefox && \
+    sudo rm -rf /var/lib/apt/lists/*

+ 13 - 0
pdf.js/.gitpod.yml

@@ -0,0 +1,13 @@
+image:
+  file: .gitpod.Dockerfile
+tasks:
+  - command: |
+      gp await-port 8888 && gp preview $(gp url 8888)/web/viewer.html && echo '[{"name": "Firefox","path": "/usr/bin/firefox"}]' | jq '.' > test/resources/browser_manifests/browser_manifest.json
+
+  - init: npm install -g gulp-cli && npm install
+    command: gulp server
+ports:
+  - port: 8888
+    onOpen: ignore
+  - port: 6080
+    onOpen: ignore

+ 1 - 0
pdf.js/.mailmap

@@ -0,0 +1 @@
+Michał Gołębiowski-Owczarek <m.goleb@gmail.com>

+ 9 - 0
pdf.js/.prettierrc

@@ -0,0 +1,9 @@
+{
+  "arrowParens": "avoid",
+  "endOfLine": "lf",
+  "printWidth": 80,
+  "semi": true,
+  "tabWidth": 2,
+  "trailingComma": "es5",
+  "useTabs": false
+}

+ 14 - 0
pdf.js/.stylelintignore

@@ -0,0 +1,14 @@
+build/
+l10n/
+docs/
+node_modules/
+external/bcmaps/
+external/webL10n/
+external/builder/fixtures/
+external/builder/fixtures_esprima/
+external/quickjs/
+src/shared/cffStandardStrings.js
+src/shared/fonts_utils.js
+test/tmp/
+test/pdfs/
+*~/

+ 18 - 0
pdf.js/.stylelintrc

@@ -0,0 +1,18 @@
+{
+  "plugins": [
+    "stylelint-prettier"
+  ],
+
+  "extends": [
+    "stylelint-prettier/recommended"
+  ],
+
+
+  "rules": {
+    "block-no-empty": true,
+    "length-zero-no-unit": [true, {
+      ignore: ["custom-properties"]
+    }],
+    "shorthand-property-no-redundant-values": true,
+  },
+}

+ 28 - 0
pdf.js/AUTHORS

@@ -0,0 +1,28 @@
+This is an (incomplete) list of people who have contributed to the
+codebase which lives in this repository. If you make a contribution
+here, you may add your name and, optionally, email address in the
+appropriate place.
+
+Adil Allawi <@ironymark>
+Andreas Gal <gal@mozilla.com>
+Artur Adib <aadib@mozilla.com>
+Brendan Dahl <bdahl@mozilla.com>
+Bill Walker <bwalker@mozilla.com>
+Chris G Jones <cjones@mozilla.com>
+David Quintana <gigaherz@gmail.com>
+Felix Kälberer <@fkaelberer>
+Jakob Miland <saebekassebil@gmail.com>
+Jonas Jenwald <jonas.jenwald@gmail.com>
+Julian Viereck
+Justin D'Arcangelo <justindarc@gmail.com>
+Kalervo Kujala
+Michał Gołębiowski-Owczarek <m.goleb@gmail.com>
+Ophir Lojkine <@lovasoa>
+Rob Wu <rob@robwu.nl>
+Shaon Barman <shaon.barman@gmail.com>
+Sehyun Park <premed055515@gmail.com>
+Tim van der Meij <info@timvandermeij.nl>
+Vivin Paliath <vivin.paliath@gmail.com>
+Vivien Nicolas <21@vingtetun.org>
+Yury Delendik <ydelendik@mozilla.com>
+waddlesplash <@waddlesplash>

+ 15 - 0
pdf.js/CODE_OF_CONDUCT.md

@@ -0,0 +1,15 @@
+# Community Participation Guidelines
+
+This repository is governed by Mozilla's code of conduct and etiquette guidelines. 
+For more details, please read the
+[Mozilla Community Participation Guidelines](https://www.mozilla.org/about/governance/policies/participation/). 
+
+## How to Report
+For more information on how to report violations of the Community Participation Guidelines, please read our '[How to Report](https://www.mozilla.org/about/governance/policies/participation/reporting/)' page.
+
+<!--
+## Project Specific Etiquette
+
+In some cases, there will be additional project etiquette i.e.: (https://bugzilla.mozilla.org/page.cgi?id=etiquette.html).
+Please update for your project.
+-->

+ 5 - 0
pdf.js/EXPORT

@@ -0,0 +1,5 @@
+PDF.js is publicly available software not subject to the Export Administration
+Regulations (EAR) per EAR 734.3(b) and 734.7. Because PDF.js is not subject
+to the EAR it does not have an Export Control Classification Number (ECCN).
+Mozilla has completed the notification for PDF.js publicly available encryption
+source code per EAR 742.15(b).

+ 177 - 0
pdf.js/LICENSE

@@ -0,0 +1,177 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS

+ 144 - 0
pdf.js/README.md

@@ -0,0 +1,144 @@
+# PDF.js [![Build Status](https://github.com/mozilla/pdf.js/workflows/CI/badge.svg?branch=master)](https://github.com/mozilla/pdf.js/actions?query=workflow%3ACI+branch%3Amaster)
+
+[PDF.js](https://mozilla.github.io/pdf.js/) is a Portable Document Format (PDF) viewer that is built with HTML5.
+
+PDF.js is community-driven and supported by Mozilla. Our goal is to
+create a general-purpose, web standards-based platform for parsing and
+rendering PDFs.
+
+## Contributing
+
+PDF.js is an open source project and always looking for more contributors. To
+get involved, visit:
+
++ [Issue Reporting Guide](https://github.com/mozilla/pdf.js/blob/master/.github/CONTRIBUTING.md)
++ [Code Contribution Guide](https://github.com/mozilla/pdf.js/wiki/Contributing)
++ [Frequently Asked Questions](https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions)
++ [Good Beginner Bugs](https://github.com/mozilla/pdf.js/issues?direction=desc&labels=good-beginner-bug&page=1&sort=created&state=open)
++ [Projects](https://github.com/mozilla/pdf.js/projects)
+
+Feel free to stop by our [Matrix room](https://chat.mozilla.org/#/room/#pdfjs:mozilla.org) for questions or guidance.
+
+## Getting Started
+
+### Online demo
+
+Please note that the "Modern browsers" version assumes native support for
+features such as optional chaining, nullish coalescing,
+and private `class` fields/methods; please also see [this wiki page](https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support).
+
++ Modern browsers: https://mozilla.github.io/pdf.js/web/viewer.html
+
++ Older browsers: https://mozilla.github.io/pdf.js/legacy/web/viewer.html
+
+### Browser Extensions
+
+#### Firefox
+
+PDF.js is built into version 19+ of Firefox.
+
+#### Chrome
+
++ Build Your Own - Get the code as explained below and issue `gulp chromium`. Then open
+Chrome, go to `Tools > Extension` and load the (unpackaged) extension from the
+directory `build/chromium`.
+
+## Getting the Code
+
+To get a local copy of the current code, clone it using git:
+
+    $ git clone https://github.com/mozilla/pdf.js.git
+    $ cd pdf.js
+
+Next, install Node.js via the [official package](https://nodejs.org) or via
+[nvm](https://github.com/creationix/nvm). You need to install the gulp package
+globally (see also [gulp's getting started](https://github.com/gulpjs/gulp/tree/master/docs/getting-started)):
+
+    $ npm install -g gulp-cli
+
+If everything worked out, install all dependencies for PDF.js:
+
+    $ npm install
+
+Finally, you need to start a local web server as some browsers do not allow opening
+PDF files using a `file://` URL. Run:
+
+    $ gulp server
+
+and then you can open:
+
++ http://localhost:8888/web/viewer.html
+
+Please keep in mind that this requires a modern and fully up-to-date browser; refer to [Building PDF.js](https://github.com/mozilla/pdf.js/blob/master/README.md#building-pdfjs) for non-development usage of the PDF.js library.
+
+It is also possible to view all test PDF files on the right side by opening:
+
++ http://localhost:8888/test/pdfs/?frame
+
+## Building PDF.js
+
+In order to bundle all `src/` files into two production scripts and build the generic
+viewer, run:
+
+    $ gulp generic
+
+If you need to support older browsers, run:
+
+    $ gulp generic-legacy
+
+This will generate `pdf.js` and `pdf.worker.js` in the `build/generic/build/` directory (respectively `build/generic-legacy/build/`).
+Both scripts are needed but only `pdf.js` needs to be included since `pdf.worker.js` will
+be loaded by `pdf.js`. The PDF.js files are large and should be minified for production.
+
+## Using PDF.js in a web application
+
+To use PDF.js in a web application you can choose to use a pre-built version of the library
+or to build it from source. We supply pre-built versions for usage with NPM and Bower under
+the `pdfjs-dist` name. For more information and examples please refer to the
+[wiki page](https://github.com/mozilla/pdf.js/wiki/Setup-pdf.js-in-a-website) on this subject.
+
+## Including via a CDN
+
+PDF.js is hosted on several free CDNs:
+ - https://www.jsdelivr.com/package/npm/pdfjs-dist
+ - https://cdnjs.com/libraries/pdf.js
+ - https://unpkg.com/pdfjs-dist/
+
+## Learning
+
+You can play with the PDF.js API directly from your browser using the live demos below:
+
++ [Interactive examples](https://mozilla.github.io/pdf.js/examples/index.html#interactive-examples)
+
+More examples can be found in the [examples folder](https://github.com/mozilla/pdf.js/tree/master/examples/). Some of them are using the pdfjs-dist package, which can be built and installed in this repo directory via `gulp dist-install` command.
+
+For an introduction to the PDF.js code, check out the presentation by our
+contributor Julian Viereck:
+
++ https://www.youtube.com/watch?v=Iv15UY-4Fg8
+
+More learning resources can be found at:
+
++ https://github.com/mozilla/pdf.js/wiki/Additional-Learning-Resources
+
+The API documentation can be found at:
+
++ https://mozilla.github.io/pdf.js/api/
+
+## Questions
+
+Check out our FAQs and get answers to common questions:
+
++ https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions
+
+Talk to us on Matrix:
+
++ https://chat.mozilla.org/#/room/#pdfjs:mozilla.org
+
+File an issue:
+
++ https://github.com/mozilla/pdf.js/issues/new
+
+Follow us on Twitter: @pdfjs
+
++ https://twitter.com/pdfjs

+ 20 - 0
pdf.js/docs/config.json

@@ -0,0 +1,20 @@
+{
+  "locals": {
+    "url": "http://localhost:8080",
+    "name": "PDF.js Documentation",
+    "description": ""
+  },
+  "require": {
+    "typogr": "typogr"
+  },
+  "jade": {
+    "pretty": true
+  },
+  "markdown": {
+    "smartLists": true,
+    "smartypants": true
+  },
+  "plugins": [
+    "./plugins/wintersmith-makerelative.coffee"
+  ]
+}

+ 8 - 0
pdf.js/docs/contents/api/index.md

@@ -0,0 +1,8 @@
+---
+title: API
+template: layout.jade
+---
+
+# API
+
+We're currently working on <a href="draft/index.html">better API docs</a>, but the API is well documented in [api.js](https://github.com/mozilla/pdf.js/blob/master/src/display/api.js).

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 6 - 0
pdf.js/docs/contents/css/bootstrap.min.css


+ 119 - 0
pdf.js/docs/contents/css/main.css

@@ -0,0 +1,119 @@
+body {
+}
+.starter-template {
+  padding: 0 15px;
+}
+.navbar-brand {
+  padding: 4px 15px;
+}
+.navbar-brand img {
+  height: 42px;
+}
+.navbar {
+  border-color: #e5e7e8;
+}
+.navbar-default .navbar-nav > .active > a,
+.navbar-default .navbar-nav > .active > a:hover,
+.navbar-default .navbar-nav > .active > a:focus  {
+  background-color: #fff;
+  border: 1px solid #e5e7e8;
+  border-width: 0 1px;
+  position: relative;
+  top: 1px;
+}
+
+footer {
+  padding-top: 40px;
+  padding-bottom: 40px;
+  margin-top: 100px;
+  color: #777;
+  text-align: center;
+  border-top: 1px solid #E5E5E5;
+}
+
+/* code styling */
+
+code {
+  font-family: 'Anonymous Pro', monospace;
+  font-size: 0.85em;
+  color: #000;
+}
+
+pre code {
+  display: block;
+  line-height: 1.1;
+}
+
+p code {
+  padding: 0.1em 0.3em 0.2em;
+  border-radius: 0.3em;
+  position: relative;
+  top: -0.15em;
+  background: #444;
+  color: #fff;
+  white-space: nowrap;
+}
+
+/* syntax hl stuff */
+
+code.lang-markdown {
+  color: #424242;
+}
+
+code.lang-markdown .header,
+code.lang-markdown .strong {
+  font-weight: bold;
+}
+
+code.lang-markdown .emphasis {
+  font-style: italic;
+}
+
+code.lang-markdown .horizontal_rule,
+code.lang-markdown .link_label,
+code.lang-markdown .code,
+code.lang-markdown .header,
+code.lang-markdown .link_url {
+  color: #555;
+}
+
+code.lang-markdown .blockquote,
+code.lang-markdown .bullet {
+  color: #bbb;
+}
+
+/* Tomorrow Theme */
+/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
+/* Original theme - https://github.com/chriskempson/tomorrow-theme */
+/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
+.tomorrow-comment, pre .comment, pre .title {
+  color: #8e908c;
+}
+
+.tomorrow-red, pre .variable, pre .attribute, pre .tag, pre .regexp, pre .ruby .constant, pre .xml .tag .title, pre .xml .pi, pre .xml .doctype, pre .html .doctype, pre .css .id, pre .css .class, pre .css .pseudo {
+  color: #c82829;
+}
+
+.tomorrow-orange, pre .number, pre .preprocessor, pre .built_in, pre .literal, pre .params, pre .constant {
+  color: #f5871f;
+}
+
+.tomorrow-yellow, pre .class, pre .ruby .class .title, pre .css .rules .attribute {
+  color: #eab700;
+}
+
+.tomorrow-green, pre .string, pre .value, pre .inheritance, pre .header, pre .ruby .symbol, pre .xml .cdata {
+  color: #718c00;
+}
+
+.tomorrow-aqua, pre .css .hexcolor {
+  color: #3e999f;
+}
+
+.tomorrow-blue, pre .function, pre .python .decorator, pre .python .title, pre .ruby .function .title, pre .ruby .title .keyword, pre .perl .sub, pre .javascript .title, pre .coffeescript .title {
+  color: #4271ae;
+}
+
+.tomorrow-purple, pre .keyword, pre .javascript .function {
+  color: #8959a8;
+}

+ 99 - 0
pdf.js/docs/contents/examples/index.md

@@ -0,0 +1,99 @@
+---
+title: Examples
+template: layout.jade
+---
+
+## Hello World Walkthrough
+
+[Full source](https://github.com/mozilla/pdf.js/blob/master/examples/learning/helloworld.html)
+
+PDF.js heavily relies on the use of [Promises](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise). If promises are new to you, it's recommended you become familiar with them before continuing on.
+
+This tutorial shows how PDF.js can be used as a library in a web browser.
+[examples/](https://github.com/mozilla/pdf.js/tree/master/examples) provides more examples, including usage in Node.js (at [examples/node/](https://github.com/mozilla/pdf.js/tree/master/examples/node)).
+
+### Document
+
+The object structure of PDF.js loosely follows the structure of an actual PDF. At the top level there is a document object. From the document, more information and individual pages can be fetched. To get the document:
+
+```js
+pdfjsLib.getDocument('helloworld.pdf')
+```
+
+Remember though that PDF.js uses promises, and the above will return a `PDFDocumentLoadingTask` instance that has a `promise` property which is resolved with the document object.
+
+```js
+var loadingTask = pdfjsLib.getDocument('helloworld.pdf');
+loadingTask.promise.then(function(pdf) {
+  // you can now use *pdf* here
+});
+```
+
+### Page
+Now that we have the document, we can get a page. Again, this uses promises.
+
+```js
+pdf.getPage(1).then(function(page) {
+  // you can now use *page* here
+});
+```
+
+### Rendering the Page
+Each PDF page has its own viewport which defines the size in pixels(72DPI) and initial rotation. By default the viewport is scaled to the original size of the PDF, but this can be changed by modifying the viewport. When the viewport is created, an initial transformation matrix will also be created that takes into account the desired scale, rotation, and it transforms the coordinate system (the 0,0 point in PDF documents the bottom-left whereas canvas 0,0 is top-left).
+
+```js
+var scale = 1.5;
+var viewport = page.getViewport({ scale: scale, });
+// Support HiDPI-screens.
+var outputScale = window.devicePixelRatio || 1;
+
+var canvas = document.getElementById('the-canvas');
+var context = canvas.getContext('2d');
+
+canvas.width = Math.floor(viewport.width * outputScale);
+canvas.height = Math.floor(viewport.height * outputScale);
+canvas.style.width = Math.floor(viewport.width) + "px";
+canvas.style.height =  Math.floor(viewport.height) + "px";
+
+var transform = outputScale !== 1
+  ? [outputScale, 0, 0, outputScale, 0, 0]
+  : null;
+
+var renderContext = {
+  canvasContext: context,
+  transform: transform,
+  viewport: viewport
+};
+page.render(renderContext);
+```
+
+Alternatively, if you want the canvas to render to a certain pixel size you could do the following:
+
+```js
+var desiredWidth = 100;
+var viewport = page.getViewport({ scale: 1, });
+var scale = desiredWidth / viewport.width;
+var scaledViewport = page.getViewport({ scale: scale, });
+```
+
+## Interactive examples
+
+### Hello World with document load error handling
+
+The example demonstrates how promises can be used to handle errors during loading.
+It also demonstrates how to wait until a page is loaded and rendered.
+
+<script async src="//jsfiddle.net/pdfjs/9engc9mw/embed/js,html,css,result/"></script>
+
+### Hello World using base64 encoded PDF
+
+The PDF.js can accept any decoded base64 data as an array.
+
+<script async src="//jsfiddle.net/pdfjs/cq0asLqz/embed/js,html,css,result/"></script>
+
+### Previous/Next example
+
+The same canvas cannot be used to perform to draw two pages at the same time --
+the example demonstrates how to wait on previous operation to be complete.
+
+<script async src="//jsfiddle.net/pdfjs/wagvs9Lf/embed/js,html,css,result/"></script>

+ 128 - 0
pdf.js/docs/contents/getting_started/index.md

@@ -0,0 +1,128 @@
+---
+title: Getting Started
+template: layout.jade
+---
+
+# Getting Started
+
+An introduction to PDF.js with examples.
+
+## Introduction
+
+Before downloading PDF.js please take a moment to understand the different layers of the PDF.js project.
+
+<table class="table">
+  <thead>
+    <tr>
+      <th>Layer</th>
+      <th>About</th>
+    </tr>
+  </thead>
+  <tbody>
+    <tr>
+      <td>Core</td>
+      <td>The core layer is where a binary PDF is parsed and interpreted. This layer is the foundation for all subsequent layers. It is not documented here because using it directly is considered an advanced usage and the API is likely to change. For an example of using the core layer see the <a href="https://github.com/brendandahl/pdf.js.utils/tree/master/browser">PDF Object Browser</a>.
+      </td>
+    </tr>
+    <tr>
+      <td>Display</td>
+      <td>The display layer takes the core layer and exposes an easier to use API to render PDFs and get other information out of a document. This API is what the version number is based on.</td>
+    </tr>
+    <tr>
+      <td>Viewer</td>
+      <td>The viewer is built on the display layer and is the UI for PDF viewer in Firefox and the other browser extensions within the project. It can be a good starting point for building your own viewer. <em>However, we do ask if you plan to embed the viewer in your own site, that it not just be an unmodified version. Please re-skin it or build upon it.</em></td>
+    </tr>
+  </tbody>
+</table>
+
+## Download
+
+Please refer to [this wiki page](https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support) for information about supported browsers.
+
+<div class="row">
+  <div class="col-md-4">
+    <h3>Prebuilt (modern browsers)</h3>
+    <p>
+      Includes the generic build of PDF.js and the viewer.
+    </p>
+    <a type="button" class="btn btn-primary" href="https://github.com/mozilla/pdf.js/releases/download/vSTABLE_VERSION/pdfjs-STABLE_VERSION-dist.zip">Stable (vSTABLE_VERSION)</a>
+  </div>
+  <div class="col-md-4">
+    <h3>Prebuilt (older browsers)</h3>
+    <p>
+      Includes the generic build of PDF.js and the viewer.
+    </p>
+    <a type="button" class="btn btn-primary" href="https://github.com/mozilla/pdf.js/releases/download/vSTABLE_VERSION/pdfjs-STABLE_VERSION-legacy-dist.zip">Stable (vSTABLE_VERSION)</a>
+  </div>
+  <div class="col-md-4">
+    <h3>Source</h3>
+    To get a local copy of the current code, clone it using git:
+    <pre><code>$ git clone https://github.com/mozilla/pdf.js.git
+$ cd pdf.js
+</code></pre>
+  </div>
+</div>
+
+## Including via a CDN
+
+PDF.js is hosted on several free CDNs:
+ - https://www.jsdelivr.com/package/npm/pdfjs-dist
+ - https://cdnjs.com/libraries/pdf.js
+ - https://unpkg.com/pdfjs-dist/
+
+## File Layout Overview
+
+Note that we only mention the most relevant files and folders.
+
+### Prebuilt
+
+```
+├── build/
+│   ├── pdf.js                             - display layer
+│   ├── pdf.js.map                         - display layer's source map
+│   ├── pdf.worker.js                      - core layer
+│   └── pdf.worker.js.map                  - core layer's source map
+├── web/
+│   ├── cmaps/                             - character maps (required by core)
+│   ├── compressed.tracemonkey-pldi-09.pdf - PDF file for testing purposes
+│   ├── debugger.js                        - helpful debugging features
+│   ├── images/                            - images for the viewer and annotation icons
+│   ├── locale/                            - translation files
+│   ├── viewer.css                         - viewer style sheet
+│   ├── viewer.html                        - viewer layout
+│   ├── viewer.js                          - viewer layer
+│   └── viewer.js.map                      - viewer layer's source map
+└── LICENSE
+```
+
+### Source
+
+```
+├── docs/                                  - website source code
+├── examples/                              - simple usage examples
+├── extensions/                            - browser extension source code
+├── external/                              - third party code
+├── l10n/                                  - translation files
+├── src/
+│   ├── core/                              - core layer
+│   ├── display/                           - display layer
+│   ├── shared/                            - shared code between the core and display layers
+│   ├── interfaces.js                      - interface definitions for the core/display layers
+│   ├── pdf.*.js                           - wrapper files for bundling
+│   └── worker_loader.js                   - used for developer builds to load worker files
+├── test/                                  - unit, font, reference, and integration tests
+├── web/                                   - viewer layer
+├── LICENSE
+├── README.md
+├── gulpfile.js                            - build scripts/logic
+├── package-lock.json                      - pinned dependency versions
+└── package.json                           - package definition and dependencies
+```
+
+## Trying the Viewer
+
+With the prebuilt or source version, open `web/viewer.html` in a browser and the test pdf should load. Note: the worker is not enabled for file:// urls, so use a server. If you're using the source build and have node, you can run `gulp server`.
+
+## More Information
+
+For a further walkthrough of a minimal viewer, see the hello world example. More documentation can be found in our [wiki](https://github.com/mozilla/pdf.js/wiki) too.

BIN
pdf.js/docs/contents/images/favicon.ico


+ 41 - 0
pdf.js/docs/contents/images/logo.svg

@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+   xmlns="http://www.w3.org/2000/svg"
+   width="64"
+   height="64">
+  <path
+     d="M 4.8364028,0.4891005 32.096378,4.5726641 59.163597,0.4891005 54.680408,57.805097 32.096378,63.510899 8.3116209,57.805097 z"
+     style="fill:#e5e7e8;fill-opacity:1;fill-rule:nonzero;stroke:#cccccc" />
+  <path
+     d="M 32.096378,10.745857 53.925414,6.8301117 51.016574,53.81906 32.096378,58.517955 z"
+     style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none" />
+  <rect
+     width="34.027256"
+     height="19.136194"
+     x="3.7557135"
+     y="22.431904"
+     style="fill:#ff2600;fill-opacity:1;fill-rule:nonzero;stroke:none" />
+  <rect
+     width="23.480518"
+     height="19.136194"
+     x="36.763767"
+     y="22.431904"
+     style="fill:#ff501a;fill-opacity:1;fill-rule:nonzero;stroke:none" />
+  <g transform="matrix(0.42778543,0,0,0.42778543,58.617711,9.6737064)">
+    <path
+       d="m -120.53125,34.59375 0,35.1875 6.53125,0 0,-5.9375 0,-5.96875 8.875,0 4.15625,-3.71875 0,-7.71875 0,-7.71875 -4.21875,-4.125 -15.34375,0 z m 6.53125,6.8125 6.21875,0 0,10.21875 -6.21875,0 0,-10.21875 z"
+       style="fill:#ffffff;fill-opacity:1" />
+    <path
+       d="m -98.125,34.59375 0,35.1875 16.125,0 3.75,-3.625 0,-27.96875 -3.96875,-3.59375 -15.90625,0 z m 6.8125,6.8125 6.8125,0 0,21.5625 -6.8125,0 0,-21.5625 z"       id="path3056"
+       style="fill:#ffffff;fill-opacity:1" />
+    <path
+       d="m -74.856072,34.602929 c 5.485697,0 10.971394,0 16.457091,0 0,2.269943 0,4.539887 0,6.80983 -3.404915,0 -6.809831,0 -10.214746,0 0,2.472069 0,4.944138 0,7.416206 2.93201,0.110496 5.864021,-0.110494 8.796031,0 l 0,3.366025 0,3.375914 c -2.93201,0.110495 -5.864021,-0.110495 -8.796031,0 l 0,7.146446 0,7.069702 c -2.080782,0 -4.161563,0 -6.242345,0 0,-11.728041 0,-23.456082 0,-35.184123 z"
+       style="fill:#ffffff;fill-opacity:1" />
+    <path
+       d="m -42.8813,67.942723 -2.181762,-1.844329 c 0,-1.986871 0,-3.973742 0,-5.960613 2.175363,6.7e-4 4.350725,0.0013 6.526088,0.002 0,0.94581 0,1.891619 0,2.837429 1.891619,0 3.783239,0 5.674858,0 0,-9.458098 0,-18.916195 0,-28.374293 2.175363,-1.26e-4 4.350725,-2.52e-4 6.526088,-3.78e-4 0,10.498614 0,20.997229 0,31.495843 -1.454508,1.229554 -2.909019,2.459106 -4.363529,3.688658 -3.333325,0 -6.666651,0 -9.999976,0 -0.727237,-0.614768 -1.454563,-1.229595 -2.181767,-1.844308 z"
+       style="fill:#ffffff;fill-opacity:1" />
+    <path
+       d="m -21.316836,67.942723 -2.109122,-1.844329 0,-5.978379 c 2.061011,0 4.392437,0.01978 6.453448,0.01978 0,0.94581 0,1.891619 0,2.837429 2.269943,0 4.539887,0 6.80983,0 0,-2.459105 0,-4.918211 0,-7.377316 -3.196954,0 -6.393909,0 -9.590863,0 l -3.745055,-3.688659 0,-6.80983 0,-6.80983 3.745055,-3.688658 c 3.863156,0 7.726313,0 11.5894692,0 l 4.2511106,3.688658 c -0.00204,1.797039 -0.00472,3.594077 -0.00737,5.391115 -2.0807816,0 -4.1615632,0 -6.2423448,0 0,-0.756648 0,-1.513295 0,-2.269943 -2.269943,0 -4.539887,0 -6.80983,0 0,2.459105 0,4.918211 0,7.377316 2.990126,0 5.980253,0 8.9703792,0 1.3605964,1.204585 4.0817956,3.613749 4.0817956,3.613749 0,4.555246 0,9.110492 0,13.665738 l -2.0892845,1.858745 -2.0892901,1.858745 -5.5180792,0 -5.51808,0 z"
+       style="fill:#ffffff;fill-opacity:1" />
+  </g>
+</svg>

+ 14 - 0
pdf.js/docs/contents/index.md

@@ -0,0 +1,14 @@
+---
+title: PDF.js
+template: layout.jade
+---
+
+
+<h1 class="text-center">PDF.js</h1>
+<p class="text-center" style="font-size: 20px">A general-purpose, web standards-based platform for parsing and rendering PDFs.
+</p>
+<p class="text-center">
+  <a type="button" class="btn btn-lg btn-default" href="getting_started/#download">Download</a>
+  <a type="button" class="btn btn-lg btn-default" href="https://github.com/mozilla/pdf.js#online-demo">Demo</a>
+  <a type="button" class="btn btn-lg btn-default" href="https://github.com/mozilla/pdf.js">GitHub Project</a>
+</p>

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 5 - 0
pdf.js/docs/contents/js/bootstrap.min.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1 - 0
pdf.js/docs/contents/js/jquery-2.1.0.min.js


+ 15 - 0
pdf.js/docs/plugins/wintersmith-makerelative.coffee

@@ -0,0 +1,15 @@
+module.exports = (env, callback) ->
+  count = (string, substr) ->
+    num = pos = 0
+    return 1/0 unless substr.length
+    num++ while pos = 1 + string.indexOf(substr, pos)
+    num
+
+  env.helpers.makeRelative = (source, dest) ->
+    return dest unless dest.indexOf("/") == 0
+    depth = count(source, '/') # 1 being /
+    ret = ""
+    ret += "../" while depth = depth - 1
+    ret + dest.substring(1)
+
+  callback()

+ 52 - 0
pdf.js/docs/templates/layout.jade

@@ -0,0 +1,52 @@
+- makeRelative = env.helpers.makeRelative
+doctype html
+html(lang='en')
+  head
+    meta(charset='utf-8')
+    meta(name='viewport', content='width=device-width, initial-scale=1.0')
+    meta(name='description', content='A general-purpose, web standards-based platform for parsing and rendering PDFs.')
+    meta(name='author', content='')
+    link(rel='shortcut icon', href=makeRelative(page.url, '/images/favicon.ico'))
+    title=page.title
+    // Bootstrap core CSS
+    link(href=makeRelative(page.url, '/css/bootstrap.min.css'), rel='stylesheet')
+    // Custom styles for this template
+    link(href=makeRelative(page.url, '/css/main.css'), rel='stylesheet')
+
+  body
+    header.navbar.navbar-default.navbar-static-top
+      .container
+          .navbar-header
+              button.navbar-toggle(type='button', data-toggle='collapse', data-target='.navbar-collapse')
+                  span.icon-bar
+                  span.icon-bar
+                  span.icon-bar
+              a.navbar-brand(href='#')
+                img(src=makeRelative(page.url, '/images/logo.svg'))
+          .collapse.navbar-collapse
+              ul.nav.navbar-nav
+                  li(class=(page.url === '/' ? 'active' : ''))
+                      a(href=makeRelative(page.url, '/')) Home
+                  li(class=(page.url === '/getting_started/' ? 'active' : ''))
+                      a(href=makeRelative(page.url, '/getting_started/')) Getting Started
+                  li(class=(page.url === '/examples/' ? 'active' : ''))
+                      a(href=makeRelative(page.url, '/examples/')) Examples
+                  li
+                      a(href='https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions') FAQ
+                  li(class=(page.url === '/api/' ? 'active' : ''))
+                      a(href=makeRelative(page.url, '/api/')) API
+
+    .container
+      .starter-template
+        section.content!= typogr(page.html).typogrify()
+
+    .container
+      footer
+        p &copy;Mozilla and individual contributors
+        :markdown-it
+          PDF.js is licensed under [Apache](https://github.com/mozilla/pdf.js/blob/master/LICENSE),
+          documentation is licensed under [CC BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/)
+
+    // Bootstrap core JavaScript
+    script(src=makeRelative(page.url, '/js/jquery-2.1.0.min.js'))
+    script(src=makeRelative(page.url, '/js/bootstrap.min.js'))

+ 11 - 0
pdf.js/examples/.eslintrc

@@ -0,0 +1,11 @@
+{
+  "extends": [
+    "../.eslintrc"
+  ],
+
+  "globals": {
+    "pdfjsImageDecoders": false,
+    "pdfjsLib": false,
+    "pdfjsViewer": false,
+  },
+}

+ 43 - 0
pdf.js/examples/components/pageviewer.html

@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<!--
+Copyright 2014 Mozilla Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<html dir="ltr" mozdisallowselectionprint>
+<head>
+  <meta charset="utf-8">
+  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
+  <meta name="google" content="notranslate">
+  <title>PDF.js page viewer using built components</title>
+
+  <style>
+    body {
+      background-color: #808080;
+      margin: 0;
+      padding: 0;
+    }
+  </style>
+
+  <link rel="stylesheet" href="../../node_modules/pdfjs-dist/web/pdf_viewer.css">
+
+  <script src="../../node_modules/pdfjs-dist/build/pdf.js"></script>
+  <script src="../../node_modules/pdfjs-dist/web/pdf_viewer.js"></script>
+</head>
+
+<body tabindex="1">
+  <div id="pageContainer" class="pdfViewer singlePageView"></div>
+
+  <script src="pageviewer.js"></script>
+</body>
+</html>

+ 89 - 0
pdf.js/examples/components/pageviewer.js

@@ -0,0 +1,89 @@
+/* Copyright 2014 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+"use strict";
+
+if (!pdfjsLib.getDocument || !pdfjsViewer.PDFPageView) {
+  // eslint-disable-next-line no-alert
+  alert("Please build the pdfjs-dist library using\n  `gulp dist-install`");
+}
+
+// The workerSrc property shall be specified.
+//
+pdfjsLib.GlobalWorkerOptions.workerSrc =
+  "../../node_modules/pdfjs-dist/build/pdf.worker.js";
+
+// Some PDFs need external cmaps.
+//
+const CMAP_URL = "../../node_modules/pdfjs-dist/cmaps/";
+const CMAP_PACKED = true;
+
+const DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf";
+const PAGE_TO_VIEW = 1;
+const SCALE = 1.0;
+
+const ENABLE_XFA = true;
+
+const container = document.getElementById("pageContainer");
+
+const eventBus = new pdfjsViewer.EventBus();
+
+// Loading document.
+const loadingTask = pdfjsLib.getDocument({
+  url: DEFAULT_URL,
+  cMapUrl: CMAP_URL,
+  cMapPacked: CMAP_PACKED,
+  enableXfa: ENABLE_XFA,
+});
+(async function () {
+  const pdfDocument = await loadingTask.promise;
+  // Document loaded, retrieving the page.
+  const pdfPage = await pdfDocument.getPage(PAGE_TO_VIEW);
+
+  const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(pdfjsLib.version);
+  if (match && (match[1] | 0) >= 3 && (match[2] | 0) >= 2) {
+    // Creating the page view with default parameters.
+    const pdfPageView = new pdfjsViewer.PDFPageView({
+      container,
+      id: PAGE_TO_VIEW,
+      scale: SCALE,
+      defaultViewport: pdfPage.getViewport({ scale: SCALE }),
+      eventBus,
+    });
+    // Associate the actual page with the view, and draw it.
+    pdfPageView.setPdfPage(pdfPage);
+    return pdfPageView.draw();
+  }
+  // Creating the page view with default parameters.
+  const pdfPageView = new pdfjsViewer.PDFPageView({
+    container,
+    id: PAGE_TO_VIEW,
+    scale: SCALE,
+    defaultViewport: pdfPage.getViewport({ scale: SCALE }),
+    eventBus,
+    // We can enable text/annotation/xfa/struct-layers, as needed.
+    textLayerFactory: !pdfDocument.isPureXfa
+      ? new pdfjsViewer.DefaultTextLayerFactory()
+      : null,
+    annotationLayerFactory: new pdfjsViewer.DefaultAnnotationLayerFactory(),
+    xfaLayerFactory: pdfDocument.isPureXfa
+      ? new pdfjsViewer.DefaultXfaLayerFactory()
+      : null,
+    structTreeLayerFactory: new pdfjsViewer.DefaultStructTreeLayerFactory(),
+  });
+  // Associate the actual page with the view, and draw it.
+  pdfPageView.setPdfPage(pdfPage);
+  return pdfPageView.draw();
+})();

+ 51 - 0
pdf.js/examples/components/simpleviewer.html

@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<!--
+Copyright 2014 Mozilla Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<html dir="ltr" mozdisallowselectionprint>
+<head>
+  <meta charset="utf-8">
+  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
+  <meta name="google" content="notranslate">
+  <title>PDF.js viewer using built components</title>
+
+  <style>
+    body {
+      background-color: #808080;
+      margin: 0;
+      padding: 0;
+    }
+    #viewerContainer {
+      overflow: auto;
+      position: absolute;
+      width: 100%;
+      height: 100%;
+    }
+  </style>
+
+  <link rel="stylesheet" href="../../node_modules/pdfjs-dist/web/pdf_viewer.css">
+
+  <script src="../../node_modules/pdfjs-dist/build/pdf.js"></script>
+  <script src="../../node_modules/pdfjs-dist/web/pdf_viewer.js"></script>
+</head>
+
+<body tabindex="1">
+  <div id="viewerContainer">
+    <div id="viewer" class="pdfViewer"></div>
+  </div>
+
+  <script src="simpleviewer.js"></script>
+</body>
+</html>

+ 97 - 0
pdf.js/examples/components/simpleviewer.js

@@ -0,0 +1,97 @@
+/* Copyright 2014 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+"use strict";
+
+if (!pdfjsLib.getDocument || !pdfjsViewer.PDFViewer) {
+  // eslint-disable-next-line no-alert
+  alert("Please build the pdfjs-dist library using\n  `gulp dist-install`");
+}
+
+// The workerSrc property shall be specified.
+//
+pdfjsLib.GlobalWorkerOptions.workerSrc =
+  "../../node_modules/pdfjs-dist/build/pdf.worker.js";
+
+// Some PDFs need external cmaps.
+//
+const CMAP_URL = "../../node_modules/pdfjs-dist/cmaps/";
+const CMAP_PACKED = true;
+
+const DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf";
+// To test the AcroForm and/or scripting functionality, try e.g. this file:
+// "../../test/pdfs/160F-2019.pdf"
+
+const ENABLE_XFA = true;
+const SEARCH_FOR = ""; // try "Mozilla";
+
+const SANDBOX_BUNDLE_SRC = "../../node_modules/pdfjs-dist/build/pdf.sandbox.js";
+
+const container = document.getElementById("viewerContainer");
+
+const eventBus = new pdfjsViewer.EventBus();
+
+// (Optionally) enable hyperlinks within PDF files.
+const pdfLinkService = new pdfjsViewer.PDFLinkService({
+  eventBus,
+});
+
+// (Optionally) enable find controller.
+const pdfFindController = new pdfjsViewer.PDFFindController({
+  eventBus,
+  linkService: pdfLinkService,
+});
+
+// (Optionally) enable scripting support.
+const pdfScriptingManager = new pdfjsViewer.PDFScriptingManager({
+  eventBus,
+  sandboxBundleSrc: SANDBOX_BUNDLE_SRC,
+});
+
+const pdfViewer = new pdfjsViewer.PDFViewer({
+  container,
+  eventBus,
+  linkService: pdfLinkService,
+  findController: pdfFindController,
+  scriptingManager: pdfScriptingManager,
+});
+pdfLinkService.setViewer(pdfViewer);
+pdfScriptingManager.setViewer(pdfViewer);
+
+eventBus.on("pagesinit", function () {
+  // We can use pdfViewer now, e.g. let's change default scale.
+  pdfViewer.currentScaleValue = "page-width";
+
+  // We can try searching for things.
+  if (SEARCH_FOR) {
+    eventBus.dispatch("find", { type: "", query: SEARCH_FOR });
+  }
+});
+
+// Loading document.
+const loadingTask = pdfjsLib.getDocument({
+  url: DEFAULT_URL,
+  cMapUrl: CMAP_URL,
+  cMapPacked: CMAP_PACKED,
+  enableXfa: ENABLE_XFA,
+});
+(async function () {
+  const pdfDocument = await loadingTask.promise;
+  // Document loaded, specifying document for the viewer and
+  // the (optional) linkService.
+  pdfViewer.setDocument(pdfDocument);
+
+  pdfLinkService.setDocument(pdfDocument, null);
+})();

+ 51 - 0
pdf.js/examples/components/singlepageviewer.html

@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<!--
+Copyright 2014 Mozilla Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<html dir="ltr" mozdisallowselectionprint>
+<head>
+  <meta charset="utf-8">
+  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
+  <meta name="google" content="notranslate">
+  <title>PDF.js Single Page Viewer using built components</title>
+
+  <style>
+    body {
+      background-color: #808080;
+      margin: 0;
+      padding: 0;
+    }
+    #viewerContainer {
+      overflow: auto;
+      position: absolute;
+      width: 100%;
+      height: 100%;
+    }
+  </style>
+
+  <link rel="stylesheet" href="../../node_modules/pdfjs-dist/web/pdf_viewer.css">
+
+  <script src="../../node_modules/pdfjs-dist/build/pdf.js"></script>
+  <script src="../../node_modules/pdfjs-dist/web/pdf_viewer.js"></script>
+</head>
+
+<body tabindex="1">
+  <div id="viewerContainer">
+    <div id="viewer" class="pdfViewer"></div>
+  </div>
+
+  <script src="singlepageviewer.js"></script>
+</body>
+</html>

+ 96 - 0
pdf.js/examples/components/singlepageviewer.js

@@ -0,0 +1,96 @@
+/* Copyright 2014 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+"use strict";
+
+if (!pdfjsLib.getDocument || !pdfjsViewer.PDFSinglePageViewer) {
+  // eslint-disable-next-line no-alert
+  alert("Please build the pdfjs-dist library using\n  `gulp dist-install`");
+}
+
+// The workerSrc property shall be specified.
+//
+pdfjsLib.GlobalWorkerOptions.workerSrc =
+  "../../node_modules/pdfjs-dist/build/pdf.worker.js";
+
+// Some PDFs need external cmaps.
+//
+const CMAP_URL = "../../node_modules/pdfjs-dist/cmaps/";
+const CMAP_PACKED = true;
+
+const DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf";
+// To test the AcroForm and/or scripting functionality, try e.g. this file:
+// "../../test/pdfs/160F-2019.pdf"
+
+const ENABLE_XFA = true;
+const SEARCH_FOR = ""; // try "Mozilla";
+
+const SANDBOX_BUNDLE_SRC = "../../node_modules/pdfjs-dist/build/pdf.sandbox.js";
+
+const container = document.getElementById("viewerContainer");
+
+const eventBus = new pdfjsViewer.EventBus();
+
+// (Optionally) enable hyperlinks within PDF files.
+const pdfLinkService = new pdfjsViewer.PDFLinkService({
+  eventBus,
+});
+
+// (Optionally) enable find controller.
+const pdfFindController = new pdfjsViewer.PDFFindController({
+  eventBus,
+  linkService: pdfLinkService,
+});
+
+// (Optionally) enable scripting support.
+const pdfScriptingManager = new pdfjsViewer.PDFScriptingManager({
+  eventBus,
+  sandboxBundleSrc: SANDBOX_BUNDLE_SRC,
+});
+
+const pdfSinglePageViewer = new pdfjsViewer.PDFSinglePageViewer({
+  container,
+  eventBus,
+  linkService: pdfLinkService,
+  findController: pdfFindController,
+  scriptingManager: pdfScriptingManager,
+});
+pdfLinkService.setViewer(pdfSinglePageViewer);
+pdfScriptingManager.setViewer(pdfSinglePageViewer);
+
+eventBus.on("pagesinit", function () {
+  // We can use pdfSinglePageViewer now, e.g. let's change default scale.
+  pdfSinglePageViewer.currentScaleValue = "page-width";
+
+  // We can try searching for things.
+  if (SEARCH_FOR) {
+    eventBus.dispatch("find", { type: "", query: SEARCH_FOR });
+  }
+});
+
+// Loading document.
+const loadingTask = pdfjsLib.getDocument({
+  url: DEFAULT_URL,
+  cMapUrl: CMAP_URL,
+  cMapPacked: CMAP_PACKED,
+  enableXfa: ENABLE_XFA,
+});
+loadingTask.promise.then(function (pdfDocument) {
+  // Document loaded, specifying document for the viewer and
+  // the (optional) linkService.
+  pdfSinglePageViewer.setDocument(pdfDocument);
+
+  pdfLinkService.setDocument(pdfDocument, null);
+});

BIN
pdf.js/examples/image_decoders/fish.jpg


+ 40 - 0
pdf.js/examples/image_decoders/jpeg_viewer.html

@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<!--
+Copyright 2018 Mozilla Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<html dir="ltr" mozdisallowselectionprint>
+<head>
+  <meta charset="utf-8">
+  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
+  <meta name="google" content="notranslate">
+  <title>PDF.js standalone JpegImage parser</title>
+
+  <style>
+    body {
+      background-color: #808080;
+      margin: 0;
+      padding: 0;
+    }
+  </style>
+
+  <script src="../../node_modules/pdfjs-dist/image_decoders/pdf.image_decoders.js"></script>
+</head>
+
+<body tabindex="1">
+  <canvas id="jpegCanvas" width="0" height="0"></canvas>
+
+  <script src="jpeg_viewer.js"></script>
+</body>
+</html>

+ 63 - 0
pdf.js/examples/image_decoders/jpeg_viewer.js

@@ -0,0 +1,63 @@
+/* Copyright 2018 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+"use strict";
+
+if (!pdfjsImageDecoders.JpegImage) {
+  // eslint-disable-next-line no-alert
+  alert("Please build the pdfjs-dist library using `gulp dist-install`");
+}
+
+const JPEG_IMAGE = "fish.jpg";
+
+const jpegCanvas = document.getElementById("jpegCanvas");
+const jpegCtx = jpegCanvas.getContext("2d");
+
+(async function () {
+  // Load the image data, and convert it to a Uint8Array.
+  //
+  const response = await fetch(JPEG_IMAGE);
+  if (!response.ok) {
+    throw new Error(response.statusText);
+  }
+  const typedArrayImage = new Uint8Array(await response.arrayBuffer());
+
+  // Parse the image data using `JpegImage`.
+  //
+  const jpegImage = new pdfjsImageDecoders.JpegImage();
+  jpegImage.parse(typedArrayImage);
+
+  const width = jpegImage.width,
+    height = jpegImage.height;
+  const jpegData = jpegImage.getData({
+    width,
+    height,
+    forceRGB: true,
+  });
+
+  // Render the JPEG image on a <canvas>.
+  //
+  const imageData = jpegCtx.createImageData(width, height);
+  const imageBytes = imageData.data;
+  for (let j = 0, k = 0, jj = width * height * 4; j < jj; ) {
+    imageBytes[j++] = jpegData[k++];
+    imageBytes[j++] = jpegData[k++];
+    imageBytes[j++] = jpegData[k++];
+    imageBytes[j++] = 255;
+  }
+  jpegCanvas.width = width;
+  jpegCanvas.height = height;
+  jpegCtx.putImageData(imageData, 0, 0);
+})();

+ 78 - 0
pdf.js/examples/learning/helloworld.html

@@ -0,0 +1,78 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="UTF-8">
+  <title>'Hello, world!' example</title>
+</head>
+<body>
+
+<h1>'Hello, world!' example</h1>
+
+<canvas id="the-canvas" style="border: 1px solid black; direction: ltr;"></canvas>
+
+<script src="../../node_modules/pdfjs-dist/build/pdf.js"></script>
+
+<script id="script">
+  //
+  // If absolute URL from the remote server is provided, configure the CORS
+  // header on that server.
+  //
+  const url = './helloworld.pdf';
+
+  //
+  // The workerSrc property shall be specified.
+  //
+  pdfjsLib.GlobalWorkerOptions.workerSrc =
+    '../../node_modules/pdfjs-dist/build/pdf.worker.js';
+
+  //
+  // Asynchronous download PDF
+  //
+  const loadingTask = pdfjsLib.getDocument(url);
+  (async () => {
+    const pdf = await loadingTask.promise;
+    //
+    // Fetch the first page
+    //
+    const page = await pdf.getPage(1);
+    const scale = 1.5;
+    const viewport = page.getViewport({ scale });
+    // Support HiDPI-screens.
+    const outputScale = window.devicePixelRatio || 1;
+
+    //
+    // Prepare canvas using PDF page dimensions
+    //
+    const canvas = document.getElementById("the-canvas");
+    const context = canvas.getContext("2d");
+
+    canvas.width = Math.floor(viewport.width * outputScale);
+    canvas.height = Math.floor(viewport.height * outputScale);
+    canvas.style.width = Math.floor(viewport.width) + "px";
+    canvas.style.height = Math.floor(viewport.height) + "px";
+
+    const transform = outputScale !== 1 
+      ? [outputScale, 0, 0, outputScale, 0, 0] 
+      : null;
+
+    //
+    // Render PDF page into canvas context
+    //
+    const renderContext = {
+      canvasContext: context,
+      transform,
+      viewport,
+    };
+    page.render(renderContext);
+  })();
+</script>
+
+<hr>
+<h2>JavaScript code:</h2>
+<pre id="code"></pre>
+<script>
+  document.getElementById('code').textContent =
+      document.getElementById('script').text;
+</script>
+</body>
+</html>

+ 68 - 0
pdf.js/examples/learning/helloworld.pdf

@@ -0,0 +1,68 @@
+%PDF-1.7
+
+1 0 obj  % entry point
+<<
+  /Type /Catalog
+  /Pages 2 0 R
+>>
+endobj
+
+2 0 obj
+<<
+  /Type /Pages
+  /MediaBox [ 0 0 200 200 ]
+  /Count 1
+  /Kids [ 3 0 R ]
+>>
+endobj
+
+3 0 obj
+<<
+  /Type /Page
+  /Parent 2 0 R
+  /Resources <<
+    /Font <<
+      /F1 4 0 R 
+    >>
+  >>
+  /Contents 5 0 R
+>>
+endobj
+
+4 0 obj
+<<
+  /Type /Font
+  /Subtype /Type1
+  /BaseFont /Times-Roman
+>>
+endobj
+
+5 0 obj  % page content
+<<
+  /Length 44
+>>
+stream
+BT
+70 50 TD
+/F1 12 Tf
+(Hello, world!) Tj
+ET
+endstream
+endobj
+
+xref
+0 6
+0000000000 65535 f 
+0000000010 00000 n 
+0000000079 00000 n 
+0000000173 00000 n 
+0000000301 00000 n 
+0000000380 00000 n 
+trailer
+<<
+  /Size 6
+  /Root 1 0 R
+>>
+startxref
+492
+%%EOF

+ 83 - 0
pdf.js/examples/learning/helloworld64.html

@@ -0,0 +1,83 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="UTF-8">
+  <title>'Hello, world!' base64 example</title>
+</head>
+<body>
+
+<h1>'Hello, world!' example</h1>
+
+<canvas id="the-canvas" style="border: 1px solid black; direction: ltr;"></canvas>
+
+<script src="../../node_modules/pdfjs-dist/build/pdf.js"></script>
+
+<script id="script">
+  // atob() is used to convert base64 encoded PDF to binary-like data.
+  // (See also https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/
+  // Base64_encoding_and_decoding.)
+  var pdfData = atob(
+    'JVBERi0xLjcKCjEgMCBvYmogICUgZW50cnkgcG9pbnQKPDwKICAvVHlwZSAvQ2F0YWxvZwog' +
+    'IC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAv' +
+    'TWVkaWFCb3ggWyAwIDAgMjAwIDIwMCBdCiAgL0NvdW50IDEKICAvS2lkcyBbIDMgMCBSIF0K' +
+    'Pj4KZW5kb2JqCgozIDAgb2JqCjw8CiAgL1R5cGUgL1BhZ2UKICAvUGFyZW50IDIgMCBSCiAg' +
+    'L1Jlc291cmNlcyA8PAogICAgL0ZvbnQgPDwKICAgICAgL0YxIDQgMCBSIAogICAgPj4KICA+' +
+    'PgogIC9Db250ZW50cyA1IDAgUgo+PgplbmRvYmoKCjQgMCBvYmoKPDwKICAvVHlwZSAvRm9u' +
+    'dAogIC9TdWJ0eXBlIC9UeXBlMQogIC9CYXNlRm9udCAvVGltZXMtUm9tYW4KPj4KZW5kb2Jq' +
+    'Cgo1IDAgb2JqICAlIHBhZ2UgY29udGVudAo8PAogIC9MZW5ndGggNDQKPj4Kc3RyZWFtCkJU' +
+    'CjcwIDUwIFRECi9GMSAxMiBUZgooSGVsbG8sIHdvcmxkISkgVGoKRVQKZW5kc3RyZWFtCmVu' +
+    'ZG9iagoKeHJlZgowIDYKMDAwMDAwMDAwMCA2NTUzNSBmIAowMDAwMDAwMDEwIDAwMDAwIG4g' +
+    'CjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAw' +
+    'MDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9v' +
+    'dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G');
+
+  //
+  // The workerSrc property shall be specified.
+  //
+  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.
+  var loadingTask = pdfjsLib.getDocument({ data: pdfData, });
+  (async function() {
+    var pdf = await loadingTask.promise;
+    // Fetch the first page.
+    var page = await pdf.getPage(1);
+    var scale = 1.5;
+    var viewport = page.getViewport({ scale: scale, });
+    // Support HiDPI-screens.
+    var outputScale = window.devicePixelRatio || 1;
+
+    // Prepare canvas using PDF page dimensions.
+    var canvas = document.getElementById('the-canvas');
+    var context = canvas.getContext('2d');
+
+    canvas.width = Math.floor(viewport.width * outputScale);
+    canvas.height = Math.floor(viewport.height * outputScale);
+    canvas.style.width = Math.floor(viewport.width) + "px";
+    canvas.style.height =  Math.floor(viewport.height) + "px";
+
+    var transform = outputScale !== 1
+      ? [outputScale, 0, 0, outputScale, 0, 0]
+      : null;
+
+    // Render PDF page into canvas context.
+    var renderContext = {
+      canvasContext: context,
+      transform,
+      viewport,
+    };
+    page.render(renderContext);
+  })();
+</script>
+
+<hr>
+<h2>JavaScript code:</h2>
+<pre id="code"></pre>
+<script>
+  document.getElementById('code').textContent =
+    document.getElementById('script').text;
+</script>
+</body>
+</html>

+ 141 - 0
pdf.js/examples/learning/prevnext.html

@@ -0,0 +1,141 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="UTF-8">
+  <title>Previous/Next example</title>
+</head>
+<body>
+
+<h1>'Previous/Next' example</h1>
+
+<div>
+  <button id="prev">Previous</button>
+  <button id="next">Next</button>
+  &nbsp; &nbsp;
+  <span>Page: <span id="page_num"></span> / <span id="page_count"></span></span>
+</div>
+
+<div>
+  <canvas id="the-canvas" style="border: 1px solid black; direction: ltr;"></canvas>
+</div>
+
+<script src="../../node_modules/pdfjs-dist/build/pdf.js"></script>
+
+<script id="script">
+  //
+  // If absolute URL from the remote server is provided, configure the CORS
+  // header on that server.
+  //
+  var url = '../../web/compressed.tracemonkey-pldi-09.pdf';
+
+  //
+  // In cases when the pdf.worker.js is located at the different folder than the
+  // PDF.js's one, or the PDF.js is executed via eval(), the workerSrc property
+  // shall be specified.
+  //
+  pdfjsLib.GlobalWorkerOptions.workerSrc =
+    '../../node_modules/pdfjs-dist/build/pdf.worker.js';
+
+  var pdfDoc = null,
+      pageNum = 1,
+      pageRendering = false,
+      pageNumPending = null,
+      scale = 0.8,
+      canvas = document.getElementById('the-canvas'),
+      ctx = canvas.getContext('2d');
+
+  /**
+   * Get page info from document, resize canvas accordingly, and render page.
+   * @param num Page number.
+   */
+  function renderPage(num) {
+    pageRendering = true;
+    // Using promise to fetch the page
+    pdfDoc.getPage(num).then(function(page) {
+      var viewport = page.getViewport({ scale: scale, });
+      // Support HiDPI-screens.
+      var outputScale = window.devicePixelRatio || 1;
+
+      canvas.width = Math.floor(viewport.width * outputScale);
+      canvas.height = Math.floor(viewport.height * outputScale);
+      canvas.style.width = Math.floor(viewport.width) + "px";
+      canvas.style.height =  Math.floor(viewport.height) + "px";
+
+      var transform = outputScale !== 1
+        ? [outputScale, 0, 0, outputScale, 0, 0]
+        : null;
+
+      // Render PDF page into canvas context
+      var renderContext = {
+        canvasContext: ctx,
+        transform: transform,
+        viewport: viewport,
+      };
+      var renderTask = page.render(renderContext);
+
+      // Wait for rendering to finish
+      renderTask.promise.then(function () {
+        pageRendering = false;
+        if (pageNumPending !== null) {
+          // New page rendering is pending
+          renderPage(pageNumPending);
+          pageNumPending = null;
+        }
+      });
+    });
+
+    // Update page counters
+    document.getElementById('page_num').textContent = num;
+  }
+
+  /**
+   * If another page rendering in progress, waits until the rendering is
+   * finished. Otherwise, executes rendering immediately.
+   */
+  function queueRenderPage(num) {
+    if (pageRendering) {
+      pageNumPending = num;
+    } else {
+      renderPage(num);
+    }
+  }
+
+  /**
+   * Displays previous page.
+   */
+  function onPrevPage() {
+    if (pageNum <= 1) {
+      return;
+    }
+    pageNum--;
+    queueRenderPage(pageNum);
+  }
+  document.getElementById('prev').addEventListener('click', onPrevPage);
+
+  /**
+   * Displays next page.
+   */
+  function onNextPage() {
+    if (pageNum >= pdfDoc.numPages) {
+      return;
+    }
+    pageNum++;
+    queueRenderPage(pageNum);
+  }
+  document.getElementById('next').addEventListener('click', onNextPage);
+
+  /**
+   * Asynchronously downloads PDF.
+   */
+  var loadingTask = pdfjsLib.getDocument(url);
+  loadingTask.promise.then(function(pdfDoc_) {
+    pdfDoc = pdfDoc_;
+    document.getElementById('page_count').textContent = pdfDoc.numPages;
+
+    // Initial/first page rendering
+    renderPage(pageNum);
+  });
+</script>
+
+</body>
+</html>

+ 11 - 0
pdf.js/examples/mobile-viewer/README.md

@@ -0,0 +1,11 @@
+## Overview
+
+Example to demonstrate PDF.js library usage with a viewer optimized for mobile usage.
+
+## Getting started
+
+Build PDF.js using `gulp dist-install` and run `gulp server` to start a web server.
+You can then work with the mobile viewer at
+http://localhost:8888/examples/mobile-viewer/viewer.html.
+
+Refer to `viewer.js` for the source code of the mobile viewer.

BIN
pdf.js/examples/mobile-viewer/images/div_line_left.png


BIN
pdf.js/examples/mobile-viewer/images/div_line_left@1.5x.png


BIN
pdf.js/examples/mobile-viewer/images/div_line_left@2x.png


BIN
pdf.js/examples/mobile-viewer/images/div_line_right.png


BIN
pdf.js/examples/mobile-viewer/images/div_line_right@1.5x.png


BIN
pdf.js/examples/mobile-viewer/images/div_line_right@2x.png


BIN
pdf.js/examples/mobile-viewer/images/document_bg.png


BIN
pdf.js/examples/mobile-viewer/images/icon_next_page.png


BIN
pdf.js/examples/mobile-viewer/images/icon_next_page@1.5x.png


BIN
pdf.js/examples/mobile-viewer/images/icon_previous_page.png


BIN
pdf.js/examples/mobile-viewer/images/icon_previous_page@1.5x.png


BIN
pdf.js/examples/mobile-viewer/images/icon_zoom_in.png


BIN
pdf.js/examples/mobile-viewer/images/icon_zoom_in@1.5x.png


BIN
pdf.js/examples/mobile-viewer/images/icon_zoom_out.png


BIN
pdf.js/examples/mobile-viewer/images/icon_zoom_out@1.5x.png


BIN
pdf.js/examples/mobile-viewer/images/spinner.png


BIN
pdf.js/examples/mobile-viewer/images/toolbar_background.png


+ 273 - 0
pdf.js/examples/mobile-viewer/viewer.css

@@ -0,0 +1,273 @@
+/* Copyright 2016 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+:root {
+  --progressBar-percent: 0%;
+}
+
+* {
+  padding: 0;
+  margin: 0;
+}
+
+html {
+  height: 100%;
+  width: 100%;
+  overflow: hidden;
+  font-size: 10px;
+}
+
+header {
+  background-color: rgba(244, 244, 244, 1);
+}
+
+header h1 {
+  border-bottom: 1px solid rgba(216, 216, 216, 1);
+  color: rgba(133, 133, 133, 1);
+  font-size: 23px;
+  font-style: italic;
+  font-weight: normal;
+  overflow: hidden;
+  padding: 10px;
+  text-align: center;
+  text-overflow: ellipsis;
+  white-space: nowrap;
+}
+
+body {
+  background: url(images/document_bg.png);
+  color: rgba(255, 255, 255, 1);
+  font-family: sans-serif;
+  font-size: 10px;
+  height: 100%;
+  width: 100%;
+  overflow: hidden;
+  padding-bottom: 5rem;
+}
+
+section {
+  position: absolute;
+  top: 0;
+  left: 0;
+  width: 100%;
+  height: 100%;
+  overflow: hidden;
+  font-size: 2rem;
+}
+
+footer {
+  background-image: url(images/toolbar_background.png);
+  height: 4rem;
+  position: absolute;
+  bottom: 0;
+  left: 0;
+  right: 0;
+  z-index: 1;
+  box-shadow: 0 -0.2rem 0.5rem rgba(50, 50, 50, 0.75);
+}
+
+.toolbarButton {
+  display: block;
+  padding: 0;
+  margin: 0;
+  border-width: 0;
+  background-position: center center;
+  background-repeat: no-repeat;
+  background-color: rgba(0, 0, 0, 0);
+}
+
+.toolbarButton.pageUp {
+  position: absolute;
+  width: 18%;
+  height: 100%;
+  left: 0;
+  background-image: url(images/icon_previous_page.png);
+  background-size: 2rem;
+}
+
+.toolbarButton.pageDown {
+  position: absolute;
+  width: 18%;
+  height: 100%;
+  left: 18%;
+  background-image: url(images/icon_next_page.png);
+  background-size: 2rem;
+}
+
+#pageNumber {
+  -moz-appearance: textfield; /* hides the spinner in moz */
+  position: absolute;
+  width: 28%;
+  height: 100%;
+  left: 36%;
+  text-align: center;
+  border: 0;
+  background-color: rgba(0, 0, 0, 0);
+  font-size: 1.2rem;
+  color: rgba(255, 255, 255, 1);
+  background-image: url(images/div_line_left.png),
+    url(images/div_line_right.png);
+  background-repeat: no-repeat;
+  background-position: left, right;
+  background-size: 0.2rem, 0.2rem;
+}
+
+.toolbarButton.zoomOut {
+  position: absolute;
+  width: 18%;
+  height: 100%;
+  left: 64%;
+  background-image: url(images/icon_zoom_out.png);
+  background-size: 2.4rem;
+}
+
+.toolbarButton.zoomIn {
+  position: absolute;
+  width: 18%;
+  height: 100%;
+  left: 82%;
+  background-image: url(images/icon_zoom_in.png);
+  background-size: 2.4rem;
+}
+
+.toolbarButton[disabled] {
+  opacity: 0.3;
+}
+
+.hidden {
+  display: none;
+}
+[hidden] {
+  display: none !important;
+}
+
+#viewerContainer {
+  position: absolute;
+  overflow: auto;
+  width: 100%;
+  top: 5rem;
+  bottom: 4rem;
+  left: 0;
+  right: 0;
+}
+
+canvas {
+  margin: auto;
+  display: block;
+}
+
+.pdfViewer .page .loadingIcon {
+  width: 2.9rem;
+  height: 2.9rem;
+  background: url("images/spinner.png") no-repeat left top / 38rem;
+  border: medium none;
+  animation: 1s steps(10, end) 0s normal none infinite moveDefault;
+  display: block;
+  position: absolute;
+  top: calc((100% - 2.9rem) / 2);
+  left: calc((100% - 2.9rem) / 2);
+}
+
+@keyframes moveDefault {
+  from {
+    background-position: 0 top;
+  }
+
+  to {
+    background-position: -39rem top;
+  }
+}
+
+#loadingBar {
+  position: relative;
+  height: 0.6rem;
+  background-color: rgba(51, 51, 51, 1);
+  border-bottom: 1px solid rgba(51, 51, 51, 1);
+}
+
+#loadingBar .progress {
+  position: absolute;
+  left: 0;
+  width: 100%;
+  transform: scaleX(var(--progressBar-percent));
+  transform-origin: 0 0;
+  height: 100%;
+  background-color: rgba(221, 221, 221, 1);
+  overflow: hidden;
+  transition: transform 200ms;
+}
+
+@keyframes progressIndeterminate {
+  0% {
+    transform: translateX(0%);
+  }
+  50% {
+    transform: translateX(100%);
+  }
+  100% {
+    transform: translateX(100%);
+  }
+}
+
+#loadingBar.indeterminate .progress {
+  transform: none;
+  background-color: rgba(153, 153, 153, 1);
+  transition: none;
+}
+
+#loadingBar.indeterminate .progress .glimmer {
+  position: absolute;
+  top: 0;
+  left: 0;
+  height: 100%;
+  width: 5rem;
+  background-image: linear-gradient(
+    to right,
+    rgba(153, 153, 153, 1) 0%,
+    rgba(255, 255, 255, 1) 50%,
+    rgba(153, 153, 153, 1) 100%
+  );
+  background-size: 100% 100%;
+  background-repeat: no-repeat;
+  animation: progressIndeterminate 2s linear infinite;
+}
+
+#errorWrapper {
+  background: none repeat scroll 0 0 rgba(255, 85, 85, 1);
+  color: rgba(255, 255, 255, 1);
+  left: 0;
+  position: absolute;
+  right: 0;
+  top: 3.2rem;
+  z-index: 1000;
+  padding: 0.3rem;
+  font-size: 0.8em;
+}
+
+#errorMessageLeft {
+  float: left;
+}
+
+#errorMessageRight {
+  float: right;
+}
+
+#errorMoreInfo {
+  background-color: rgba(255, 255, 255, 1);
+  color: rgba(0, 0, 0, 1);
+  padding: 0.3rem;
+  margin: 0.3rem;
+  width: 98%;
+}

+ 76 - 0
pdf.js/examples/mobile-viewer/viewer.html

@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<!--
+Copyright 2016 Mozilla Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<html dir="ltr">
+  <head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
+
+    <title>PDF.js viewer</title>
+
+    <link rel="stylesheet" href="../../node_modules/pdfjs-dist/web/pdf_viewer.css">
+    <link rel="stylesheet" type="text/css" href="viewer.css">
+
+    <script src="../../node_modules/pdfjs-dist/build/pdf.js"></script>
+    <script src="../../node_modules/pdfjs-dist/web/pdf_viewer.js"></script>
+  </head>
+
+  <body>
+    <header>
+      <h1 id="title"></h1>
+    </header>
+
+    <div id="viewerContainer">
+      <div id="viewer" class="pdfViewer"></div>
+    </div>
+
+    <div id="loadingBar">
+      <div class="progress"></div>
+      <div class="glimmer"></div>
+    </div>
+
+    <div id="errorWrapper" hidden="true">
+      <div id="errorMessageLeft">
+        <span id="errorMessage"></span>
+        <button id="errorShowMore">
+          More Information
+        </button>
+        <button id="errorShowLess">
+          Less Information
+        </button>
+      </div>
+      <div id="errorMessageRight">
+        <button id="errorClose">
+          Close
+        </button>
+      </div>
+      <div class="clearBoth"></div>
+      <textarea id="errorMoreInfo" hidden="true" readonly="readonly"></textarea>
+    </div>
+
+    <footer>
+      <button class="toolbarButton pageUp" title="Previous Page" id="previous"></button>
+      <button class="toolbarButton pageDown" title="Next Page" id="next"></button>
+
+      <input type="number" id="pageNumber" class="toolbarField pageNumber" value="1" size="4" min="1">
+
+      <button class="toolbarButton zoomOut" title="Zoom Out" id="zoomOut"></button>
+      <button class="toolbarButton zoomIn" title="Zoom In" id="zoomIn"></button>
+    </footer>
+
+     <script src="viewer.js"></script>
+  </body>
+</html>

+ 454 - 0
pdf.js/examples/mobile-viewer/viewer.js

@@ -0,0 +1,454 @@
+/* Copyright 2016 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+"use strict";
+
+if (!pdfjsLib.getDocument || !pdfjsViewer.PDFViewer) {
+  // eslint-disable-next-line no-alert
+  alert("Please build the pdfjs-dist library using\n `gulp dist-install`");
+}
+
+const USE_ONLY_CSS_ZOOM = true;
+const TEXT_LAYER_MODE = 0; // DISABLE
+const MAX_IMAGE_SIZE = 1024 * 1024;
+const CMAP_URL = "../../node_modules/pdfjs-dist/cmaps/";
+const CMAP_PACKED = true;
+
+pdfjsLib.GlobalWorkerOptions.workerSrc =
+  "../../node_modules/pdfjs-dist/build/pdf.worker.js";
+
+const DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf";
+const DEFAULT_SCALE_DELTA = 1.1;
+const MIN_SCALE = 0.25;
+const MAX_SCALE = 10.0;
+const DEFAULT_SCALE_VALUE = "auto";
+
+const PDFViewerApplication = {
+  pdfLoadingTask: null,
+  pdfDocument: null,
+  pdfViewer: null,
+  pdfHistory: null,
+  pdfLinkService: null,
+  eventBus: null,
+
+  /**
+   * Opens PDF document specified by URL.
+   * @returns {Promise} - Returns the promise, which is resolved when document
+   *                      is opened.
+   */
+  open(params) {
+    if (this.pdfLoadingTask) {
+      // We need to destroy already opened document
+      return this.close().then(
+        function () {
+          // ... and repeat the open() call.
+          return this.open(params);
+        }.bind(this)
+      );
+    }
+
+    const url = params.url;
+    const self = this;
+    this.setTitleUsingUrl(url);
+
+    // Loading document.
+    const loadingTask = pdfjsLib.getDocument({
+      url,
+      maxImageSize: MAX_IMAGE_SIZE,
+      cMapUrl: CMAP_URL,
+      cMapPacked: CMAP_PACKED,
+    });
+    this.pdfLoadingTask = loadingTask;
+
+    loadingTask.onProgress = function (progressData) {
+      self.progress(progressData.loaded / progressData.total);
+    };
+
+    return loadingTask.promise.then(
+      function (pdfDocument) {
+        // Document loaded, specifying document for the viewer.
+        self.pdfDocument = pdfDocument;
+        self.pdfViewer.setDocument(pdfDocument);
+        self.pdfLinkService.setDocument(pdfDocument);
+        self.pdfHistory.initialize({
+          fingerprint: pdfDocument.fingerprints[0],
+        });
+
+        self.loadingBar.hide();
+        self.setTitleUsingMetadata(pdfDocument);
+      },
+      function (exception) {
+        const message = exception && exception.message;
+        const l10n = self.l10n;
+        let loadingErrorMessage;
+
+        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 pdfjsLib.MissingPDFException) {
+          // special message for missing PDFs
+          loadingErrorMessage = l10n.get(
+            "missing_file_error",
+            null,
+            "Missing PDF file."
+          );
+        } else if (exception instanceof pdfjsLib.UnexpectedResponseException) {
+          loadingErrorMessage = l10n.get(
+            "unexpected_response_error",
+            null,
+            "Unexpected server response."
+          );
+        } else {
+          loadingErrorMessage = l10n.get(
+            "loading_error",
+            null,
+            "An error occurred while loading the PDF."
+          );
+        }
+
+        loadingErrorMessage.then(function (msg) {
+          self.error(msg, { message });
+        });
+        self.loadingBar.hide();
+      }
+    );
+  },
+
+  /**
+   * Closes opened PDF document.
+   * @returns {Promise} - Returns the promise, which is resolved when all
+   *                      destruction is completed.
+   */
+  close() {
+    const errorWrapper = document.getElementById("errorWrapper");
+    errorWrapper.hidden = true;
+
+    if (!this.pdfLoadingTask) {
+      return Promise.resolve();
+    }
+
+    const promise = this.pdfLoadingTask.destroy();
+    this.pdfLoadingTask = null;
+
+    if (this.pdfDocument) {
+      this.pdfDocument = null;
+
+      this.pdfViewer.setDocument(null);
+      this.pdfLinkService.setDocument(null, null);
+
+      if (this.pdfHistory) {
+        this.pdfHistory.reset();
+      }
+    }
+
+    return promise;
+  },
+
+  get loadingBar() {
+    const bar = document.getElementById("loadingBar");
+    return pdfjsLib.shadow(
+      this,
+      "loadingBar",
+      new pdfjsViewer.ProgressBar(bar)
+    );
+  },
+
+  setTitleUsingUrl: function pdfViewSetTitleUsingUrl(url) {
+    this.url = url;
+    let title = pdfjsLib.getFilenameFromUrl(url) || url;
+    try {
+      title = decodeURIComponent(title);
+    } catch (e) {
+      // decodeURIComponent may throw URIError,
+      // fall back to using the unprocessed url in that case
+    }
+    this.setTitle(title);
+  },
+
+  setTitleUsingMetadata(pdfDocument) {
+    const self = this;
+    pdfDocument.getMetadata().then(function (data) {
+      const info = data.info,
+        metadata = data.metadata;
+      self.documentInfo = info;
+      self.metadata = metadata;
+
+      // Provides some basic debug information
+      console.log(
+        "PDF " +
+          pdfDocument.fingerprints[0] +
+          " [" +
+          info.PDFFormatVersion +
+          " " +
+          (info.Producer || "-").trim() +
+          " / " +
+          (info.Creator || "-").trim() +
+          "]" +
+          " (PDF.js: " +
+          (pdfjsLib.version || "-") +
+          ")"
+      );
+
+      let pdfTitle;
+      if (metadata && metadata.has("dc:title")) {
+        const title = metadata.get("dc:title");
+        // Ghostscript sometimes returns 'Untitled', so prevent setting the
+        // title to 'Untitled.
+        if (title !== "Untitled") {
+          pdfTitle = title;
+        }
+      }
+
+      if (!pdfTitle && info && info.Title) {
+        pdfTitle = info.Title;
+      }
+
+      if (pdfTitle) {
+        self.setTitle(pdfTitle + " - " + document.title);
+      }
+    });
+  },
+
+  setTitle: function pdfViewSetTitle(title) {
+    document.title = title;
+    document.getElementById("title").textContent = title;
+  },
+
+  error: function pdfViewError(message, moreInfo) {
+    const l10n = this.l10n;
+    const moreInfoText = [
+      l10n.get(
+        "error_version_info",
+        { version: pdfjsLib.version || "?", build: pdfjsLib.build || "?" },
+        "PDF.js v{{version}} (build: {{build}})"
+      ),
+    ];
+
+    if (moreInfo) {
+      moreInfoText.push(
+        l10n.get(
+          "error_message",
+          { message: moreInfo.message },
+          "Message: {{message}}"
+        )
+      );
+      if (moreInfo.stack) {
+        moreInfoText.push(
+          l10n.get("error_stack", { stack: moreInfo.stack }, "Stack: {{stack}}")
+        );
+      } else {
+        if (moreInfo.filename) {
+          moreInfoText.push(
+            l10n.get(
+              "error_file",
+              { file: moreInfo.filename },
+              "File: {{file}}"
+            )
+          );
+        }
+        if (moreInfo.lineNumber) {
+          moreInfoText.push(
+            l10n.get(
+              "error_line",
+              { line: moreInfo.lineNumber },
+              "Line: {{line}}"
+            )
+          );
+        }
+      }
+    }
+
+    const errorWrapper = document.getElementById("errorWrapper");
+    errorWrapper.hidden = false;
+
+    const errorMessage = document.getElementById("errorMessage");
+    errorMessage.textContent = message;
+
+    const closeButton = document.getElementById("errorClose");
+    closeButton.onclick = function () {
+      errorWrapper.hidden = true;
+    };
+
+    const errorMoreInfo = document.getElementById("errorMoreInfo");
+    const moreInfoButton = document.getElementById("errorShowMore");
+    const lessInfoButton = document.getElementById("errorShowLess");
+    moreInfoButton.onclick = function () {
+      errorMoreInfo.hidden = false;
+      moreInfoButton.hidden = true;
+      lessInfoButton.hidden = false;
+      errorMoreInfo.style.height = errorMoreInfo.scrollHeight + "px";
+    };
+    lessInfoButton.onclick = function () {
+      errorMoreInfo.hidden = true;
+      moreInfoButton.hidden = false;
+      lessInfoButton.hidden = true;
+    };
+    moreInfoButton.hidden = false;
+    lessInfoButton.hidden = true;
+    Promise.all(moreInfoText).then(function (parts) {
+      errorMoreInfo.value = parts.join("\n");
+    });
+  },
+
+  progress: function pdfViewProgress(level) {
+    const percent = Math.round(level * 100);
+    // Updating the bar if value increases.
+    if (percent > this.loadingBar.percent || isNaN(percent)) {
+      this.loadingBar.percent = percent;
+    }
+  },
+
+  get pagesCount() {
+    return this.pdfDocument.numPages;
+  },
+
+  get page() {
+    return this.pdfViewer.currentPageNumber;
+  },
+
+  set page(val) {
+    this.pdfViewer.currentPageNumber = val;
+  },
+
+  zoomIn: function pdfViewZoomIn(ticks) {
+    let newScale = this.pdfViewer.currentScale;
+    do {
+      newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
+      newScale = Math.ceil(newScale * 10) / 10;
+      newScale = Math.min(MAX_SCALE, newScale);
+    } while (--ticks && newScale < MAX_SCALE);
+    this.pdfViewer.currentScaleValue = newScale;
+  },
+
+  zoomOut: function pdfViewZoomOut(ticks) {
+    let newScale = this.pdfViewer.currentScale;
+    do {
+      newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
+      newScale = Math.floor(newScale * 10) / 10;
+      newScale = Math.max(MIN_SCALE, newScale);
+    } while (--ticks && newScale > MIN_SCALE);
+    this.pdfViewer.currentScaleValue = newScale;
+  },
+
+  initUI: function pdfViewInitUI() {
+    const eventBus = new pdfjsViewer.EventBus();
+    this.eventBus = eventBus;
+
+    const linkService = new pdfjsViewer.PDFLinkService({
+      eventBus,
+    });
+    this.pdfLinkService = linkService;
+
+    this.l10n = pdfjsViewer.NullL10n;
+
+    const container = document.getElementById("viewerContainer");
+    const pdfViewer = new pdfjsViewer.PDFViewer({
+      container,
+      eventBus,
+      linkService,
+      l10n: this.l10n,
+      useOnlyCssZoom: USE_ONLY_CSS_ZOOM,
+      textLayerMode: TEXT_LAYER_MODE,
+    });
+    this.pdfViewer = pdfViewer;
+    linkService.setViewer(pdfViewer);
+
+    this.pdfHistory = new pdfjsViewer.PDFHistory({
+      eventBus,
+      linkService,
+    });
+    linkService.setHistory(this.pdfHistory);
+
+    document.getElementById("previous").addEventListener("click", function () {
+      PDFViewerApplication.page--;
+    });
+
+    document.getElementById("next").addEventListener("click", function () {
+      PDFViewerApplication.page++;
+    });
+
+    document.getElementById("zoomIn").addEventListener("click", function () {
+      PDFViewerApplication.zoomIn();
+    });
+
+    document.getElementById("zoomOut").addEventListener("click", function () {
+      PDFViewerApplication.zoomOut();
+    });
+
+    document
+      .getElementById("pageNumber")
+      .addEventListener("click", function () {
+        this.select();
+      });
+
+    document
+      .getElementById("pageNumber")
+      .addEventListener("change", function () {
+        PDFViewerApplication.page = this.value | 0;
+
+        // Ensure that the page number input displays the correct value,
+        // even if the value entered by the user was invalid
+        // (e.g. a floating point number).
+        if (this.value !== PDFViewerApplication.page.toString()) {
+          this.value = PDFViewerApplication.page;
+        }
+      });
+
+    eventBus.on("pagesinit", function () {
+      // We can use pdfViewer now, e.g. let's change default scale.
+      pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE;
+    });
+
+    eventBus.on(
+      "pagechanging",
+      function (evt) {
+        const page = evt.pageNumber;
+        const numPages = PDFViewerApplication.pagesCount;
+
+        document.getElementById("pageNumber").value = page;
+        document.getElementById("previous").disabled = page <= 1;
+        document.getElementById("next").disabled = page >= numPages;
+      },
+      true
+    );
+  },
+};
+
+window.PDFViewerApplication = PDFViewerApplication;
+
+document.addEventListener(
+  "DOMContentLoaded",
+  function () {
+    PDFViewerApplication.initUI();
+  },
+  true
+);
+
+// The offsetParent is not set until the PDF.js iframe or object is visible;
+// waiting for first animation.
+const animationStarted = new Promise(function (resolve) {
+  window.requestAnimationFrame(resolve);
+});
+
+// We need to delay opening until all HTML is loaded.
+animationStarted.then(function () {
+  PDFViewerApplication.open({
+    url: DEFAULT_URL,
+  });
+});

+ 9 - 0
pdf.js/examples/node/.eslintrc

@@ -0,0 +1,9 @@
+{
+  "extends": [
+    "../.eslintrc"
+  ],
+
+  "env": {
+    "node": true,
+  },
+}

+ 285 - 0
pdf.js/examples/node/domstubs.js

@@ -0,0 +1,285 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function xmlEncode(s) {
+  let i = 0,
+    ch;
+  s = String(s);
+  while (
+    i < s.length &&
+    (ch = s[i]) !== "&" &&
+    ch !== "<" &&
+    ch !== '"' &&
+    ch !== "\n" &&
+    ch !== "\r" &&
+    ch !== "\t"
+  ) {
+    i++;
+  }
+  if (i >= s.length) {
+    return s;
+  }
+  let buf = s.substring(0, i);
+  while (i < s.length) {
+    ch = s[i++];
+    switch (ch) {
+      case "&":
+        buf += "&amp;";
+        break;
+      case "<":
+        buf += "&lt;";
+        break;
+      case '"':
+        buf += "&quot;";
+        break;
+      case "\n":
+        buf += "&#xA;";
+        break;
+      case "\r":
+        buf += "&#xD;";
+        break;
+      case "\t":
+        buf += "&#x9;";
+        break;
+      default:
+        buf += ch;
+        break;
+    }
+  }
+  return buf;
+}
+
+function DOMElement(name) {
+  this.nodeName = name;
+  this.childNodes = [];
+  this.attributes = {};
+  this.textContent = "";
+
+  if (name === "style") {
+    this.sheet = {
+      cssRules: [],
+      insertRule(rule) {
+        this.cssRules.push(rule);
+      },
+    };
+  }
+}
+
+DOMElement.prototype = {
+  getAttribute: function DOMElement_getAttribute(name) {
+    if (name in this.attributes) {
+      return this.attributes[name];
+    }
+    return null;
+  },
+
+  getAttributeNS: function DOMElement_getAttributeNS(NS, name) {
+    // Fast path
+    if (name in this.attributes) {
+      return this.attributes[name];
+    }
+    // Slow path - used by test/unit/display_svg_spec.js
+    // Assuming that there is only one matching attribute for a given name,
+    // across all namespaces.
+    if (NS) {
+      const suffix = ":" + name;
+      for (const fullName in this.attributes) {
+        if (fullName.slice(-suffix.length) === suffix) {
+          return this.attributes[fullName];
+        }
+      }
+    }
+    return null;
+  },
+
+  setAttribute: function DOMElement_setAttribute(name, value) {
+    this.attributes[name] = value || "";
+  },
+
+  setAttributeNS: function DOMElement_setAttributeNS(NS, name, value) {
+    this.setAttribute(name, value);
+  },
+
+  append: function DOMElement_append(...elements) {
+    const childNodes = this.childNodes;
+    for (const element of elements) {
+      if (!childNodes.includes(element)) {
+        childNodes.push(element);
+      }
+    }
+  },
+
+  appendChild: function DOMElement_appendChild(element) {
+    const childNodes = this.childNodes;
+    if (!childNodes.includes(element)) {
+      childNodes.push(element);
+    }
+  },
+
+  hasChildNodes: function DOMElement_hasChildNodes() {
+    return this.childNodes.length !== 0;
+  },
+
+  cloneNode: function DOMElement_cloneNode() {
+    const newNode = new DOMElement(this.nodeName);
+    newNode.childNodes = this.childNodes;
+    newNode.attributes = this.attributes;
+    newNode.textContent = this.textContent;
+    return newNode;
+  },
+
+  // This method is offered for convenience. It is recommended to directly use
+  // getSerializer because that allows you to process the chunks as they come
+  // instead of requiring the whole image to fit in memory.
+  toString: function DOMElement_toString() {
+    const buf = [];
+    const serializer = this.getSerializer();
+    let chunk;
+    while ((chunk = serializer.getNext()) !== null) {
+      buf.push(chunk);
+    }
+    return buf.join("");
+  },
+
+  getSerializer: function DOMElement_getSerializer() {
+    return new DOMElementSerializer(this);
+  },
+};
+
+function DOMElementSerializer(node) {
+  this._node = node;
+  this._state = 0;
+  this._loopIndex = 0;
+  this._attributeKeys = null;
+  this._childSerializer = null;
+}
+DOMElementSerializer.prototype = {
+  /**
+   * Yields the next chunk in the serialization of the element.
+   *
+   * @returns {string|null} null if the element has fully been serialized.
+   */
+  getNext: function DOMElementSerializer_getNext() {
+    const node = this._node;
+    switch (this._state) {
+      case 0: // Start opening tag.
+        ++this._state;
+        return "<" + node.nodeName;
+      case 1: // Add SVG namespace if this is the root element.
+        ++this._state;
+        if (node.nodeName === "svg:svg") {
+          return (
+            ' xmlns:xlink="http://www.w3.org/1999/xlink"' +
+            ' xmlns:svg="http://www.w3.org/2000/svg"'
+          );
+        }
+      /* falls through */
+      case 2: // Initialize variables for looping over attributes.
+        ++this._state;
+        this._loopIndex = 0;
+        this._attributeKeys = Object.keys(node.attributes);
+      /* falls through */
+      case 3: // Serialize any attributes and end opening tag.
+        if (this._loopIndex < this._attributeKeys.length) {
+          const name = this._attributeKeys[this._loopIndex++];
+          return " " + name + '="' + xmlEncode(node.attributes[name]) + '"';
+        }
+        ++this._state;
+        return ">";
+      case 4: // Serialize textContent for tspan/style elements.
+        if (node.nodeName === "svg:tspan" || node.nodeName === "svg:style") {
+          this._state = 6;
+          return xmlEncode(node.textContent);
+        }
+        ++this._state;
+        this._loopIndex = 0;
+      /* falls through */
+      case 5: // Serialize child nodes (only for non-tspan/style elements).
+        while (true) {
+          const value =
+            this._childSerializer && this._childSerializer.getNext();
+          if (value !== null) {
+            return value;
+          }
+          const nextChild = node.childNodes[this._loopIndex++];
+          if (nextChild) {
+            this._childSerializer = new DOMElementSerializer(nextChild);
+          } else {
+            this._childSerializer = null;
+            ++this._state;
+            break;
+          }
+        }
+      /* falls through */
+      case 6: // Ending tag.
+        ++this._state;
+        return "</" + node.nodeName + ">";
+      case 7: // Done.
+        return null;
+      default:
+        throw new Error("Unexpected serialization state: " + this._state);
+    }
+  },
+};
+
+const document = {
+  childNodes: [],
+
+  get currentScript() {
+    return { src: "" };
+  },
+
+  get documentElement() {
+    return this;
+  },
+
+  createElementNS(NS, element) {
+    const elObject = new DOMElement(element);
+    return elObject;
+  },
+
+  createElement(element) {
+    return this.createElementNS("", element);
+  },
+
+  getElementsByTagName(element) {
+    if (element === "head") {
+      return [this.head || (this.head = new DOMElement("head"))];
+    }
+    return [];
+  },
+};
+
+function Image() {
+  this._src = null;
+  this.onload = null;
+}
+Image.prototype = {
+  get src() {
+    return this._src;
+  },
+  set src(value) {
+    this._src = value;
+    if (this.onload) {
+      this.onload();
+    }
+  },
+};
+
+exports.document = document;
+exports.Image = Image;
+
+const exported_symbols = Object.keys(exports);
+
+exports.setStubs = function (namespace) {
+  exported_symbols.forEach(function (key) {
+    console.assert(!(key in namespace), "property should not be set: " + key);
+    namespace[key] = exports[key];
+  });
+};
+exports.unsetStubs = function (namespace) {
+  exported_symbols.forEach(function (key) {
+    console.assert(key in namespace, "property should be set: " + key);
+    delete namespace[key];
+  });
+};

+ 76 - 0
pdf.js/examples/node/getinfo.js

@@ -0,0 +1,76 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+//
+// Basic node example that prints document metadata and text content.
+//
+
+// Run `gulp dist-install` to generate 'pdfjs-dist' npm package files.
+const pdfjsLib = require("pdfjs-dist/legacy/build/pdf.js");
+
+// Loading file from file system into typed array
+const pdfPath =
+  process.argv[2] || "../../web/compressed.tracemonkey-pldi-09.pdf";
+
+// Will be using promises to load document, pages and misc data instead of
+// callback.
+const loadingTask = pdfjsLib.getDocument(pdfPath);
+loadingTask.promise
+  .then(function (doc) {
+    const numPages = doc.numPages;
+    console.log("# Document Loaded");
+    console.log("Number of Pages: " + numPages);
+    console.log();
+
+    let lastPromise; // will be used to chain promises
+    lastPromise = doc.getMetadata().then(function (data) {
+      console.log("# Metadata Is Loaded");
+      console.log("## Info");
+      console.log(JSON.stringify(data.info, null, 2));
+      console.log();
+      if (data.metadata) {
+        console.log("## Metadata");
+        console.log(JSON.stringify(data.metadata.getAll(), null, 2));
+        console.log();
+      }
+    });
+
+    const loadPage = function (pageNum) {
+      return doc.getPage(pageNum).then(function (page) {
+        console.log("# Page " + pageNum);
+        const viewport = page.getViewport({ scale: 1.0 });
+        console.log("Size: " + viewport.width + "x" + viewport.height);
+        console.log();
+        return page
+          .getTextContent()
+          .then(function (content) {
+            // Content contains lots of information about the text layout and
+            // styles, but we need only strings at the moment
+            const strings = content.items.map(function (item) {
+              return item.str;
+            });
+            console.log("## Text Content");
+            console.log(strings.join(" "));
+            // Release page resources.
+            page.cleanup();
+          })
+          .then(function () {
+            console.log();
+          });
+      });
+    };
+    // Loading of the first page will wait on metadata and subsequent loadings
+    // will wait on the previous pages.
+    for (let i = 1; i <= numPages; i++) {
+      lastPromise = lastPromise.then(loadPage.bind(null, i));
+    }
+    return lastPromise;
+  })
+  .then(
+    function () {
+      console.log("# End of Document");
+    },
+    function (err) {
+      console.error("Error: " + err);
+    }
+  );

+ 17 - 0
pdf.js/examples/node/pdf2png/README.md

@@ -0,0 +1,17 @@
+## Overview
+
+Example to demonstrate converting a PDF file to a PNG image using the PDF.js library.
+
+## Getting started
+
+Install the dependencies and build the PDF.js library:
+
+    $ npm install
+    $ gulp dist-install
+
+Install the Node canvas library and run the example to convert the first page of a
+PDF file to a PNG image:
+
+    $ npm install canvas
+    $ cd examples/node/pdf2png
+    $ node pdf2png.js

+ 111 - 0
pdf.js/examples/node/pdf2png/pdf2png.js

@@ -0,0 +1,111 @@
+/* Copyright 2017 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+const Canvas = require("canvas");
+const assert = require("assert").strict;
+const fs = require("fs");
+
+function NodeCanvasFactory() {}
+NodeCanvasFactory.prototype = {
+  create: function NodeCanvasFactory_create(width, height) {
+    assert(width > 0 && height > 0, "Invalid canvas size");
+    const canvas = Canvas.createCanvas(width, height);
+    const context = canvas.getContext("2d");
+    return {
+      canvas,
+      context,
+    };
+  },
+
+  reset: function NodeCanvasFactory_reset(canvasAndContext, width, height) {
+    assert(canvasAndContext.canvas, "Canvas is not specified");
+    assert(width > 0 && height > 0, "Invalid canvas size");
+    canvasAndContext.canvas.width = width;
+    canvasAndContext.canvas.height = height;
+  },
+
+  destroy: function NodeCanvasFactory_destroy(canvasAndContext) {
+    assert(canvasAndContext.canvas, "Canvas is not specified");
+
+    // Zeroing the width and height cause Firefox to release graphics
+    // resources immediately, which can greatly reduce memory consumption.
+    canvasAndContext.canvas.width = 0;
+    canvasAndContext.canvas.height = 0;
+    canvasAndContext.canvas = null;
+    canvasAndContext.context = null;
+  },
+};
+
+const pdfjsLib = require("pdfjs-dist/legacy/build/pdf.js");
+
+// Some PDFs need external cmaps.
+const CMAP_URL = "../../../node_modules/pdfjs-dist/cmaps/";
+const CMAP_PACKED = true;
+
+// Where the standard fonts are located.
+const STANDARD_FONT_DATA_URL =
+  "../../../node_modules/pdfjs-dist/standard_fonts/";
+
+// Loading file from file system into typed array.
+const pdfPath =
+  process.argv[2] || "../../../web/compressed.tracemonkey-pldi-09.pdf";
+const data = new Uint8Array(fs.readFileSync(pdfPath));
+
+// Load the PDF file.
+const loadingTask = pdfjsLib.getDocument({
+  data,
+  cMapUrl: CMAP_URL,
+  cMapPacked: CMAP_PACKED,
+  standardFontDataUrl: STANDARD_FONT_DATA_URL,
+});
+
+(async function () {
+  try {
+    const pdfDocument = await loadingTask.promise;
+    console.log("# PDF document loaded.");
+    // Get the first page.
+    const page = await pdfDocument.getPage(1);
+    // Render the page on a Node canvas with 100% scale.
+    const viewport = page.getViewport({ scale: 1.0 });
+    const canvasFactory = new NodeCanvasFactory();
+    const canvasAndContext = canvasFactory.create(
+      viewport.width,
+      viewport.height
+    );
+    const renderContext = {
+      canvasContext: canvasAndContext.context,
+      viewport,
+      canvasFactory,
+    };
+
+    const renderTask = page.render(renderContext);
+    await renderTask.promise;
+    // Convert the canvas to an image buffer.
+    const image = canvasAndContext.canvas.toBuffer();
+    fs.writeFile("output.png", image, function (error) {
+      if (error) {
+        console.error("Error: " + error);
+      } else {
+        console.log(
+          "Finished converting first page of PDF file to a PNG image."
+        );
+      }
+    });
+    // Release page resources.
+    page.cleanup();
+  } catch (reason) {
+    console.log(reason);
+  }
+})();

+ 128 - 0
pdf.js/examples/node/pdf2svg.js

@@ -0,0 +1,128 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+//
+// Node tool to dump SVG output into a file.
+//
+
+const fs = require("fs");
+const util = require("util");
+const path = require("path");
+const stream = require("stream");
+
+// HACK few hacks to let PDF.js be loaded not as a module in global space.
+require("./domstubs.js").setStubs(global);
+
+// Run `gulp dist-install` to generate 'pdfjs-dist' npm package files.
+const pdfjsLib = require("pdfjs-dist/legacy/build/pdf.js");
+
+// Some PDFs need external cmaps.
+const CMAP_URL = "../../node_modules/pdfjs-dist/cmaps/";
+const CMAP_PACKED = true;
+
+// Loading file from file system into typed array
+const pdfPath =
+  process.argv[2] || "../../web/compressed.tracemonkey-pldi-09.pdf";
+const data = new Uint8Array(fs.readFileSync(pdfPath));
+
+const outputDirectory = "./svgdump";
+
+try {
+  // Note: This creates a directory only one level deep. If you want to create
+  // multiple subdirectories on the fly, use the mkdirp module from npm.
+  fs.mkdirSync(outputDirectory);
+} catch (e) {
+  if (e.code !== "EEXIST") {
+    throw e;
+  }
+}
+
+// Dumps svg outputs to a folder called svgdump
+function getFilePathForPage(pageNum) {
+  const name = path.basename(pdfPath, path.extname(pdfPath));
+  return path.join(outputDirectory, `${name}-${pageNum}.svg`);
+}
+
+/**
+ * A readable stream which offers a stream representing the serialization of a
+ * given DOM element (as defined by domstubs.js).
+ *
+ * @param {object} options
+ * @param {DOMElement} options.svgElement The element to serialize
+ */
+function ReadableSVGStream(options) {
+  if (!(this instanceof ReadableSVGStream)) {
+    return new ReadableSVGStream(options);
+  }
+  stream.Readable.call(this, options);
+  this.serializer = options.svgElement.getSerializer();
+}
+util.inherits(ReadableSVGStream, stream.Readable);
+// Implements https://nodejs.org/api/stream.html#stream_readable_read_size_1
+ReadableSVGStream.prototype._read = function () {
+  let chunk;
+  while ((chunk = this.serializer.getNext()) !== null) {
+    if (!this.push(chunk)) {
+      return;
+    }
+  }
+  this.push(null);
+};
+
+// Streams the SVG element to the given file path.
+function writeSvgToFile(svgElement, filePath) {
+  let readableSvgStream = new ReadableSVGStream({
+    svgElement,
+  });
+  const writableStream = fs.createWriteStream(filePath);
+  return new Promise(function (resolve, reject) {
+    readableSvgStream.once("error", reject);
+    writableStream.once("error", reject);
+    writableStream.once("finish", resolve);
+    readableSvgStream.pipe(writableStream);
+  }).catch(function (err) {
+    readableSvgStream = null; // Explicitly null because of v8 bug 6512.
+    writableStream.end();
+    throw err;
+  });
+}
+
+// Will be using async/await to load document, pages and misc data.
+const loadingTask = pdfjsLib.getDocument({
+  data,
+  cMapUrl: CMAP_URL,
+  cMapPacked: CMAP_PACKED,
+  fontExtraProperties: true,
+});
+(async function () {
+  const doc = await loadingTask.promise;
+  const numPages = doc.numPages;
+  console.log("# Document Loaded");
+  console.log(`Number of Pages: ${numPages}`);
+  console.log();
+
+  for (let pageNum = 1; pageNum <= numPages; pageNum++) {
+    try {
+      const page = await doc.getPage(pageNum);
+      console.log(`# Page ${pageNum}`);
+      const viewport = page.getViewport({ scale: 1.0 });
+      console.log(`Size: ${viewport.width}x${viewport.height}`);
+      console.log();
+
+      const opList = await page.getOperatorList();
+      const svgGfx = new pdfjsLib.SVGGraphics(
+        page.commonObjs,
+        page.objs,
+        /* forceDataSchema = */ true
+      );
+      svgGfx.embedFonts = true;
+      const svg = await svgGfx.getSVG(opList, viewport);
+      await writeSvgToFile(svg, getFilePathForPage(pageNum));
+      // Release page resources.
+      page.cleanup();
+    } catch (err) {
+      console.log(`Error: ${err}`);
+    }
+  }
+  console.log("# End of Document");
+})();

+ 14 - 0
pdf.js/examples/text-only/index.html

@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="UTF-8">
+    <title>Text-only PDF.js example</title>
+    <script src="../../node_modules/pdfjs-dist/build/pdf.js"></script>
+    <script src="pdf2svg.js"></script>
+</head>
+<body>
+  <p>Text-only PDF.js example</p>
+  <div id="pageContainer" style="display: inline-block; border: solid 1px black;">
+  </div>
+</body>
+</html>

+ 72 - 0
pdf.js/examples/text-only/pdf2svg.js

@@ -0,0 +1,72 @@
+/* Copyright 2014 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+const PDF_PATH = "../../web/compressed.tracemonkey-pldi-09.pdf";
+const PAGE_NUMBER = 1;
+const PAGE_SCALE = 1.5;
+const SVG_NS = "http://www.w3.org/2000/svg";
+
+pdfjsLib.GlobalWorkerOptions.workerSrc =
+  "../../node_modules/pdfjs-dist/build/pdf.worker.js";
+
+function buildSVG(viewport, textContent) {
+  // Building SVG with size of the viewport (for simplicity)
+  const svg = document.createElementNS(SVG_NS, "svg:svg");
+  svg.setAttribute("width", viewport.width + "px");
+  svg.setAttribute("height", viewport.height + "px");
+  // items are transformed to have 1px font size
+  svg.setAttribute("font-size", 1);
+
+  // processing all items
+  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.
+    const tx = pdfjsLib.Util.transform(
+      pdfjsLib.Util.transform(viewport.transform, textItem.transform),
+      [1, 0, 0, -1, 0, 0]
+    );
+    const style = textContent.styles[textItem.fontName];
+    // adding text element
+    const text = document.createElementNS(SVG_NS, "svg:text");
+    text.setAttribute("transform", "matrix(" + tx.join(" ") + ")");
+    text.setAttribute("font-family", style.fontFamily);
+    text.textContent = textItem.str;
+    svg.append(text);
+  });
+  return svg;
+}
+
+async function pageLoaded() {
+  // Loading document and page text content
+  const loadingTask = pdfjsLib.getDocument({ url: PDF_PATH });
+  const pdfDocument = await loadingTask.promise;
+  const page = await pdfDocument.getPage(PAGE_NUMBER);
+  const viewport = page.getViewport({ scale: PAGE_SCALE });
+  const textContent = await page.getTextContent();
+  // building SVG and adding that to the DOM
+  const svg = buildSVG(viewport, textContent);
+  document.getElementById("pageContainer").append(svg);
+  // Release page resources.
+  page.cleanup();
+}
+
+document.addEventListener("DOMContentLoaded", function () {
+  if (typeof pdfjsLib === "undefined") {
+    // eslint-disable-next-line no-alert
+    alert("Please build the pdfjs-dist library using\n  `gulp dist-install`");
+    return;
+  }
+  pageLoaded();
+});

+ 9 - 0
pdf.js/examples/webpack/.eslintrc

@@ -0,0 +1,9 @@
+{
+  "extends": [
+    "../.eslintrc"
+  ],
+
+  "env": {
+    "node": true,
+  },
+}

+ 1 - 0
pdf.js/examples/webpack/.gitignore

@@ -0,0 +1 @@
+node_modules/

+ 35 - 0
pdf.js/examples/webpack/README.md

@@ -0,0 +1,35 @@
+## Overview
+
+Example to demonstrate PDF.js library usage with Webpack.
+
+## Getting started
+
+Install the example dependencies and build the project:
+
+    $ gulp dist-install
+    $ cd examples/webpack
+    $ npm install
+    $ ./node_modules/webpack/bin/webpack.js
+
+You can observe the build results by running `gulp server` and navigating to
+http://localhost:8888/examples/webpack/index.html.
+
+Refer to the `main.js` and `webpack.config.js` files for the source code.
+Note that PDF.js packaging requires packaging of the main application and
+the worker code, and the `workerSrc` path shall be set to the latter file.
+
+### Minification
+
+If you are configuring Webpack to output a minified build, please note that you
+*must* configure the minifier to keep original class/function names intact;
+otherwise the build is not guaranteed to work correctly.
+
+## Worker loading
+
+If you are getting the `Setting up fake worker` warning, make sure you are
+importing `pdfjs-dist/webpack` which is the zero-configuration method for
+Webpack users. Installing `worker-loader` is no longer necessary.
+
+    import * as pdfjsLib from 'pdfjs-dist/webpack';
+
+For a full working example refer to [this repository](https://github.com/yurydelendik/pdfjs-react).

+ 11 - 0
pdf.js/examples/webpack/index.html

@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8">
+  <title>webpack example</title>
+  <script src="../../build/webpack/main.bundle.js"></script>
+</head>
+<body>
+  <canvas id="theCanvas"></canvas>
+</body>
+</html>

+ 35 - 0
pdf.js/examples/webpack/main.js

@@ -0,0 +1,35 @@
+// Any copyright is dedicated to the Public Domain.
+// http://creativecommons.org/licenses/publicdomain/
+
+// Hello world example for webpack.
+
+const pdfjsLib = require("pdfjs-dist");
+
+const pdfPath = "../learning/helloworld.pdf";
+
+// Setting worker path to worker bundle.
+pdfjsLib.GlobalWorkerOptions.workerSrc =
+  "../../build/webpack/pdf.worker.bundle.js";
+
+// Loading a document.
+const loadingTask = pdfjsLib.getDocument(pdfPath);
+loadingTask.promise
+  .then(function (pdfDocument) {
+    // Request a first page
+    return pdfDocument.getPage(1).then(function (pdfPage) {
+      // Display page on the existing canvas with 100% scale.
+      const viewport = pdfPage.getViewport({ scale: 1.0 });
+      const canvas = document.getElementById("theCanvas");
+      canvas.width = viewport.width;
+      canvas.height = viewport.height;
+      const ctx = canvas.getContext("2d");
+      const renderTask = pdfPage.render({
+        canvasContext: ctx,
+        viewport,
+      });
+      return renderTask.promise;
+    });
+  })
+  .catch(function (reason) {
+    console.error("Error: " + reason);
+  });

+ 12 - 0
pdf.js/examples/webpack/package.json

@@ -0,0 +1,12 @@
+{
+  "name": "webpack-pdf.js-example",
+  "version": "0.1.0",
+  "scripts": {
+    "build": "webpack"
+  },
+  "devDependencies": {
+    "webpack": "^5.11.1",
+    "webpack-cli": "^4.3.1",
+    "pdfjs-dist": "../../node_modules/pdfjs-dist"
+  }
+}

+ 16 - 0
pdf.js/examples/webpack/webpack.config.js

@@ -0,0 +1,16 @@
+const webpack = require("webpack"); // eslint-disable-line no-unused-vars
+const path = require("path");
+
+module.exports = {
+  context: __dirname,
+  entry: {
+    main: "./main.js",
+    "pdf.worker": "pdfjs-dist/build/pdf.worker.entry",
+  },
+  mode: "none",
+  output: {
+    path: path.join(__dirname, "../../build/webpack"),
+    publicPath: "../../build/webpack/",
+    filename: "[name].bundle.js",
+  },
+};

+ 22 - 0
pdf.js/extensions/chromium/.eslintrc

@@ -0,0 +1,22 @@
+{
+  "extends": [
+    ../../.eslintrc
+  ],
+
+  "env": {
+    "webextensions": true
+  },
+
+  "plugins": [
+    "mozilla"
+  ],
+
+  "parserOptions": {
+    "sourceType": "script"
+  },
+
+  "rules": {
+    "mozilla/import-globals": "error",
+    "no-var": "off",
+  },
+}

+ 1 - 0
pdf.js/extensions/chromium/.gitignore

@@ -0,0 +1 @@
+content/

+ 223 - 0
pdf.js/extensions/chromium/contentscript.js

@@ -0,0 +1,223 @@
+/*
+Copyright 2014 Mozilla Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+"use strict";
+
+var VIEWER_URL = chrome.extension.getURL("content/web/viewer.html");
+
+function getViewerURL(pdf_url) {
+  return VIEWER_URL + "?file=" + encodeURIComponent(pdf_url);
+}
+
+if (CSS.supports("animation", "0s")) {
+  document.addEventListener("animationstart", onAnimationStart, true);
+} else {
+  document.addEventListener("webkitAnimationStart", onAnimationStart, true);
+}
+
+function onAnimationStart(event) {
+  if (event.animationName === "pdfjs-detected-object-or-embed") {
+    watchObjectOrEmbed(event.target);
+  }
+}
+
+// Called for every <object> or <embed> element in the page.
+// This may change the type, src/data attributes and/or the child nodes of the
+// element. This function only affects elements for the first call. Subsequent
+// invocations have no effect.
+function watchObjectOrEmbed(elem) {
+  var mimeType = elem.type;
+  if (mimeType && mimeType.toLowerCase() !== "application/pdf") {
+    return;
+  }
+  // <embed src> <object data>
+  var srcAttribute = "src" in elem ? "src" : "data";
+  var path = elem[srcAttribute];
+  if (!mimeType && !/\.pdf($|[?#])/i.test(path)) {
+    return;
+  }
+
+  if (
+    elem.tagName === "EMBED" &&
+    elem.name === "plugin" &&
+    elem.parentNode === document.body &&
+    elem.parentNode.childElementCount === 1 &&
+    elem.src === location.href
+  ) {
+    // This page is most likely Chrome's default page that embeds a PDF file.
+    // The fact that the extension's background page did not intercept and
+    // redirect this PDF request means that this PDF cannot be opened by PDF.js,
+    // e.g. because it is a response to a POST request (as in #6174).
+    // A reduced test case to test PDF response to POST requests is available at
+    // https://robwu.nl/pdfjs/issue6174/.
+    // Until #4483 is fixed, POST requests should be ignored.
+    return;
+  }
+  if (elem.tagName === "EMBED" && elem.src === "about:blank") {
+    // Starting from Chrome 76, internal embeds do not have the original URL,
+    // but "about:blank" instead.
+    // See https://github.com/mozilla/pdf.js/issues/11137
+    return;
+  }
+
+  if (elem.__I_saw_this_element) {
+    return;
+  }
+  elem.__I_saw_this_element = true;
+
+  var tagName = elem.tagName.toUpperCase();
+  var updateEmbedOrObject;
+  if (tagName === "EMBED") {
+    updateEmbedOrObject = updateEmbedElement;
+  } else if (tagName === "OBJECT") {
+    updateEmbedOrObject = updateObjectElement;
+  } else {
+    return;
+  }
+
+  var lastSrc;
+  var isUpdating = false;
+
+  function updateViewerFrame() {
+    if (!isUpdating) {
+      isUpdating = true;
+      try {
+        if (lastSrc !== elem[srcAttribute]) {
+          updateEmbedOrObject(elem);
+          lastSrc = elem[srcAttribute];
+        }
+      } finally {
+        isUpdating = false;
+      }
+    }
+  }
+
+  updateViewerFrame();
+
+  // Watch for page-initiated changes of the src/data attribute.
+  var srcObserver = new MutationObserver(updateViewerFrame);
+  srcObserver.observe(elem, {
+    attributes: true,
+    childList: false,
+    characterData: false,
+    attributeFilter: [srcAttribute],
+  });
+}
+
+// Display the PDF Viewer in an <embed>.
+function updateEmbedElement(elem) {
+  if (elem.type === "text/html" && elem.src.lastIndexOf(VIEWER_URL, 0) === 0) {
+    // The viewer is already shown.
+    return;
+  }
+  // The <embed> tag needs to be removed and re-inserted before any src changes
+  // are effective.
+  var parentNode = elem.parentNode;
+  var nextSibling = elem.nextSibling;
+  if (parentNode) {
+    elem.remove();
+  }
+  elem.type = "text/html";
+  elem.src = getEmbeddedViewerURL(elem.src);
+  if (parentNode) {
+    nextSibling.before(elem);
+  }
+}
+
+// Display the PDF Viewer in an <object>.
+function updateObjectElement(elem) {
+  // <object> elements are terrible. Experiments (in49.0.2623.75) show that the
+  // following happens:
+  // - When fallback content is shown (e.g. because the built-in PDF Viewer is
+  //   disabled), updating the "data" attribute has no effect. Not surprising
+  //   considering that HTMLObjectElement::m_useFallbackContent is not reset
+  //   once it is set to true. Source:
+  //   WebKit/Source/core/html/HTMLObjectElement.cpp#378 (rev 749fe30d676b6c14).
+  // - When the built-in PDF Viewer plugin is enabled, updating the "data"
+  //   attribute reloads the content (provided that the type was correctly set).
+  // - When <object type=text/html data="chrome-extension://..."> is used
+  //   (tested with a data-URL, data:text/html,<object...>, the extension's
+  //   origin allowlist is not set up, so the viewer can't load the PDF file.
+  // - The content of the <object> tag may be affected by <param> tags.
+  //
+  // To make sure that our solution works for all cases, we will insert a frame
+  // as fallback content and force the <object> tag to render its fallback
+  // content.
+  var iframe = elem.firstElementChild;
+  if (!iframe || !iframe.__inserted_by_pdfjs) {
+    iframe = createFullSizeIframe();
+    elem.textContent = "";
+    elem.append(iframe);
+    iframe.__inserted_by_pdfjs = true;
+  }
+  iframe.src = getEmbeddedViewerURL(elem.data);
+
+  // Some bogus content type that is not handled by any plugin.
+  elem.type = "application/not-a-pee-dee-eff-type";
+  // Force the <object> to reload and render its fallback content.
+  elem.data += "";
+
+  // Usually the browser renders plugin content in this tag, which is completely
+  // oblivious of styles such as padding, but we insert and render child nodes,
+  // so force padding to be zero to avoid undesired dimension changes.
+  elem.style.padding = "0";
+
+  // <object> and <embed> elements have a "display:inline" style by default.
+  // Despite this property, when a plugin is loaded in the tag, the tag is
+  // treated like "display:inline-block". However, when the browser does not
+  // render plugin content, the <object> tag does not behave like that, and as
+  // a result the width and height is ignored.
+  // Force "display:inline-block" to make sure that the width/height as set by
+  // web pages is respected.
+  // (<embed> behaves as expected with the default display value, but setting it
+  // to display:inline-block doesn't hurt).
+  elem.style.display = "inline-block";
+}
+
+// Create an <iframe> element without borders that takes the full width and
+// height.
+function createFullSizeIframe() {
+  var iframe = document.createElement("iframe");
+  iframe.style.background = "none";
+  iframe.style.border = "none";
+  iframe.style.borderRadius = "none";
+  iframe.style.boxShadow = "none";
+  iframe.style.cssFloat = "none";
+  iframe.style.display = "block";
+  iframe.style.height = "100%";
+  iframe.style.margin = "0";
+  iframe.style.maxHeight = "none";
+  iframe.style.maxWidth = "none";
+  iframe.style.position = "static";
+  iframe.style.transform = "none";
+  iframe.style.visibility = "visible";
+  iframe.style.width = "100%";
+  return iframe;
+}
+
+// Get the viewer URL, provided that the path is a valid URL.
+function getEmbeddedViewerURL(path) {
+  var fragment = /^([^#]*)(#.*)?$/.exec(path);
+  path = fragment[1];
+  fragment = fragment[2] || "";
+
+  // Resolve relative path to document.
+  var a = document.createElement("a");
+  a.href = document.baseURI;
+  a.href = path;
+  path = a.href;
+  return getViewerURL(path) + fragment;
+}

+ 22 - 0
pdf.js/extensions/chromium/contentstyle.css

@@ -0,0 +1,22 @@
+/**
+ * Detect creation of <embed> and <object> tags.
+ */
+@-webkit-keyframes pdfjs-detected-object-or-embed {
+  from {
+    /* empty */
+  }
+}
+@keyframes pdfjs-detected-object-or-embed {
+  from {
+    /* empty */
+  }
+}
+object,
+embed {
+  -webkit-animation-delay: 0s !important;
+  -webkit-animation-name: pdfjs-detected-object-or-embed !important;
+  -webkit-animation-play-state: running !important;
+  animation-delay: 0s !important;
+  animation-name: pdfjs-detected-object-or-embed !important;
+  animation-play-state: running !important;
+}

+ 128 - 0
pdf.js/extensions/chromium/extension-router.js

@@ -0,0 +1,128 @@
+/*
+Copyright 2013 Mozilla Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+"use strict";
+
+(function ExtensionRouterClosure() {
+  var VIEWER_URL = chrome.extension.getURL("content/web/viewer.html");
+  var CRX_BASE_URL = chrome.extension.getURL("/");
+
+  var schemes = [
+    "http",
+    "https",
+    "ftp",
+    "file",
+    "chrome-extension",
+    "blob",
+    "data",
+    // Chromium OS
+    "filesystem",
+    // Chromium OS, shorthand for filesystem:<origin>/external/
+    "drive",
+  ];
+
+  /**
+   * @param {string} url The URL prefixed with chrome-extension://.../
+   * @returns {string|undefined} The percent-encoded URL of the (PDF) file.
+   */
+  function parseExtensionURL(url) {
+    url = url.substring(CRX_BASE_URL.length);
+    // Find the (url-encoded) colon and verify that the scheme is allowed.
+    var schemeIndex = url.search(/:|%3A/i);
+    if (schemeIndex === -1) {
+      return undefined;
+    }
+    var scheme = url.slice(0, schemeIndex).toLowerCase();
+    if (schemes.includes(scheme)) {
+      url = url.split("#")[0];
+      if (url.charAt(schemeIndex) === ":") {
+        url = encodeURIComponent(url);
+      }
+      return url;
+    }
+    return undefined;
+  }
+
+  // TODO(rob): Use declarativeWebRequest once declared URL-encoding is
+  //            supported, see http://crbug.com/273589
+  //            (or rewrite the query string parser in viewer.js to get it to
+  //             recognize the non-URL-encoded PDF URL.)
+  chrome.webRequest.onBeforeRequest.addListener(
+    function (details) {
+      // This listener converts chrome-extension://.../http://...pdf to
+      // chrome-extension://.../content/web/viewer.html?file=http%3A%2F%2F...pdf
+      var url = parseExtensionURL(details.url);
+      if (url) {
+        url = VIEWER_URL + "?file=" + url;
+        var i = details.url.indexOf("#");
+        if (i > 0) {
+          url += details.url.slice(i);
+        }
+        console.log("Redirecting " + details.url + " to " + url);
+        return { redirectUrl: url };
+      }
+      return undefined;
+    },
+    {
+      types: ["main_frame", "sub_frame"],
+      urls: schemes.map(function (scheme) {
+        // Format: "chrome-extension://[EXTENSIONID]/<scheme>*"
+        return CRX_BASE_URL + scheme + "*";
+      }),
+    },
+    ["blocking"]
+  );
+
+  // When session restore is used, viewer pages may be loaded before the
+  // webRequest event listener is attached (= page not found).
+  // Or the extension could have been crashed (OOM), leaving a sad tab behind.
+  // Reload these tabs.
+  chrome.tabs.query(
+    {
+      url: CRX_BASE_URL + "*:*",
+    },
+    function (tabsFromLastSession) {
+      for (const { id } of tabsFromLastSession) {
+        chrome.tabs.reload(id);
+      }
+    }
+  );
+  console.log("Set up extension URL router.");
+
+  Object.keys(localStorage).forEach(function (key) {
+    // The localStorage item is set upon unload by chromecom.js.
+    var parsedKey = /^unload-(\d+)-(true|false)-(.+)/.exec(key);
+    if (parsedKey) {
+      var timeStart = parseInt(parsedKey[1], 10);
+      var isHidden = parsedKey[2] === "true";
+      var url = parsedKey[3];
+      if (Date.now() - timeStart < 3000) {
+        // Is it a new item (younger than 3 seconds)? Assume that the extension
+        // just reloaded, so restore the tab (work-around for crbug.com/511670).
+        chrome.tabs.create({
+          url:
+            chrome.runtime.getURL("restoretab.html") +
+            "?" +
+            encodeURIComponent(url) +
+            "#" +
+            encodeURIComponent(localStorage.getItem(key)),
+          active: !isHidden,
+        });
+      }
+      localStorage.removeItem(key);
+    }
+  });
+})();

BIN
pdf.js/extensions/chromium/icon128.png


BIN
pdf.js/extensions/chromium/icon16.png


BIN
pdf.js/extensions/chromium/icon19.png


BIN
pdf.js/extensions/chromium/icon38.png


BIN
pdf.js/extensions/chromium/icon48.png


+ 71 - 0
pdf.js/extensions/chromium/manifest.json

@@ -0,0 +1,71 @@
+{
+  "manifest_version": 2,
+  "name": "PDF Viewer",
+  "version": "PDFJSSCRIPT_VERSION",
+  "description": "Uses HTML5 to display PDF files directly in the browser.",
+  "icons": {
+    "128": "icon128.png",
+    "48": "icon48.png",
+    "16": "icon16.png"
+  },
+  "permissions": [
+    "fileBrowserHandler",
+    "webRequest", "webRequestBlocking",
+    "<all_urls>",
+    "tabs",
+    "webNavigation",
+    "storage"
+  ],
+  "content_scripts": [{
+    "matches": [
+      "http://*/*",
+      "https://*/*",
+      "ftp://*/*",
+      "file://*/*"
+    ],
+    "run_at": "document_start",
+    "all_frames": true,
+    "css": ["contentstyle.css"],
+    "js": ["contentscript.js"]
+  }],
+  "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
+  "file_browser_handlers": [{
+    "id": "open-as-pdf",
+    "default_title": "Open with PDF Viewer",
+    "file_filters": [
+      "filesystem:*.pdf"
+    ]
+  }],
+  "storage": {
+    "managed_schema": "preferences_schema.json"
+  },
+  "options_ui": {
+    "page": "options/options.html",
+    "chrome_style": true
+  },
+  "options_page": "options/options.html",
+  "background": {
+    "page": "pdfHandler.html"
+  },
+  "page_action": {
+    "default_icon": {
+      "19": "icon19.png",
+      "38": "icon38.png"
+    },
+    "default_title": "Show PDF URL",
+    "default_popup": "pageActionPopup.html"
+  },
+  "incognito": "split",
+  "web_accessible_resources": [
+    "content/web/viewer.html",
+    "http:/*",
+    "https:/*",
+    "ftp:/*",
+    "file:/*",
+    "chrome-extension:/*",
+    "blob:*",
+    "data:*",
+    "filesystem:/*",
+    "drive:*"
+  ]
+}

+ 153 - 0
pdf.js/extensions/chromium/options/migration.js

@@ -0,0 +1,153 @@
+/*
+Copyright 2016 Mozilla Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+/* eslint strict: ["error", "function"] */
+
+(function () {
+  "use strict";
+  var storageLocal = chrome.storage.local;
+  var storageSync = chrome.storage.sync;
+
+  if (!storageSync) {
+    // No sync storage area - nothing to migrate to.
+    return;
+  }
+
+  getStorageNames(function (storageKeys) {
+    storageLocal.get(storageKeys, function (values) {
+      if (!values || !Object.keys(values).length) {
+        // No local storage - nothing to migrate.
+        // ... except possibly for a renamed preference name.
+        migrateRenamedStorage();
+        return;
+      }
+      migrateToSyncStorage(values);
+    });
+  });
+
+  function getStorageNames(callback) {
+    var x = new XMLHttpRequest();
+    var schema_location = chrome.runtime.getManifest().storage.managed_schema;
+    x.open("get", chrome.runtime.getURL(schema_location));
+    x.onload = function () {
+      var storageKeys = Object.keys(x.response.properties);
+      callback(storageKeys);
+    };
+    x.responseType = "json";
+    x.send();
+  }
+
+  // Save |values| to storage.sync and delete the values with that key from
+  // storage.local.
+  function migrateToSyncStorage(values) {
+    storageSync.set(values, function () {
+      if (chrome.runtime.lastError) {
+        console.error(
+          "Failed to migrate settings due to an error: " +
+            chrome.runtime.lastError.message
+        );
+        return;
+      }
+      // Migration successful. Delete local settings.
+      storageLocal.remove(Object.keys(values), function () {
+        // In theory remove() could fail (e.g. if the browser's storage
+        // backend is corrupt), but since storageSync.set succeeded, consider
+        // the migration successful.
+        console.log(
+          "Successfully migrated preferences from local to sync storage."
+        );
+        migrateRenamedStorage();
+      });
+    });
+  }
+
+  // TODO: Remove this migration code somewhere in the future, when most users
+  // have had their chance of migrating to the new preference format.
+  // Note: We cannot modify managed preferences, so the migration logic is
+  // duplicated in web/chromecom.js too.
+  function migrateRenamedStorage() {
+    storageSync.get(
+      [
+        "enableHandToolOnLoad",
+        "cursorToolOnLoad",
+        "disableTextLayer",
+        "enhanceTextSelection",
+        "textLayerMode",
+        "showPreviousViewOnLoad",
+        "disablePageMode",
+        "viewOnLoad",
+      ],
+      function (items) {
+        // Migration code for https://github.com/mozilla/pdf.js/pull/7635.
+        if (typeof items.enableHandToolOnLoad === "boolean") {
+          if (items.enableHandToolOnLoad) {
+            storageSync.set(
+              {
+                cursorToolOnLoad: 1,
+              },
+              function () {
+                if (!chrome.runtime.lastError) {
+                  storageSync.remove("enableHandToolOnLoad");
+                }
+              }
+            );
+          } else {
+            storageSync.remove("enableHandToolOnLoad");
+          }
+        }
+        // Migration code for https://github.com/mozilla/pdf.js/pull/9479.
+        if (typeof items.disableTextLayer === "boolean") {
+          if (items.disableTextLayer) {
+            storageSync.set(
+              {
+                textLayerMode: 0,
+              },
+              function () {
+                if (!chrome.runtime.lastError) {
+                  storageSync.remove([
+                    "disableTextLayer",
+                    "enhanceTextSelection",
+                  ]);
+                }
+              }
+            );
+          } else {
+            storageSync.remove(["disableTextLayer", "enhanceTextSelection"]);
+          }
+        }
+        // Migration code for https://github.com/mozilla/pdf.js/pull/10502.
+        if (typeof items.showPreviousViewOnLoad === "boolean") {
+          if (!items.showPreviousViewOnLoad) {
+            storageSync.set(
+              {
+                viewOnLoad: 1,
+              },
+              function () {
+                if (!chrome.runtime.lastError) {
+                  storageSync.remove([
+                    "showPreviousViewOnLoad",
+                    "disablePageMode",
+                  ]);
+                }
+              }
+            );
+          } else {
+            storageSync.remove(["showPreviousViewOnLoad", "disablePageMode"]);
+          }
+        }
+      }
+    );
+  }
+})();

+ 180 - 0
pdf.js/extensions/chromium/options/options.html

@@ -0,0 +1,180 @@
+<!doctype html>
+<!--
+Copyright 2015 Mozilla Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<html>
+<head>
+<meta charset="utf-8">
+<title>PDF.js viewer options</title>
+<style>
+/* TODO: Remove as much custom CSS as possible - crbug.com/446511 */
+body {
+  min-width: 400px; /* a page at the settings page is at least 400px wide */
+  margin: 14px 17px; /* already added by default in Chrome 40.0.2212.0 */
+}
+.settings-row {
+  margin: 0.65em 0;
+}
+</style>
+</head>
+<body>
+<div id="settings-boxes"></div>
+<button id="reset-button">Restore default settings</button>
+
+<template id="checkbox-template">
+<!-- Chromium's style: //src/extensions/renderer/resources/extension.css -->
+<div class="checkbox">
+  <label>
+    <input type="checkbox">
+    <span></span>
+  </label>
+</div>
+</template>
+
+<template id="viewerCssTheme-template">
+<div class="settings-row">
+  <label>
+    <span></span>
+    <select>
+      <option value="0">Use system theme</option>
+      <option value="1">Light theme</option>
+      <option value="2">Dark theme</option>
+    </select>
+  </label>
+</div>
+</template>
+
+<template id="viewOnLoad-template">
+<div class="settings-row">
+  <label>
+    <span></span>
+    <select>
+      <option value="-1">Default</option>
+      <option value="0">Show previous position</option>
+      <option value="1">Show initial position</option>
+    </select>
+  </label>
+</div>
+</template>
+
+<template id="defaultZoomValue-template">
+<div class="settings-row">
+  <label>
+    <span></span>
+    <select>
+      <option value="auto" selected="selected">Automatic Zoom</option>
+      <option value="page-actual">Actual Size</option>
+      <option value="page-fit">Page Fit</option>
+      <option value="page-width">Page Width</option>
+      <option value="custom" class="custom-zoom" hidden></option>
+      <option value="50">50%</option>
+      <option value="75">75%</option>
+      <option value="100">100%</option>
+      <option value="125">125%</option>
+      <option value="150">150%</option>
+      <option value="200">200%</option>
+      <option value="300">300%</option>
+      <option value="400">400%</option>
+    </select>
+  </label>
+</div>
+</template>
+
+<template id="sidebarViewOnLoad-template">
+<div class="settings-row">
+  <label>
+    <span></span>
+    <select>
+      <option value="-1">Default</option>
+      <option value="0">Do not show sidebar</option>
+      <option value="1">Show thumbnails in sidebar</option>
+      <option value="2">Show document outline in sidebar</option>
+      <option value="3">Show attachments in sidebar</option>
+    </select>
+  </label>
+</div>
+</template>
+
+<template id="cursorToolOnLoad-template">
+<div class="settings-row">
+  <label>
+    <span></span>
+    <select>
+      <option value="0">Text selection tool</option>
+      <option value="1">Hand tool</option>
+    </select>
+  </label>
+</div>
+</template>
+
+<template id="textLayerMode-template">
+<div class="settings-row">
+  <label>
+    <span></span>
+    <select>
+      <option value="0">Disable text selection</option>
+      <option value="1">Enable text selection</option>
+    </select>
+  </label>
+</div>
+</template>
+
+<template id="externalLinkTarget-template">
+<div class="settings-row">
+  <label>
+    <span></span>
+    <select>
+      <option value="0">Default</option>
+      <option value="1">Current window/tab</option>
+      <option value="2">New window/tab</option>
+      <option value="3">Parent window/tab</option>
+      <option value="4">Top window/tab</option>
+    </select>
+  </label>
+</div>
+</template>
+
+<template id="scrollModeOnLoad-template">
+<div class="settings-row">
+  <label>
+    <span></span>
+    <select>
+      <option value="-1">Default</option>
+      <option value="3">Page scrolling</option>
+      <option value="0">Vertical scrolling</option>
+      <option value="1">Horizontal scrolling</option>
+      <option value="2">Wrapped scrolling</option>
+    </select>
+  </label>
+</div>
+</template>
+
+<template id="spreadModeOnLoad-template">
+<div class="settings-row">
+  <label>
+    <span></span>
+    <select>
+      <option value="-1">Default</option>
+      <option value="0">No spreads</option>
+      <option value="1">Odd spreads</option>
+      <option value="2">Even spreads</option>
+    </select>
+  </label>
+</div>
+</template>
+
+<script src="options.js"></script>
+</body>
+</html>

+ 210 - 0
pdf.js/extensions/chromium/options/options.js

@@ -0,0 +1,210 @@
+/*
+Copyright 2015 Mozilla Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+"use strict";
+var storageAreaName = chrome.storage.sync ? "sync" : "local";
+var storageArea = chrome.storage[storageAreaName];
+
+Promise.all([
+  new Promise(function getManagedPrefs(resolve) {
+    if (!chrome.storage.managed) {
+      resolve({});
+      return;
+    }
+    // Get preferences as set by the system administrator.
+    chrome.storage.managed.get(null, function (prefs) {
+      // Managed storage may be disabled, e.g. in Opera.
+      resolve(prefs || {});
+    });
+  }),
+  new Promise(function getUserPrefs(resolve) {
+    storageArea.get(null, function (prefs) {
+      resolve(prefs || {});
+    });
+  }),
+  new Promise(function getStorageSchema(resolve) {
+    // Get the storage schema - a dictionary of preferences.
+    var x = new XMLHttpRequest();
+    var schema_location = chrome.runtime.getManifest().storage.managed_schema;
+    x.open("get", chrome.runtime.getURL(schema_location));
+    x.onload = function () {
+      resolve(x.response.properties);
+    };
+    x.responseType = "json";
+    x.send();
+  }),
+])
+  .then(function (values) {
+    var managedPrefs = values[0];
+    var userPrefs = values[1];
+    var schema = values[2];
+    function getPrefValue(prefName) {
+      if (prefName in userPrefs) {
+        return userPrefs[prefName];
+      } else if (prefName in managedPrefs) {
+        return managedPrefs[prefName];
+      }
+      return schema[prefName].default;
+    }
+    var prefNames = Object.keys(schema);
+    var renderPreferenceFunctions = {};
+    // Render options
+    prefNames.forEach(function (prefName) {
+      var prefSchema = schema[prefName];
+      if (!prefSchema.title) {
+        // Don't show preferences if the title is missing.
+        return;
+      }
+
+      // A DOM element with a method renderPreference.
+      var renderPreference;
+      if (prefSchema.type === "boolean") {
+        // Most prefs are booleans, render them in a generic way.
+        renderPreference = renderBooleanPref(
+          prefSchema.title,
+          prefSchema.description,
+          prefName
+        );
+      } else if (prefSchema.type === "integer" && prefSchema.enum) {
+        // Most other prefs are integer-valued enumerations, render them in a
+        // generic way too.
+        // Unlike the renderBooleanPref branch, each preference handled by this
+        // branch still needs its own template in options.html with
+        // id="$prefName-template".
+        renderPreference = renderEnumPref(prefSchema.title, prefName);
+      } else if (prefName === "defaultZoomValue") {
+        renderPreference = renderDefaultZoomValue(prefSchema.title);
+      } else {
+        // Should NEVER be reached. Only happens if a new type of preference is
+        // added to the storage manifest.
+        console.error("Don't know how to handle " + prefName + "!");
+        return;
+      }
+
+      renderPreference(getPrefValue(prefName));
+      renderPreferenceFunctions[prefName] = renderPreference;
+    });
+
+    // Names of preferences that are displayed in the UI.
+    var renderedPrefNames = Object.keys(renderPreferenceFunctions);
+
+    // Reset button to restore default settings.
+    document.getElementById("reset-button").onclick = function () {
+      userPrefs = {};
+      storageArea.remove(prefNames, function () {
+        renderedPrefNames.forEach(function (prefName) {
+          renderPreferenceFunctions[prefName](getPrefValue(prefName));
+        });
+      });
+    };
+
+    // Automatically update the UI when the preferences were changed elsewhere.
+    chrome.storage.onChanged.addListener(function (changes, areaName) {
+      var prefs = null;
+      if (areaName === storageAreaName) {
+        prefs = userPrefs;
+      } else if (areaName === "managed") {
+        prefs = managedPrefs;
+      }
+      if (prefs) {
+        renderedPrefNames.forEach(function (prefName) {
+          var prefChanges = changes[prefName];
+          if (prefChanges) {
+            if ("newValue" in prefChanges) {
+              userPrefs[prefName] = prefChanges.newValue;
+            } else {
+              // Otherwise the pref was deleted
+              delete userPrefs[prefName];
+            }
+            renderPreferenceFunctions[prefName](getPrefValue(prefName));
+          }
+        });
+      }
+    });
+  })
+  .then(null, console.error.bind(console));
+
+function importTemplate(id) {
+  return document.importNode(document.getElementById(id).content, true);
+}
+
+// Helpers to create UI elements that display the preference, and return a
+// function which updates the UI with the preference.
+
+function renderBooleanPref(shortDescription, description, prefName) {
+  var wrapper = importTemplate("checkbox-template");
+  wrapper.title = description;
+
+  var checkbox = wrapper.querySelector('input[type="checkbox"]');
+  checkbox.onchange = function () {
+    var pref = {};
+    pref[prefName] = this.checked;
+    storageArea.set(pref);
+  };
+  wrapper.querySelector("span").textContent = shortDescription;
+  document.getElementById("settings-boxes").append(wrapper);
+
+  function renderPreference(value) {
+    checkbox.checked = value;
+  }
+  return renderPreference;
+}
+
+function renderEnumPref(shortDescription, prefName) {
+  var wrapper = importTemplate(prefName + "-template");
+  var select = wrapper.querySelector("select");
+  select.onchange = function () {
+    var pref = {};
+    pref[prefName] = parseInt(this.value);
+    storageArea.set(pref);
+  };
+  wrapper.querySelector("span").textContent = shortDescription;
+  document.getElementById("settings-boxes").append(wrapper);
+
+  function renderPreference(value) {
+    select.value = value;
+  }
+  return renderPreference;
+}
+
+function renderDefaultZoomValue(shortDescription) {
+  var wrapper = importTemplate("defaultZoomValue-template");
+  var select = wrapper.querySelector("select");
+  select.onchange = function () {
+    storageArea.set({
+      defaultZoomValue: this.value,
+    });
+  };
+  wrapper.querySelector("span").textContent = shortDescription;
+  document.getElementById("settings-boxes").append(wrapper);
+
+  function renderPreference(value) {
+    value = value || "auto";
+    select.value = value;
+    var customOption = select.querySelector("option.custom-zoom");
+    if (select.selectedIndex === -1 && value) {
+      // Custom zoom percentage, e.g. set via managed preferences.
+      // [zoom] or [zoom],[left],[top]
+      customOption.text = value.indexOf(",") > 0 ? value : value + "%";
+      customOption.value = value;
+      customOption.hidden = false;
+      customOption.selected = true;
+    } else {
+      customOption.hidden = true;
+    }
+  }
+  return renderPreference;
+}

+ 45 - 0
pdf.js/extensions/chromium/pageAction/background.js

@@ -0,0 +1,45 @@
+/*
+Copyright 2014 Mozilla Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+"use strict";
+
+(function PageActionClosure() {
+  /**
+   * @param {number} tabId - ID of tab where the page action will be shown.
+   * @param {string} url - URL to be displayed in page action.
+   */
+  function showPageAction(tabId, displayUrl) {
+    // rewriteUrlClosure in viewer.js ensures that the URL looks like
+    // chrome-extension://[extensionid]/http://example.com/file.pdf
+    var url = /^chrome-extension:\/\/[a-p]{32}\/([^#]+)/.exec(displayUrl);
+    if (url) {
+      url = url[1];
+      chrome.pageAction.setPopup({
+        tabId,
+        popup: "/pageAction/popup.html?file=" + encodeURIComponent(url),
+      });
+      chrome.pageAction.show(tabId);
+    } else {
+      console.log("Unable to get PDF url from " + displayUrl);
+    }
+  }
+
+  chrome.runtime.onMessage.addListener(function (message, sender) {
+    if (message === "showPageAction" && sender.tab) {
+      showPageAction(sender.tab.id, sender.tab.url);
+    }
+  });
+})();

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä