Repository navigation
docs: Vite plugin demo app and README for 4.6.0 #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Vite plugin demo | ||
|
|
||
| A minimal Vite app with `<pdfjs-viewer-element>` and the package's Vite plugin. Its PDF holds one scanned image compressed with CCITT. PDF.js decodes that with `wasm/jbig2.wasm`, one of the data files the plugin copies into the build. | ||
|
|
||
| ```bash | ||
| npm install | ||
| npm run build | ||
| npm run preview | ||
| ``` | ||
|
|
||
| Open the address `vite preview` prints. The left half of the page is black. | ||
|
|
||
| To see the problem the plugin solves, remove `pdfjsViewerData()` from [vite.config.js](vite.config.js) and build again. The page stays white, and the console says `Unable to decode image "img_p0_1": "Jbig2Error: JBig2 failed to initialize"`. The build has no `assets/wasm/` folder: `vite preview` answers those requests with the app's HTML page, and a static host answers 404. | ||
|
|
||
| `npm run dev` shows the image with or without the plugin, because the dev server serves the package's own files. That is why the problem only appears after a build. | ||
|
|
||
| The demo installs the published package, version 4.6.0 or later. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1"> | ||
| <title>pdfjs-viewer | Vite plugin demo</title> | ||
| <style> | ||
| /* The viewer fills what the text leaves, however many lines the text wraps to. */ | ||
| body { | ||
| display: flex; | ||
| flex-direction: column; | ||
| height: 100dvh; | ||
| margin: 0; | ||
| font-family: system-ui, sans-serif; | ||
| } | ||
|
|
||
| p { | ||
| margin: 1rem; | ||
| } | ||
|
|
||
| pdfjs-viewer-element { | ||
| flex: 1; | ||
| min-height: 0; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <p>The page holds one scanned image, compressed with CCITT. Its left half is black. Built without the plugin, the page stays white.</p> | ||
| <pdfjs-viewer-element src="/scanned.pdf"></pdfjs-viewer-element> | ||
| <script type="module" src="./main.js"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| import '@missing-elements/pdfjs-viewer' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "name": "pdfjs-viewer-vite-plugin-demo", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "vite", | ||
| "build": "vite build", | ||
| "preview": "vite preview" | ||
| }, | ||
| "dependencies": { | ||
| "@missing-elements/pdfjs-viewer": "^4.6.0" | ||
| }, | ||
| "devDependencies": { | ||
| "vite": "^8.3.8" | ||
| } | ||
| } |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { pdfjsViewerData } from '@missing-elements/pdfjs-viewer/vite' | ||
|
|
||
| // Copies the PDF.js data (WASM decoders, CMaps, fonts, ICC profiles, icons and the scripting | ||
| // sandbox) into the build output, next to the viewer files. Remove it to see the problem it solves. | ||
| export default { | ||
| plugins: [pdfjsViewerData()] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.