Code Monkey home page Code Monkey logo

Comments (6)

gtm-nayan avatar gtm-nayan commented on May 28, 2024

@squeezeboxhuf can you check which version of svelte-pdfjs you're using? I was experimenting with some stuff on the alpha versions so if you have those it'll not work. The latest stable version 0.3.4 should work.

from svelte-pdfjs.

squeezeboxhuf avatar squeezeboxhuf commented on May 28, 2024

I have made some progress! I discovered that I had to have a sveltekit project with TypeScript, then I modded my svelte.config.js and tsconfig.json to match your additional aliases, then copied the component parts from this repository src/lib into my src/lib folder and Hey Presto, I see a PDF document!

from svelte-pdfjs.

gtm-nayan avatar gtm-nayan commented on May 28, 2024

I'm glad you found a way to make it work somehow but that's not how the package is meant to be used.

If it's not too much of a bother to you, can you install version 0.3.4 with npm i [email protected] pdfjs-dist and see if the issue persists? Thanks. 🙂

from svelte-pdfjs.

squeezeboxhuf avatar squeezeboxhuf commented on May 28, 2024

Yes that did the trick! So I reverted my tsconfig and svelte.config, removed the src/lib additions and I am still getting PDFs displayed! Thank you.

One extra question! I have some multi-page documents, so I am using a {#each} loop for maxPages numbers to repeat the <Page> component within the <Document> ... like this...

{#if browser}
<Document
{file}
on:loadsuccess={(e) => console.log((maxPages = e.detail.numPages))}
on:loaderror={console.log}
>
{#each Array.from({ length: maxPages }, (_, i) => i + 1) as num}
<p class="separator">page {num} || <span on:click={handleRotate}>rotate</span></p>
<div>
<Page
{scale}
{num}
{renderTextLayer}
{rotation}
getViewport={preferThisWidth(targetWidth)}
/>
</div>
{/each}
</Document>
{/if}

But this results in an error after the first page (first page displays OK) : "PageCanvas.svelte? [sm]:9 Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'width') at render_page (PageCanvas.svelte? [sm]:9:17)". So I put the each loop around the <Document> component and it's OK. Effectively I'm creating a <Document> with a <Page> within it, for each page. Is that what you'd expect to be needed? My first presumption was to iterate just the <Page> elements.

I've discovered it might be my page separator paragraph interfering... It's OK to iterate just the <Page> as long as I don't put any other objects in the loop... I've tried putting separator para before and after but it still seems to upset the subsequent pages.

For now, I've left it iterating each containing <Document> and <Page>.

Thanks

from svelte-pdfjs.

gtm-nayan avatar gtm-nayan commented on May 28, 2024

I just published 0.3.7 to npm which should fix it.

@squeezeboxhuf Upgrade and let me know if it works or not.

from svelte-pdfjs.

squeezeboxhuf avatar squeezeboxhuf commented on May 28, 2024

Yes - that's great. Thank you.

from svelte-pdfjs.

Related Issues (12)

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.