Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

saveAsBlob not recognized #114

Open
zaynekomichi opened this issue Mar 21, 2023 · 5 comments
Open

saveAsBlob not recognized #114

zaynekomichi opened this issue Mar 21, 2023 · 5 comments
Labels
question Further information is requested

Comments

@zaynekomichi
Copy link

zaynekomichi commented Mar 21, 2023

React app using typescript,

merge.saveAsBlob() does not exist in PDFmerge
const mergeItems = async() => {
    const merger = new PDFMerger();
    for (const file of items) {
        await merger.add(file)
    }

    const mergedPdf = await merger.saveAsBlob();
    const url = URL.createObjectURL(mergedPdf);

    return setMergedPdfUrl(url);
}
@zaynekomichi
Copy link
Author

pass type any to const merge

@mojoaxel
Copy link
Collaborator

mojoaxel commented Mar 21, 2023

The function saveAsBlob is defined on the PDFMerger browser type. I don't know why this is a problem. Maybe somebody else that is using the browser version can shine some light on this?

@mojoaxel mojoaxel reopened this Mar 21, 2023
@mojoaxel mojoaxel added the question Further information is requested label Mar 21, 2023
@zaynekomichi
Copy link
Author

Using it in tauri

@xDivisionByZerox
Copy link

@zaynekomichi Did you write the error messaeg yourself instead of copy pasting it? Because it is totally off.

You get a reference error on merge. Well, sure. The source code you provided only has a merger (with "r") variable.
Next the "PDFmerge" from your error message does not match the "PDFMerger" from the provided source code.

Nevertheless, you said you use tauri. I found this SO post potentially explaining the problem.

[...] The only NPM packages you can use are for the UI side of the Tauri application, and that also means they run inside the browser sandbox, and therefore they don't have native access to system resources beyond the web API. [...]

So I guess pdf-merger-js is missing access to the native web API's like Blob or File.
As you can se in the first lines of the script the globalObject only consideres native Web Environments:

const globalObject =
typeof globalThis === 'object'
? globalThis
: typeof window === 'object'
? window // Browser
: typeof self === 'object'
? self // Worker
: this

@zaynekomichi
Copy link
Author

I pasted the message, will reproduce the error and attach an image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants