Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
Using convertPdfToPng in Svelte i get Cannot access 'callback' before initialization

Trying to pass in a pdf to a svelte script, to convert the pages to pdf.

<script>
import { onMount } from 'svelte';
import { convertPdfToPng } from 'convert-pdf-png';

let files;


const convertAndDoSomething=(files)=>
{
    const pdf = files[0];
    console.log("been called");

    convertPdfToPng(pdf, {
        outputType: 'callback',
        callback: callback
    });

    const callback = images => {
        // the function returns an array
        // every img is a normal file object
        images.forEach(img => {
            console.log(img.filename);
        });
    }
};


</script>


<input type="file" bind:files>

{#if files && files[0]}
    <p use:convertAndDoSomething>
        {files[0].name}
    </p>
{/if}

this gives an error: Uncaught (in promise) ReferenceError: Cannot access 'callback' before initialization at convertAndDoSomething (Example6.svelte:17:19) at Object.mount [as m] (Example6.svelte:38:6) at Object.update [as p] (Example6.svelte:35:22) at update (index.mjs:1075:36) at flush (index.mjs:1042:13)

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!