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)