Skip to content
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

Improve client-side support #320

Open
tim-we opened this issue Dec 5, 2023 · 1 comment
Open

Improve client-side support #320

tim-we opened this issue Dec 5, 2023 · 1 comment

Comments

@tim-we
Copy link
Contributor

tim-we commented Dec 5, 2023

First of all thanks for this library.

Your README states:

A Portable Document Format (PDF) generation library targeting both the server- and client-side.

However the library does not work out of the box in a browser environment. Document extends Readable which uses Stream which is not defined in a browser env. To make it work you have to add polyfills. Using vite I can make it work using this configuration:

import { defineConfig } from "vite";
import { nodePolyfills } from "vite-plugin-node-polyfills";

export default defineConfig({
  plugins: [
    nodePolyfills({
      include: ["stream"]
    }),
  ]
});

I think there should be at least some documentation on how to use the library in a client-side environment if that is explicitly targeted. (Related: #207)

I'm happy to provide a PR with a new markdown file stating the above. Is there a chance that would be accepted?

I also think it would be a good idea to add a check for the existence of Stream before using it and throw a error with custom message explaining the problem and perhaps linking to the documentation (hopefully existing by then). That check should be placed in the Document constructor before

pdfjs/lib/document.js

Lines 25 to 27 in b6cdd70

super({
highWaterMark: opts.highWaterMark || 16384, // 16kB
});

Also happy to provide a PR for that.

@rkusa
Copy link
Owner

rkusa commented Dec 5, 2023

Hi, thanks for taking the time for bringing this up. I agree, the claim does not hold true anymore. It is from a time where everyone was using webpack and webpack was still polyfilling most Node dependencies by default. That being said, I'd be open to either remove the claim, or add any helpful instructions to make it work. I'd happily accept a PR (but might be slow to respond due to pdfjs not being very high on my prio right now).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants