vinodnimbalkar / svelte-pdf

svelte-pdf provides a component for rendering PDF documents using PDF.js
https://www.npmjs.com/package/svelte-pdf
MIT License
206 stars 48 forks source link

How to use it in sveltekit project? #68

Open CHETANECINFOSOLUTIONS opened 10 months ago

CHETANECINFOSOLUTIONS commented 10 months ago

My code

<script>
import { onMount } from 'svelte';
let PdfViewer;
onMount(async () => {
        const module = await import('svelte-pdf');
        PdfViewer = module.default;
    });

</script>
<svelte:component
    this={PdfViewer}
    url="https://raw.githubusercontent.com/vinodnimbalkar/svelte-pdf/369db2f9edbf5ab8c87184193e1404340729bb3a/public/sample.pdf"/>

it shows this error

Screenshot 2024-01-25 at 12 28 14 PM
vinodnimbalkar commented 10 months ago

Hi @CHETANECINFOSOLUTIONS

<script>
    import PdfViewer from 'svelte-pdf';
</script>

<PdfViewer url='https://raw.githubusercontent.com/vinodnimbalkar/svelte-pdf/369db2f9edbf5ab8c87184193e1404340729bb3a/public/sample.pdf' />

Please check this: https://stackblitz.com/edit/sveltejs-kit-template-default-pjuhkj image

CHETANECINFOSOLUTIONS commented 10 months ago

Thank you for replying. I have tried this way also still returns same error.

AlexSimpson97 commented 7 months ago

Has anyone got this working in sveltekit? as of April 2024?

CHETANECINFOSOLUTIONS commented 7 months ago

Has anyone got this working in sveltekit? as of April 2024?

you can try using this library, it works. https://pdfjs.express/documentation/get-started/svelte

brianmazzocchi commented 7 months ago

Has anyone got this working in sveltekit? as of April 2024?

I have it working on sveltekit !

AlexSimpson97 commented 6 months ago

Has anyone got this working in sveltekit? as of April 2024?

I have it working on sveltekit !

Have you got a working repo I can take a look at?

brianmazzocchi commented 6 months ago

Has anyone got this working in sveltekit? as of April 2024?

I have it working on sveltekit !

Have you got a working repo I can take a look at?

Regrettably not, but if you want you can show me your implementation and I can help you with it

taut-and-yare commented 6 months ago

Has anyone got this working in sveltekit? as of April 2024?

I have it working on sveltekit !

Have you got a working repo I can take a look at?

Regrettably not, but if you want you can show me your implementation and I can help you with it

Unless I'm missing something there's not much implementation to talk about, so let's assume the implementation at the top (initial post on this issue). Or the one in the docs:

<script>
    import PdfViewer from 'svelte-pdf';
</script>

<PdfViewer url='./sample.pdf' />

I also get the same error: This document requires a password: Setting up fake worker failed: "Cannot load script at: http://localhost:5173/node_modules/.vite/deps/pdfjs-dist/build/pdf.worker.js".

It seems that it goes in here: https://github.com/vinodnimbalkar/svelte-pdf/blob/master/src/lib/PdfViewer.svelte#L189

But I guess that this has to do with the installation.

In my project, the pdfjs-dist/ directory is located in the root level of node_modules/ instead of in node_modules/.vite/ directory as the error reports. Additionally, upon npm run build I get this warning:

Using @sveltejs/adapter-vercel Warning: The following modules failed to locate dependencies that may (or may not) be required for your app to work: node_modules/pdfjs-dist/build/pdf.mjs

  • canvas ✔ done ✓ built in 2.57s