Giter VIP home page Giter VIP logo

svelte-pdf's Introduction

svelte-pdf

MadeWithSvelte.com shield npm npm

Simple svelte PDF Viewer component with controls like

  • Page navigation
  • Zoom
  • Rotation
  • Print
  • AutoFlip Page

Demo

Source code of demo page is included in example directory.

https://svelte-pdf.netlify.com

How to install

npm install svelte-pdf

How to use

Using local path

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

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

Using url

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

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

Using base64 encoded string

<script>
	import PdfViewer from 'svelte-pdf';
  const base64 =
    "JVBERi0xLjcKCjEgMCBvYmogICUgZW50cnkgcG9pbnQKPDwKICAvVHlwZSAvQ2F0YWxvZwogIC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAvTWVkaWFCb3ggWyAwIDAgMjAwIDIwMCBdCiAgL0NvdW50IDEKICAvS2lkcyBbIDMgMCBSIF0KPj4KZW5kb2JqCgozIDAgb2JqCjw8CiAgL1R5cGUgL1BhZ2UKICAvUGFyZW50IDIgMCBSCiAgL1Jlc291cmNlcyA8PAogICAgL0ZvbnQgPDwKICAgICAgL0YxIDQgMCBSIAogICAgPj4KICA+PgogIC9Db250ZW50cyA1IDAgUgo+PgplbmRvYmoKCjQgMCBvYmoKPDwKICAvVHlwZSAvRm9udAogIC9TdWJ0eXBlIC9UeXBlMQogIC9CYXNlRm9udCAvVGltZXMtUm9tYW4KPj4KZW5kb2JqCgo1IDAgb2JqICAlIHBhZ2UgY29udGVudAo8PAogIC9MZW5ndGggNDQKPj4Kc3RyZWFtCkJUCjcwIDUwIFRECi9GMSAxMiBUZgooSGVsbG8sIHdvcmxkISkgVGoKRVQKZW5kc3RyZWFtCmVuZG9iagoKeHJlZgowIDYKMDAwMDAwMDAwMCA2NTUzNSBmIAowMDAwMDAwMDEwIDAwMDAwIG4gCjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAwMDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9vdCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G";
</script>

<PdfViewer data={atob(base64)} />

Props

prop name type default Required
url string N/A Yes
data string N/A No
scale float 1.8 No
pageNum number 1 No
flipTime number 120 No
showButtons array ["navigation", "zoom", "print", "rotate", "download", "autoflip", "timeInfo", "pageInfo"] No
showBorder boolean true No
downloadFileName string N/A No

Examples

To view the examples, clone the svelte-pdf repo and install the dependencies:

$ git clone https://github.com/vinodnimbalkar/svelte-pdf.git
$ cd example
$ npm install
$ npm run dev

Then run the http://localhost:5000:

How to use it in Sapper with SSR enabled

1. Install it as part of devDependencies

When using Svelte components installed from npm, it needs the original component source (rather than any precompiled JavaScript that ships with the component). This allows the component to be rendered server-side, and also keeps your client-side app smaller...

  -- [Rich Harris](https://github.com/Rich-Harris/svelte-workshop#using-external-components)

We have to install svelte-pdf as part of devDependencies

npm install -D svelte-pdf

...this will cause it to get bundled (and therefore compiled) with your app.

2. Make our PdfViewer component SSR compatible

Since out PdfViewer component has a dependency on window object, we have to use dynamic import, from within the onMount function (which is only called on the client), so that our import code is never called on the server. Refer to the official doc here...

<script>
  import { onMount } from "svelte";
  let PdfViewer;

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

<svelte:component this={PdfViewer} url="YOUR-PDF-URL"/>

Contributing

Feel free to open an issue (or even better, send a Pull Request). Contributions are very welcome!! 😄

License

MIT © Vinod Nimbalkar

svelte-pdf's People

Contributors

aureleoules avatar bdfinst avatar d-lowl avatar dauid64 avatar dependabot[bot] avatar juljimm avatar lguzzon avatar venkateshwarans avatar vinodnimbalkar avatar webdagger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

svelte-pdf's Issues

Semver vulnerability

Running pnpm audit results in:

semver vulnerable to Regular Expression Denial of Service
Vulnerable versions <7.5.2
Patched versions    >=7.5.2
Paths:
    - [email protected] > [email protected] > @mapbox/[email protected] > [email protected] > [email protected]
    - [email protected] > [email protected] > [email protected] > @mapbox/[email protected] > [email protected] > [email protected]
More info https://github.com/advisories/GHSA-c2qf-rxjj-qqgw

I saw #56 b61420e, but wasn't sure if that would fix the warning, I haven't checked the source code...

Edit: pdfjs-dist's optional dependency canvas was the root cause, so I'm closing this

Setting up fake worker failed

I have an issue when rendering the component on my app asynchronously:

Setting up fake worker failed: "Cannot load script at: http://localhost:3000/client/app/vendors-node_modules_svelte-pdf_index_js.7eb84ba08763e11d3530.worker.js".

image

image

Any idea what the problem is?

Thanks in advance!

Update npm package

It seems the current npm package is svelte-pdf 1.0.20, using pdfjs-dist 3.8.

Here in the repo it is svelte-pdf 1.0.21, using pdfjs-dist 4.0. Could you update?

FileSaver default export

Hello,

I came accross this issue while using your amazing library:

The requested module '/node_modules/file-saver/dist/FileSaver.min.js?v=9d52a9b1' does not provide an export named 'default' (at PdfViewer.svelte:5:10)

Screenshot 2022-12-11 at 18 59 12

which is:

import FileSaver from "file-saver";

Screenshot 2022-12-11 at 18 59 51

Let me know if I can help

Unhide Scroll top button

Hi @vinodnimbalkar, first of all, thank you for you component. Is very usefull on my project. I have a question.

¿There's a way to hide the button that make a scroll to the top of page? It's no required for me but I cannot find the way to hide it.

Thanks.

Captura de pantalla 2023-09-12 193319

Support data passed directly, not via url

For use-cases where the data is already available, it would be convenient to have a data prop or similar rather than url, which necessitates constructing something like data:mimetype;charset=utf-8,<data> to pass in.

Doesn't work in Safari when used on a Sapper app

I am getting an empty result on Safari when the package is used within a Sapper app (it works fine on other browsers)

This is the code I've used, taken straight from the docs:

`<script>
import { onMount } from "svelte";
let PdfViewer;
let url = "something";

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

<svelte:component this={PdfViewer} url={url} />`

Could not read from file: ...pdf.worker.min.js

With the default example I see the pdf for 1 second and then I have error 504 (because it cannot find the file and timeouts) and I keep having this issue:

`✘ [ERROR] Could not read from file: /Users/user/Projects/Git/myproject/static/ui/node_modules/svelte-pdf/node_modules/pdfjs-dist/build/pdf.worker.min.js?url

node_modules/svelte-pdf/PdfViewer.svelte:45:24:
  45 │ ...rt pdfjsWorker from "pdfjs-dist/build/pdf.worker.min.js?url";`

I am using last version of Svelte/SvelteKit/Vite together with Tailwinds

Not able to import MJS in Astro + svelte

Okay so i have an astro site and I just added svelte (typescript), when importing svelte-pdf as per the docs I get the following error when running yarn dev:

Error could not read from file: C:\...\node_modules\svelte-pdf\node_modules\pdfjs-dist\build\pdf.worker.js

The reason really is because pdfjs uses .mjs now and no default export, so changing it to the bottom phrase works:

pdfjs.GlobalWorkerOptions.workerSrc = new URL("pdfjs-dist/build/pdf.worker.js", import.meta.url);

In case anyone has this issue, make sure to set your svelte component in astro as follows:

<Componenet client:only="svelte" />

Compile Error Svelte (Worker Import)

<script>
	// export let name;
	import {onMount} from 'svelte'
	import PdfViewer from 'svelte-pdf';
onMount(()=>{
	
});
</script>

<main>
	<div class="w-50 vh-75 pa2">
		<PdfViewer url='sample.pdf' />
	</div>
</main>

Just trying to test it out a very basic example but keep getting this error everytime I try to compile.

Error: Could not load .../node_modules/pdfjs-dist/build/pdf.worker.min.js?url (imported by node_modules/svelte-pdf/src/PdfViewer.svelte)
ENOENT: no such file or directory, open '....node_modules/pdfjs-dist/build/pdf.worker.min.js?url'

How to virtually display all PDF pages next to each other (horizontally or vertically)?

When opening a PDF file on Mac or iPad, usually all pages are next to each other and I can just scroll or swipe to see the next page, either below or on the side. It seems I need to add the buttons with svelte-pdf to navigate to the next page. Is there a way to enable scrolling/swiping (horizontally or vertically) for a more seamless user experience?

Svelte accessibility warnings present within plugin

Background

The following warnings are output to console when building a project that uses this library, version 1.0.20.

It is not expected that plugins output build warnings.

Accessibility

The code should be refactored to be more accessible.

Eval

If it's possible to not use eval, that would be great. If not, this warning should be either suppressed or a config should be provided from the package to suppress it.

web:build: 244:         {#if showButtons.includes("navigation")}
web:build: 245:           <Tooltip>
web:build: 246:             <span
web:build:                  ^
web:build: 247:               slot="activator"
web:build: 248:               class="button-control {pageNum <= 1 ? 'disabled' : null}"
web:build: 13:11:47 [vite-plugin-svelte] D:/Coding/0 - Work/dragongc/dragongc/node_modules/svelte-pdf/PdfViewer.svelte:266:12 A11y: <span> with click, keydown handlers must have an ARIA role
web:build: 264:           </Tooltip>
web:build: 265:           <Tooltip>
web:build: 266:             <span
web:build:                  ^
web:build: 267:               slot="activator"
web:build: 268:               class="button-control {pageNum >= totalPage ? 'disabled' : null}"
web:build: 13:11:47 [vite-plugin-svelte] D:/Coding/0 - Work/dragongc/dragongc/node_modules/svelte-pdf/PdfViewer.svelte:288:12 A11y: <span> with click, keydown handlers must have an ARIA role
web:build: 286:           {#if showButtons.includes("zoom")}
web:build: 287:           <Tooltip>
web:build: 288:             <span
web:build:                  ^
web:build: 289:               slot="activator"
web:build: 290:               class="button-control {scale >= maxScale ? 'disabled' : null}"
web:build: 13:11:47 [vite-plugin-svelte] D:/Coding/0 - Work/dragongc/dragongc/node_modules/svelte-pdf/PdfViewer.svelte:310:12 A11y: <span> with click, keydown handlers must have an ARIA role
web:build: 308:           </Tooltip>
web:build: 309:           <Tooltip>
web:build: 310:             <span
web:build:                  ^
web:build: 311:               slot="activator"
web:build: 312:               class="button-control {scale <= minScale ? 'disabled' : null}"
web:build: 13:11:47 [vite-plugin-svelte] D:/Coding/0 - Work/dragongc/dragongc/node_modules/svelte-pdf/PdfViewer.svelte:334:12 A11y: <span> with click, keydown handlers must have an ARIA role
web:build: 332:           {#if showButtons.includes("print")}
web:build: 333:           <Tooltip>
web:build: 334:             <span
web:build:                  ^
web:build: 335:               slot="activator"
web:build: 336:               class="button-control"
web:build: 13:11:47 [vite-plugin-svelte] D:/Coding/0 - Work/dragongc/dragongc/node_modules/svelte-pdf/PdfViewer.svelte:356:12 A11y: <span> with click, keydown handlers must have an ARIA role
web:build: 354:           {#if showButtons.includes("rotate")}
web:build: 355:           <Tooltip>
web:build: 356:             <span
web:build:                  ^
web:build: 357:               slot="activator"
web:build: 358:               class="button-control"
web:build: 13:11:47 [vite-plugin-svelte] D:/Coding/0 - Work/dragongc/dragongc/node_modules/svelte-pdf/PdfViewer.svelte:376:12 A11y: <span> with click, keydown handlers must have an ARIA role
web:build: 374:           </Tooltip>
web:build: 375:           <Tooltip>
web:build: 376:             <span
web:build:                  ^
web:build: 377:               slot="activator"
web:build: 378:               class="button-control"
web:build: 13:11:47 [vite-plugin-svelte] D:/Coding/0 - Work/dragongc/dragongc/node_modules/svelte-pdf/PdfViewer.svelte:398:12 A11y: <span> with click, keydown handlers must have an ARIA role
web:build: 396:           {#if showButtons.includes("download")}
web:build: 397:           <Tooltip>
web:build: 398:             <span
web:build:                  ^
web:build: 399:               slot="activator"
web:build: 400:               class="button-control"
web:build: 13:11:47 [vite-plugin-svelte] D:/Coding/0 - Work/dragongc/dragongc/node_modules/svelte-pdf/PdfViewer.svelte:417:12 A11y: <span> with click, keydown handlers must have an ARIA role
web:build: 415:           {#if showButtons.includes("autoflip")}
web:build: 416:           <Tooltip>
web:build: 417:             <span
web:build:                  ^
web:build: 418:               slot="activator"
web:build: 419:               class="page-info button-control"
web:build: 13:11:47 [vite-plugin-svelte] D:/Coding/0 - Work/dragongc/dragongc/node_modules/svelte-pdf/utils/Tooltip.svelte:71:2 A11y: <div> with 
mouseenter, mouseleave, mouseenter, mouseleave handlers must have an ARIA role
web:build: 69: 
web:build: 70: <div class="activator">
web:build: 71:   <div
web:build:       ^
web:build: 72:     on:mouseenter={debounce(showTooltip, 100)}
web:build: 73:     on:mouseleave={debounce(hideTooltip, 500)}
web:build: ../../node_modules/pdfjs-dist/build/pdf.js (1982:23): Use of eval in "../../node_modules/pdfjs-dist/build/pdf.js" is strongly discouraged as it poses security risks and may cause issues with minification.

Callback for loading progress?

Is there a way to pass in a callback for loading progress? I see that the underlying pdf.js has a mechanism for this but don't see a way to utilize it in svelte-pdf.

I have some very large PDFs to view and the component just sits there with no indication that the load is in progress.

I believe it just needs to be passed in to the onProgress to the loadingTask object ether during its creation or after loadingTask is created.

My svelte/javascript fu is not up to figuring out how to build and test svelte-pdf locally so I was not able to test and create a PR.

Uncaught (in promise) SyntaxError: import not found: default

I'm trying to use it with Sveltekit. I installed svelte-pdf as a dev dependency. This is what my code looks like:

<script>
	import { onMount } from 'svelte';
	let PdfViewer;

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

	export let url;
</script>

<svelte:component this={PdfViewer} {url} />

Once the component mounts, the browser gives me the error:

Uncaught (in promise) SyntaxError: import not found: default

It refers to PdfViewer.svelte:41:7 which is:

import pdfjsWorker from "/node_modules/pdfjs-dist/build/pdf.worker.entry.js?v=c744c57a";

Convert Svelte components into PDF as input type

As a developer of a frontend only project, I need a way to create a PDF and give the user a nice interface to preview and download his / her documentation.

The document includes svelte components and currently gets exported via the print engine of the browser. I wish I could just give the PDF library my Svelte Component as an input and in return get a way to display its content in a preview.

Possible ACs:

  • it is possible to accept svelte component as input type
  • it is possible to convert svelte into PDF using the browser api
  • it is possible to download the created PDF

Helpful Notes:

  • The User K J suggested using a library called html2pdf.js to convert HTML into PDF, and it looks very promising in my codepen test environment, so maybe integrating that would be already halfway of the solution. See Stackoverflow Post

Pulled into my localhost and installed with the given instructions

Hello,

I have pulled this from the git and tried installing I see I am getting 500 Internal error, is that I need to takecare of anything else? Can you please help. if I see the terminal I see this issue.

Error: Invalid `workerSrc` type.
    at set workerSrc (file:///Users/shilpag/Docker/work/newproject/testing/svelte-pdf/node_modules/pdfjs-dist/build/pdf.mjs:8099:13)
    at /Users/shilpag/Docker/work/newproject/testing/svelte-pdf/src/lib/PdfViewer.svelte:31:38
    at Object.$$render (/Users/shilpag/Docker/work/newproject/testing/svelte-pdf/node_modules/svelte/src/runtime/internal/ssr.js:156:16)
    at eval (/Users/shilpag/Docker/work/newproject/testing/svelte-pdf/src/routes/+page.svelte:11:97)
    at Object.$$render (/Users/shilpag/Docker/work/newproject/testing/svelte-pdf/node_modules/svelte/src/runtime/internal/ssr.js:156:16)
    at Object.default (/Users/shilpag/Docker/work/newproject/testing/svelte-pdf/.svelte-kit/generated/root.svelte:45:41)
    at /Users/shilpag/Docker/work/newproject/testing/svelte-pdf/node_modules/@sveltejs/kit/src/runtime/components/layout.svelte:5:41
    at Object.$$render (/Users/shilpag/Docker/work/newproject/testing/svelte-pdf/node_modules/svelte/src/runtime/internal/ssr.js:156:16)
    at /Users/shilpag/Docker/work/newproject/testing/svelte-pdf/.svelte-kit/generated/root.svelte:44:40
    at $$render (/Users/shilpag/Docker/work/newproject/testing/svelte-pdf/node_modules/svelte/src/runtime/internal/ssr.js:156:16)

Unable to open 'pdf.js'

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

<PdfViewer url='https://infocenter.nordicsemi.com/pdf/nRF51_RM_v3.0.1.pdf'></PdfViewer>

SyntaxError: ambiguous indirect export: default

Running on SvelteKit:

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

leads to

Uncaught (in promise) SyntaxError: ambiguous indirect export: default [PdfViewer.svelte:5:9](http://localhost:3000/node_modules/svelte-pdf/PdfViewer.svelte)
    rejected [id].svelte:1129
    (Async: promise callback)
    step [id].svelte:1136
    __awaiter [id].svelte:1139
    __awaiter [id].svelte:1116
    instance [id].svelte:26
    run index.mjs:18
    map self-hosted:221
    mount_component index.mjs:1427
    flush index.mjs:746
    init index.mjs:1515
    Root root.svelte:690
    createProxiedComponent svelte-hooks.js:245
    ProxyComponent proxy.js:241
    Proxy<Root> proxy.js:341
    _init start.js:649
    start start.js:533
    AsyncFunctionNext self-hosted:807
    (Async: async)
    start start.js:1099
    <anonymous> 16:454

which refers to

import FileSaver from "/node_modules/file-saver/dist/FileSaver.min.js?v=83e1d885";

to top button - cannot use href #top inside sapper

Due to the way svelte + sapper fails to work right with href hash anchors, the "go to top" arrow at the bottom of the viewer should fire javascript window.scrollTo(0, 0); code instead of using a #top href

Vertical Scrolling

Hi,
Your work here is really good. PDF file looks simple and elegant on the browser.

Is there any possibility of having a vertical scrolling option, instead of the buttons (or autoflip) to change pages?

Thanks for the project

Control each option (print,download...) on its own rather than disable all options once or show them

It would be nice to have optional props to control each option on its own

For use cases where for example you want to disable the download or print option for specific users of your application and still enable other options

and I would be glad to work on this enhancement feature if it's something you see that would be a great plus for this package

there are also some CSS control changes on the viewer that I would like to work on because I used this package in a project of mine lately, and it's a great package btw, and I needed to disable all options by controlling CSS and the classes globally in the application and I saw that the classes were very generic, so I might run over some CSS conflicts in the future.

Not importing into repl

I was told in discord that a well-formed component should import into the repl (unless it relies on a preprocessor.)

repl

Nice Package!

Any way to add thumbnails and continuous page scroll?

Also "save as" button.

It would be nice to have optional props to hide/unhide buttons.

Thanks for the good work.

Typescript compiler expects data prop

When importing svelte-pdf as per the docs, typescript flags my <PdfViewer {url} /> and expects me to add the data prop. Please fix as the docs state that this is not required.

I'm using svelte-pdf v1.0.20

Can it dynamically reload a PDF?

I have a question that I cannot answer by reading the current docs (and even the codebase):

Will I be able to dynamically set the PDF url and trigger a reload to reload it?

In my use case the PDF URL contains some path parameters, that the backend generates a special pdf based on them.

So, from the frontend I would like to push some switches/levers and then trigger a pdf reload to see the newly generated pdf!

Is something like that possible...?

Thanks!

callback for page change

To me, an extremely useful feature would be, if I could find out on which the pdf currently is.

I see two options for that:

  1. the component forwards an event when the page changes, that indicates which page currently is selected.
  2. the component could accept a callback function as a parameter, that gets executed when the page changes.

But maybe there are better ways... I'm not really good with Svelte yet.

Would that be a feature you might consider implementing?
Or would a PR implementing this be considered?

Compile Error in Sveltekit

When I try to add to SvelteKit v1.0.0-next.230, I get the below error:

svelte-pdf doesn't appear to be written in CJS, but also doesn't appear to be a valid ES module (i.e. it doesn't have "type": "module" or an .mjs extension for the entry point). Please contact the package author to fix.

Here is the implementation:

<script>
  import { onMount } from "svelte";
  let PdfViewer;

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

<svelte:component this={PdfViewer} url="YOUR-PDF-URL"/>

Please advise if there is something I can change to make it work it SvelteKit?

PdfViewer not a valid SSR component

Error: <PdfViewer> is not a valid SSR component. You may need to review your build config to ensure that dependencies are compiled, rather than imported as pre-compiled modules. Otherwise you may need to fix a <PdfViewer>.
    at Module.validate_component (C:\Users\peter\web-projects\test-pdf\node_modules\.pnpm\[email protected]\node_modules\svelte\src\runtime\internal\ssr.js:126:9)
    at C:\Users\peter\web-projects\test-pdf\src\routes\+page.svelte:25:42
    at Object.$$render (C:\Users\peter\web-projects\test-pdf\node_modules\.pnpm\[email protected]\node_modules\svelte\src\runtime\internal\ssr.js:156:16)
    at Object.default (C:\Users\peter\web-projects\test-pdf\.svelte-kit\generated\root.svelte:45:41)
    at C:\Users\peter\web-projects\test-pdf\node_modules\.pnpm\@[email protected]_@[email protected][email protected][email protected]\node_modules\@sveltejs\kit\src\runtime\components\layout.svelte:5:41
    at Object.$$render (C:\Users\peter\web-projects\test-pdf\node_modules\.pnpm\[email protected]\node_modules\svelte\src\runtime\internal\ssr.js:156:16)
    at C:\Users\peter\web-projects\test-pdf\.svelte-kit\generated\root.svelte:44:40
    at $$render (C:\Users\peter\web-projects\test-pdf\node_modules\.pnpm\[email protected]\node_modules\svelte\src\runtime\internal\ssr.js:156:16)
    at Object.render (C:\Users\peter\web-projects\test-pdf\node_modules\.pnpm\[email protected]\node_modules\svelte\src\runtime\internal\ssr.js:164:17)
    at Module.render_response (C:\Users\peter\web-projects\test-pdf\node_modules\.pnpm\@[email protected]_@[email protected][email protected][email protected]\node_modules\@sveltejs\kit\src\runtime\server\page\render.js:171:29)

How to use it in sveltekit project?

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.