Skip to content

Instantly share code, notes, and snippets.

@TheOnlyWayUp
Last active October 27, 2024 21:14
Show Gist options
  • Save TheOnlyWayUp/baedaee6e81ff269fe5ffc55c09428af to your computer and use it in GitHub Desktop.
Save TheOnlyWayUp/baedaee6e81ff269fe5ffc55c09428af to your computer and use it in GitHub Desktop.
Importing PDF.JS on Sveltekit

PDF.JS on Svelte(kit), Vite

mozilla/pdf.js#12389 (comment)

It seems default import doesn't work, it works with namespace import import * as pdfjs from 'pdfjs-dist';.

My deepest appreciation to the author of this comment. Thanks man ๐Ÿ™

Alright, back to the grind. Hope this was helpful

๐Ÿ™

  • Do not mess with optimized dependencies, breaks library importing on the client side
  • Ref wojtekmaj/react-pdf#782 (comment), or modify your package.json to copy the node_module's worker script to a static folder. First is easier, but leaks information to third-party services. Latter just takes a minute longer.
@GleamTech
Copy link

FYI, we also offer a PDF Viewer based on PDF.js which we made easy to use with any JS framework (React, Vue, Angular, Svelte, Blazor etc).

npm install pdfjskit
import PdfViewer from "pdfjskit";

var pdfViewer = new PdfViewer({
  documentUrl: "pdfjskit/sample.pdf",
  width: "80%",
  height: 720,
  resizable: true,
  language: "en-US",
  theme: "slate, classic-dark"
});

pdfViewer.render(document.getElementById("container"));

For details, please see:
https://github.com/GleamTech/PdfJsKit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment