Giter Site home page Giter Site logo

vinodnimbalkar / svelte-pdf Goto Github PK

View Code? Open in Web Editor NEW
193.0 5.0 44.0 2.2 MB

svelte-pdf provides a component for rendering PDF documents using PDF.js

Home Page: https://www.npmjs.com/package/svelte-pdf

License: MIT License

CSS 19.79% HTML 2.06% JavaScript 9.75% Svelte 68.41%
pdf pdf-viewer pdf-viewer-component svelte javascript pdfjs-dist pdfjs

svelte-pdf's Introduction

Hi My name is Vinod Nimbalkar

  • 🔭 I’m currently working on Nodejs, Python, Svelte
  • 📫 How to reach me: omvinod at yahoo dot com
  • 😄 Pronouns: He/Him

📶 Stats:

My github stats Top Langs

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  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

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)

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

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!

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'

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

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

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!

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

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

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} />`

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>

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

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?

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";

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.

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.

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?

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";

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

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

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.