### Build and install PDF.js Webpack example Source: https://github.com/mozilla/pdf.js/blob/master/examples/webpack/README.md Commands to install dependencies and build the Webpack example project. ```bash $ gulp dist-install $ cd examples/webpack $ npm install $ ./node_modules/webpack/bin/webpack.js ``` -------------------------------- ### Clone and Setup PDF.js Repository Source: https://github.com/mozilla/pdf.js/wiki/Contributing Clone the PDF.js repository from GitHub and initialize submodules and install dependencies using npm. ```bash git clone git://github.com/{username}/pdf.js.git cd pdf.js ``` ```bash git submodule init git submodule update npm install ``` -------------------------------- ### Start the development server Source: https://github.com/mozilla/pdf.js/wiki/Bisecting-a-Regression Commands to navigate to the directory and launch the local server using Gulp. ```bash cd pdf.js npx gulp server ``` -------------------------------- ### Install PDF.js via NPM Source: https://github.com/mozilla/pdf.js/wiki/Setup-PDF.js-in-a-website Standard installation command for adding PDF.js as a project dependency. ```bash npm install pdfjs-dist --save ``` -------------------------------- ### Install PDF.js Dependencies Source: https://github.com/mozilla/pdf.js/blob/master/README.md Install Node.js and all necessary dependencies for PDF.js development using npm. ```bash $ npm install ``` -------------------------------- ### Run Font Tests Locally Source: https://github.com/mozilla/pdf.js/blob/master/test/font/README.md Use these commands to set up a virtual environment, install dependencies, and run the font tests locally. Ensure Python 3 and pip are installed. ```bash python3 -m venv venv source venv/bin/activate pip install fonttools npx gulp fonttest ``` -------------------------------- ### Run Talos Tests on Infrastructure Source: https://github.com/mozilla/pdf.js/wiki/Benchmarking-your-changes Example command for triggering Talos tests on Mozilla's try infrastructure. ```bash ./mach try fuzzy -q 'windows10-64-shippable opt-talos-other' --rebuild 6 --artifact ``` -------------------------------- ### Run Linting Source: https://github.com/mozilla/pdf.js/wiki/Contributing Execute the linting process to ensure code adheres to the style guide. Errors can often be automatically fixed. ```bash npx gulp lint ``` ```bash npx gulp lint --fix ``` -------------------------------- ### Start Local Development Server Source: https://github.com/mozilla/pdf.js/blob/master/README.md Run a local web server using npx gulp server to view the PDF.js viewer in a browser. This is necessary because some browsers restrict file access via 'file://' URLs. ```bash $ npx gulp server ``` -------------------------------- ### Install PDF.js via NPM Source: https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions Install generic PDF.js library builds from NPM. Refer to the official releases for more details. ```bash npm install pdfjs-dist ``` -------------------------------- ### Install PDF.js for Webpack Source: https://github.com/mozilla/pdf.js/wiki/Setup-PDF.js-in-a-website Installation command for adding PDF.js as a development dependency in Webpack projects. ```bash npm install pdfjs-dist --save-dev ``` -------------------------------- ### Generate Release Artifacts with Gulp Source: https://github.com/mozilla/pdf.js/wiki/Release-Process Run this command to install dependencies and publish release artifacts. Ensure you have fetched the latest changes from the mozilla remote. ```bash git fetch mozilla git checkout mozilla/master npm install npx gulp publish ``` -------------------------------- ### Start Viewer Without Loading PDF Source: https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions Initialize the viewer without automatically loading a PDF. A PDF can be loaded later using PDFViewerApplication.open(). ```javascript PDFViewerApplication.open({ url: "" }); ``` -------------------------------- ### Clone PDF.js Repository Source: https://github.com/mozilla/pdf.js/blob/master/docs/contents/getting_started/index.md Clone the PDF.js repository to get a local copy of the current code. Navigate into the cloned directory to begin development. ```bash $ git clone https://github.com/mozilla/pdf.js.git $ cd pdf.js ``` -------------------------------- ### Vim Syntastic Configuration for ESLint Source: https://github.com/mozilla/pdf.js/wiki/Contributing Configure Vim with Syntastic to automatically lint JavaScript files on save. Requires ESLint to be installed globally. ```vim let g:syntastic_javascript_checkers=['eslint'] ``` -------------------------------- ### Compile OpenJPEG Decoder Source: https://github.com/mozilla/pdf.js/blob/master/external/openjpeg/README.md After building the Docker image, use this command to compile the OpenJPEG decoder and place the output in the specified pdf.js external directory. Requires a Docker setup. ```bash node build.js -co /pdf.js/external/openjpeg/ ``` -------------------------------- ### Source File Layout Source: https://github.com/mozilla/pdf.js/blob/master/docs/contents/getting_started/index.md Overview of the directory structure for the PDF.js source code. This includes documentation, examples, source files for different layers, tests, and build scripts. ```plaintext ├── docs/ - website source code ├── examples/ - simple usage examples ├── extensions/ - browser extension source code ├── external/ - third party code ├── l10n/ - translation files ├── src/ - core layer │ ├── core/ │ ├── 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 ├── test/ - unit, font, reference, and integration tests ├── web/ - viewer layer ├── LICENSE ├── README.md ├── gulpfile.mjs - build scripts/logic ├── package-lock.json - pinned dependency versions └── package.json - package definition and dependencies ``` -------------------------------- ### Run the Full Test Suite Source: https://github.com/mozilla/pdf.js/wiki/Contributing Execute the complete testing framework, including unit, font, integration, and reference tests. ```bash npx gulp test ``` -------------------------------- ### Build Project Targets Source: https://github.com/mozilla/pdf.js/blob/master/AGENTS.md Commands to build the project for modern browsers or distribution. ```bash npx gulp generic ``` ```bash npx gulp dist npx gulp dist-install # Build and install locally ``` -------------------------------- ### Build qcms decoder Source: https://github.com/mozilla/pdf.js/blob/master/external/qcms/README.md Commands to clone the repository, build the Docker image, and compile the decoder. ```bash git clone https://github.com/mozilla/pdf.js.qcms/ ``` ```bash node build.js -C ``` ```bash node build.js -co /pdf.js/external/qcms/ ``` -------------------------------- ### Get PDF Document Source: https://github.com/mozilla/pdf.js/blob/master/docs/contents/examples/index.md Loads a PDF document from a given URL. This returns a PDFDocumentLoadingTask which has a promise that resolves with the PDF document object. ```javascript var loadingTask = pdfjsLib.getDocument({ url: "helloworld.pdf" }); loadingTask.promise.then(function(pdf) { // you can now use *pdf* here }); ``` -------------------------------- ### Get PDF Page Source: https://github.com/mozilla/pdf.js/blob/master/docs/contents/examples/index.md Retrieves a specific page from a loaded PDF document. This operation is asynchronous and returns a promise that resolves with the page object. ```javascript pdf.getPage(1).then(function(page) { // you can now use *page* here }); ``` -------------------------------- ### Build Docker Image for OpenJPEG Source: https://github.com/mozilla/pdf.js/blob/master/external/openjpeg/README.md Use this command to build the Docker image required for compiling the OpenJPEG decoder. Ensure Docker is set up. ```bash node build.js -C ``` -------------------------------- ### Initialize and Run PDF.js Test Slave Source: https://github.com/mozilla/pdf.js/blob/master/test/test_slave.html Initializes the Driver instance with DOM elements for scrolling, inflight requests, and output, then executes the run method. ```javascript import { Driver } from "./driver.js"; const driver = new Driver({ disableScrolling: document.getElementById("disableScrolling"), inflight: document.getElementById("inflight"), output: document.getElementById("output"), end: document.getElementById("end"), }); driver.run(); ``` -------------------------------- ### Configure Mercurial UI and Extensions Source: https://github.com/mozilla/pdf.js/wiki/Updating-pdf.js-on-Mozilla-Central Set up the ~/.hgrc file to define user identity, default MQ settings, and diff behavior. ```ini [ui] username = YOUR NAME [defaults] qnew = -Ue [extensions] hgext.mq = [diff] git = 1 showfunc = 1 unified = 8 [paths] try = ssh://hg.mozilla.org/try ``` -------------------------------- ### Manage Patches and Pushes Source: https://github.com/mozilla/pdf.js/wiki/Updating-pdf.js-on-Mozilla-Central Workflow for creating, refreshing, and pushing patches to the Try server. ```bash hg qnew bug-743264-fix -m "Bug 743264 - Update pdf.js to Version 0.2.537." ``` ```bash # copy files build ./build/mozcenral/* into mozilla-central/ root hg qrefresh ``` ```bash hg qnew try --message "try: -b do -p macosx,macosx64,win32,linux,linux32 -u all -t none" ``` ```bash hg outgoing ``` ```bash hg push -f try ``` ```bash hg qpop ``` ```bash hg export qtip > ~/projects/mine/pdf.js/patches~/bug-743264-fix.patch ``` -------------------------------- ### Generate Reference Images for Tests Source: https://github.com/mozilla/pdf.js/wiki/Contributing Create original snapshots for reference tests before making changes. Ensure your working directory is clean. ```bash npx gulp makeref ``` -------------------------------- ### Execute Performance Benchmarks Source: https://github.com/mozilla/pdf.js/wiki/Benchmarking-your-changes Commands to generate baseline and current performance measurements using the test runner. ```bash $ git checkout master $ npx gulp generic $ npx gulp components $ cd test $ node test.mjs --statsFile=stats/results/baseline.json --statsDelay=5000 --manifestFile=benchmark.json ``` ```bash $ cd .. $ git checkout $ npx gulp generic $ npx gulp components $ cd test $ node test.mjs --statsFile=stats/results/current.json --statsDelay=5000 --manifestFile=benchmark.json ``` -------------------------------- ### Build PDF.js from Source Source: https://github.com/mozilla/pdf.js/wiki/Setup-PDF.js-in-a-website Command to build the PDF.js library from the source code after cloning the repository. ```bash npx gulp generic ``` -------------------------------- ### Update Mozilla Central and Build Source: https://github.com/mozilla/pdf.js/wiki/Updating-pdf.js-on-Mozilla-Central Commands to prepare the repository and generate build artifacts for Mozilla Central. ```bash hg qpop -a ``` ```bash hg pull -u ``` ```bash gulp mozcentral ``` ```bash BASELINE= gulp mozcentralbaseline; gulp mozcentraldiff ``` -------------------------------- ### Define Benchmark Manifest Source: https://github.com/mozilla/pdf.js/wiki/Benchmarking-your-changes Create a JSON file to specify PDF files and test parameters for the test runner. ```json [ { "id": "tracemonkey-eq", "file": "pdfs/tracemonkey.pdf", "md5": "9a192d8b1a7dc652a19835f6f08098bd", "rounds": 50, "lastPage": 5, "type": "eq" } ] ``` -------------------------------- ### Initialize git bisect Source: https://github.com/mozilla/pdf.js/wiki/Bisecting-a-Regression Commands to begin the bisection process and mark the current state as broken. ```bash git bisect start git bisect bad ``` -------------------------------- ### Build Production Scripts Source: https://github.com/mozilla/pdf.js/blob/master/README.md Bundle all source files into production-ready scripts for the generic viewer. This generates 'pdf.js' and 'pdf.worker.js'. ```bash $ npx gulp generic ``` -------------------------------- ### Clone the PDF.js repository Source: https://github.com/mozilla/pdf.js/wiki/Bisecting-a-Regression Initial step to download the source code from the official repository. ```bash git clone git://github.com/mozilla/pdf.js.git ``` -------------------------------- ### Configure Event Bus Source: https://github.com/mozilla/pdf.js/wiki/Third-party-viewer-usage Instantiate an EventBus and pass it to the PDFViewer to listen for internal viewer events like pagesinit. ```javascript // Create the event bus instance for the viewer application. const eventBus = new pdfjsViewer.EventBus(); // Pass the event bus instance to the PDF viewer. const pdfViewer = new pdfjsViewer.PDFViewer({ ... eventBus: eventBus, }); // Listen for `pagesinit` events on the event bus. eventBus.on("pagesinit", function() { // Handle the `pagesinit` event here. }); ``` -------------------------------- ### Initialize PDF Viewer Source: https://github.com/mozilla/pdf.js/wiki/Third-party-viewer-usage Use the webviewerloaded event to wait for the PDFViewerApplication initialization promise. ```javascript document.addEventListener("webviewerloaded", function() { PDFViewerApplication.initializedPromise.then(function() { // The viewer has now been initialized. }) }); ``` -------------------------------- ### Build Minified PDF.js Source: https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions Use this command to build a minified version of PDF.js. Ensure your minifier is configured to keep original class/function names intact if not using this command. ```bash npx gulp minified ``` -------------------------------- ### Open PDF with Query String Source: https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions Load a PDF file by appending a query string to the viewer URL. The PDF path/URL must be encoded using encodeURIComponent(). ```html Open PDF ``` -------------------------------- ### Run Talos Tests Locally Source: https://github.com/mozilla/pdf.js/wiki/Benchmarking-your-changes Commands to execute the pdfpaint Talos test within a local Firefox build environment. ```bash ./mach talos-test -a pdfpaint ``` -------------------------------- ### Build Legacy Production Scripts Source: https://github.com/mozilla/pdf.js/blob/master/README.md Bundle source files for older browser support, generating 'pdf.js' and 'pdf.worker.js' for legacy environments. ```bash $ npx gulp generic-legacy ``` -------------------------------- ### Run Test Suites Source: https://github.com/mozilla/pdf.js/blob/master/AGENTS.md Executes various test suites including unit, integration, and font tests. ```bash npx gulp test ``` ```bash npx gulp unittest ``` ```bash npx gulp integrationtest ``` ```bash npx gulp fonttest ``` -------------------------------- ### Execute squash alias Source: https://github.com/mozilla/pdf.js/wiki/Squashing-Commits Commands to run after configuring the squash alias. ```bash git merge upstream/master git squash super-feature ``` -------------------------------- ### Prebuilt File Layout Source: https://github.com/mozilla/pdf.js/blob/master/docs/contents/getting_started/index.md Overview of the directory structure for a prebuilt version of PDF.js. This includes the build artifacts, web viewer files, and essential components. ```plaintext ├── build/ │ ├── pdf.mjs - display layer │ ├── pdf.mjs.map - display layer's source map │ ├── pdf.worker.mjs - core layer │ └── pdf.worker.mjs.map - core layer's source map ├── web/ │ ├── cmaps/ - character maps (required by core) │ ├── compressed.tracemonkey-pldi-09.pdf - PDF file for testing purposes │ ├── images/ - images for the viewer and annotation icons │ ├── locale/ - translation files │ ├── viewer.css - viewer style sheet │ ├── viewer.html - viewer layout │ ├── viewer.mjs - viewer layer │ └── viewer.mjs.map - viewer layer's source map └── LICENSE ``` -------------------------------- ### Process Fonts with Adobe FDK Source: https://github.com/mozilla/pdf.js/wiki/Debugging-PDF.js These commands demonstrate a round-trip conversion for CID fonts and updating font tables using tx and sfntedit. ```bash % tx -t1 font.otf font.cid % tx -cff font.cid font.cff % sfntedit -a CFF=font.cff font.otf % sfntedit -f font.otf ``` -------------------------------- ### Compare Benchmark Results Source: https://github.com/mozilla/pdf.js/wiki/Benchmarking-your-changes Compare two generated JSON result files to identify performance differences. ```bash $ node stats/statcmp.js stats/results/baseline.json stats/results/current.json ``` -------------------------------- ### Squash commits in a simple case Source: https://github.com/mozilla/pdf.js/wiki/Squashing-Commits Use this command when there are no merge commits in the history to combine multiple commits into one. ```bash git rebase -i HEAD~3 ``` -------------------------------- ### Configure a squash alias Source: https://github.com/mozilla/pdf.js/wiki/Squashing-Commits Add this alias to your .git/config to simplify the squashing process. ```bash [alias] squash = !sh -c 'git checkout upstream/master && git merge --no-commit --squash $0 && git checkout -B $0 && git commit -e' ``` -------------------------------- ### Enable All PDFBug Tools via URL Source: https://github.com/mozilla/pdf.js/wiki/Debugging-PDF.js Append this parameter to the URL to enable all available PDFBug debugging tools. For specific tools, list their IDs separated by commas. ```url #pdfBug=all ``` ```url #pdfBug=FontInspector,Stepper ``` -------------------------------- ### Perform Code Uplift Source: https://github.com/mozilla/pdf.js/wiki/Updating-pdf.js-on-Mozilla-Central Steps to cherry-pick commits and apply them to a specific branch for uplift. ```bash git checkout -b tt-aurora-fix ``` ```bash git cherry-pick ``` ```bash BASELINE= gulp mozcentralbaseline; gulp mozcentraldiff ``` ```bash qimport -n cherry-pick /mozcentral.diff; qpush; ``` -------------------------------- ### Nested Bracket Test Cases Source: https://github.com/mozilla/pdf.js/blob/master/test/bidi/BidiCharacterTest.txt Test sequences for validating the handling of deeply nested bracket pairs in the Bidi algorithm. ```text 0061 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0062 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029;1;1;2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2;0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 ``` ```text 0061 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0062 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029;1;1;2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2;0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 ``` ```text 0061 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0028 0062 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029 0029;1;1;2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1;129 128 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 ``` -------------------------------- ### Convert Font to XML and Back with TTX Source: https://github.com/mozilla/pdf.js/wiki/Debugging-PDF.js Use this command to perform a round-trip conversion of a font file, which can help isolate issues by comparing binary files or editing the XML representation. ```bash % ttx font.otf && ttx font.ttx ``` -------------------------------- ### Generate Per-Test Coverage Index Source: https://github.com/mozilla/pdf.js/blob/master/README.md Run browser tests with '--coverage-per-test' to generate an index for querying which tests cover specific lines or functions. ```bash $ npx gulp botbrowsertest --coverage-per-test ``` -------------------------------- ### Configure Git Identity and Line Endings Source: https://github.com/mozilla/pdf.js/wiki/Updating-pdf.js-on-Mozilla-Central Set global user credentials and disable automatic CRLF conversion for Windows compatibility. ```bash git config --global user.email "you@example.com" git config --global user.name "Your Name" ``` ```bash git config --global core.autocrlf false ``` -------------------------------- ### Implement legacy class pattern Source: https://github.com/mozilla/pdf.js/wiki/Style-Guide Legacy class-like objects using closures and prototypes found in existing code. ```javascript var ClassName = (function ClassNameClosure() { function ClassName(...) { ... } ClassName.prototype = { functionName(arg1, arg2, ...) { ... }, aVeryVeryVeryVeryVeryLongFunctionName( arg1, arg2, ... ), }; return ClassName; })(); ``` -------------------------------- ### Import PDF.js for Webpack Source: https://github.com/mozilla/pdf.js/blob/master/examples/webpack/README.md Use the zero-configuration import method for Webpack to avoid worker loading issues. ```javascript import * as pdfjsLib from 'pdfjs-dist/webpack.mjs'; ``` -------------------------------- ### Compare Infrastructure Results Source: https://github.com/mozilla/pdf.js/wiki/Benchmarking-your-changes URL template for comparing performance results on Treeherder using commit IDs. ```text https://treeherder.mozilla.org/perfherder/compare?originalProject=try&originalRevision=&newProject=try&newRevision=&framework=1&showOnlyImportant=1&page=1 ``` -------------------------------- ### Configure Coverage Report Output Source: https://github.com/mozilla/pdf.js/blob/master/README.md Control the output directory and formats for code coverage reports. The report can be generated in multiple formats like 'html', 'json', and 'text'. ```bash --coverage-output ``` ```bash --coverage-formats ``` -------------------------------- ### Open PDF with PDFViewerApplication API Source: https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions Use the PDFViewerApplication.open() method to load a PDF file programmatically. This method accepts a URL or raw binary data as a Uint8Array. ```javascript PDFViewerApplication.open({ url: "compressed.tracemonkey-pldi-09.pdf" }); ``` ```javascript PDFViewerApplication.open({ url: "encoded_pdf_url" }); ``` ```javascript PDFViewerApplication.open({ data: myUint8Array }); ``` -------------------------------- ### Add a New Reference Test Source: https://github.com/mozilla/pdf.js/wiki/Contributing Add a new 'eq' type reference test for a PDF file by placing it in the test/pdfs directory and running this script. For other test types or page ranges, manual manifest updates are required. ```bash node test/add_test.mjs test/pdfs/foo.pdf ``` -------------------------------- ### Add Upstream Repository Source: https://github.com/mozilla/pdf.js/wiki/Contributing Register the official PDF.js repository as an upstream remote for fetching updates. ```bash git remote add upstream git://github.com/mozilla/pdf.js.git ``` -------------------------------- ### Render PDF Page to Canvas Source: https://github.com/mozilla/pdf.js/blob/master/examples/learning/helloworld.html Use this code to load a PDF, render a specific page onto an HTML canvas, and handle scaling for different screen densities. Ensure the workerSrc is correctly configured. ```javascript // // 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.mjs"; // // Asynchronous download PDF // const loadingTask = pdfjsLib.getDocument({ url }); 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); ``` -------------------------------- ### PDF.js GeckoView Import Map Source: https://github.com/mozilla/pdf.js/blob/master/web/viewer-geckoview.html Defines the import map for the PDF.js viewer in a GeckoView environment, aliasing various modules to their respective paths within the project or node_modules. ```json { "imports": { "pdfjs/": "../src/", "pdfjs-lib": "../src/pdf.js", "pdfjs-web/": "./", "fluent-bundle": "../node_modules/@fluent/bundle/esm/index.js", "fluent-dom": "../node_modules/@fluent/dom/esm/index.js", "cached-iterable": "../node_modules/cached-iterable/src/index.mjs", "display-binary_data_factory": "../src/display/binary_data_factory.js", "display-network_stream": "../src/display/network_stream.js", "display-node_utils": "../src/display/stubs.js", "web-alt_text_manager": "./stubs-geckoview.js", "web-annotation_editor_params": "./stubs-geckoview.js", "web-download_manager": "./download_manager.js", "web-external_services": "./genericcom.js", "web-new_alt_text_manager": "./stubs-geckoview.js", "web-null_l10n": "./genericl10n.js", "web-pdf_attachment_viewer": "./stubs-geckoview.js", "web-pdf_cursor_tools": "./stubs-geckoview.js", "web-pdf_document_properties": "./stubs-geckoview.js", "web-pdf_find_bar": "./stubs-geckoview.js", "web-pdf_layer_viewer": "./stubs-geckoview.js", "web-pdf_outline_viewer": "./stubs-geckoview.js", "web-pdf_presentation_mode": "./stubs-geckoview.js", "web-pdf_thumbnail_viewer": "./stubs-geckoview.js", "web-preferences": "./genericcom.js", "web-print_service": "./pdf_print_service.js", "web-secondary_toolbar": "./stubs-geckoview.js", "web-signature_manager": "./stubs-geckoview.js", "web-toolbar": "./toolbar-geckoview.js", "web-views_manager": "./stubs-geckoview.js" } } ``` -------------------------------- ### Import Paths for PDF.js Debugging Source: https://github.com/mozilla/pdf.js/blob/master/web/internal/debugger.html Defines the import paths for various modules used in PDF.js debugging. Ensure these paths are correctly set up in your project. ```json { "imports": { "pdfjs/": "../../src/", "pdfjs-lib": "../../src/pdf.js", "display-binary_data_factory": "../../src/display/binary_data_factory.js", "display-network_stream": "../../src/display/network_stream.js", "display-node_utils": "../../src/display/stubs.js" } } ``` -------------------------------- ### Create Feature Branch Source: https://github.com/mozilla/pdf.js/wiki/Contributing Create and switch to a new feature branch for development, based on the upstream master branch. ```bash git checkout -b {branch_name} upstream/master ``` -------------------------------- ### Lint and Format Code Source: https://github.com/mozilla/pdf.js/blob/master/AGENTS.md Commands to maintain code quality using linting and formatting tools. ```bash npx gulp lint ``` ```bash npx eslint --fix ``` -------------------------------- ### Define modern class structure Source: https://github.com/mozilla/pdf.js/wiki/Style-Guide Use the ES6 class syntax for new code implementations. ```javascript class ClassName { constructor(...) { ... } functionName(arg1, arg2, ...) { ... } aVeryVeryVeryVeryVeryLongFunctionName( arg1, arg2, ... ) } ``` -------------------------------- ### Enable PDF Bugging in Generic Viewer Source: https://github.com/mozilla/pdf.js/wiki/Debugging-PDF.js Execute this command in the JavaScript console to enable debugging tools for the generic PDF.js viewer. ```javascript PDFViewerApplication.preferences.set('pdfBugEnabled', true); ``` -------------------------------- ### Miscellaneous Bidi Test Sequences Source: https://github.com/mozilla/pdf.js/blob/master/test/bidi/BidiCharacterTest.txt Various test cases for Bidi algorithm edge cases, including directional formatting characters and mixed-direction text. ```text 061C;0;0;1;0 05D0 2067 202A 0041;1;1;1 1 x 4;3 1 0 062A 0031 002F 0032;2;1;1 2 2 2;1 2 3 0 062A 0031 002F 0032;0;0;1 2 2 2;1 2 3 0 062A 0031 002F 0032;1;1;1 2 2 2;1 2 3 0 05D0 2066 202A 2069 05D1;0;0;1 1 x 1 1;4 3 1 0 05D0 2066 202B 2069 05D1;0;0;1 1 x 1 1;4 3 1 0 05D0 2066 202C 2069 05D1;0;0;1 1 x 1 1;4 3 1 0 05D0 2066 202D 2069 05D1;0;0;1 1 x 1 1;4 3 1 0 05D0 2066 202E 2069 05D1;0;0;1 1 x 1 1;4 3 1 0 05D0 2066 2060 2069 05D1;0;0;1 1 x 1 1;4 3 1 0 0061 2067 202A 2069 0062;1;1;2 2 x 2 2;0 1 3 4 0061 2067 202C 202E 2069 0062;1;1;2 2 x x 2 2;0 1 4 5 05D0 0029 2066 202B 2069 0627;0;0;1 1 1 x 1 1;5 4 2 1 0 0661 002D 0031;0;0;2 0 0;0 1 2 0061 0020 0031 0020 0032 002D 0033;1;1;2 2 2 2 2 2 2;0 1 2 3 4 5 6 05D0 0020 0031 002D 0032;0;0;1 1 2 2 2;2 3 4 1 0 061C 0020 0031 002D 0032;0;0;1 1 2 1 2;4 3 2 1 0 061C 0020 06F1 0020 06F2 002D 06F3;0;0;1 1 2 1 2 1 2;6 5 4 3 2 1 0 ``` -------------------------------- ### Update pull request after squashing Source: https://github.com/mozilla/pdf.js/wiki/Squashing-Commits Push the squashed changes to the remote repository. ```bash git push --force origin super-feature ```