Closed RythenGlyth closed 2 months ago
Interesting, I get a different error output on your first example as follows:
5735101: ($0) => { throw new Error(UTF8ToString($0)); },
^
Error: unknown output document format:
at 5735101 (file:///artifex/SDK/mupdfjs/npm-0.2.0/node_modules/mupdf/dist/mupdf-wasm.js:995:27)
at runEmAsmFunction (file:///artifex/SDK/mupdfjs/npm-0.2.0/node_modules/mupdf/dist/mupdf-wasm.js:4256:30)
at _emscripten_asm_const_int (file:///artifex/SDK/mupdfjs/npm-0.2.0/node_modules/mupdf/dist/mupdf-wasm.js:4259:14)
at wasm://wasm/0239b566:wasm-function[111]:0x802a
at invoke_vi (file:///artifex/SDK/mupdfjs/npm-0.2.0/node_modules/mupdf/dist/mupdf-wasm.js:5685:29)
at wasm://wasm/0239b566:wasm-function[325]:0x2d502
at Object._wasm_new_document_writer_with_buffer (file:///artifex/SDK/mupdfjs/npm-0.2.0/node_modules/mupdf/dist/mupdf-wasm.js:705:12)
at new DocumentWriter (file:///artifex/SDK/mupdfjs/npm-0.2.0/node_modules/mupdf/dist/mupdf.js:1136:24)
at file:///artifex/SDK/mupdfjs/npm-0.2.0/node.mjs:4:13
Node.js v20.8.0
it seems like you can get the error with just 2 lines:
import * as mupdf from 'mupdf'
const outBuffer = new mupdf.Buffer()
const out = new mupdf.DocumentWriter(outBuffer, "PDF", "")
So I think this error is related to the mupdf.DocumentWriter
constructor.
Interesting, I get a different error output on your first example as follows:
5735101: ($0) => { throw new Error(UTF8ToString($0)); }, ^ Error: unknown output document format: at 5735101 (file:///artifex/SDK/mupdfjs/npm-0.2.0/node_modules/mupdf/dist/mupdf-wasm.js:995:27) at runEmAsmFunction (file:///artifex/SDK/mupdfjs/npm-0.2.0/node_modules/mupdf/dist/mupdf-wasm.js:4256:30) at _emscripten_asm_const_int (file:///artifex/SDK/mupdfjs/npm-0.2.0/node_modules/mupdf/dist/mupdf-wasm.js:4259:14) at wasm://wasm/0239b566:wasm-function[111]:0x802a at invoke_vi (file:///artifex/SDK/mupdfjs/npm-0.2.0/node_modules/mupdf/dist/mupdf-wasm.js:5685:29) at wasm://wasm/0239b566:wasm-function[325]:0x2d502 at Object._wasm_new_document_writer_with_buffer (file:///artifex/SDK/mupdfjs/npm-0.2.0/node_modules/mupdf/dist/mupdf-wasm.js:705:12) at new DocumentWriter (file:///artifex/SDK/mupdfjs/npm-0.2.0/node_modules/mupdf/dist/mupdf.js:1136:24) at file:///artifex/SDK/mupdfjs/npm-0.2.0/node.mjs:4:13 Node.js v20.8.0
That's really strange. I used the 0.2.0 npm version as you did if I interpret your error stack correctly. (I also compiled my own version of this package and it threw the same errors)
What does differ is the node version and maybe the OS? I ran mine on Windows
it seems like you can get the error with just 2 lines:
import * as mupdf from 'mupdf' const outBuffer = new mupdf.Buffer() const out = new mupdf.DocumentWriter(outBuffer, "PDF", "")
So I think this error is related to the
mupdf.DocumentWriter
constructor.
For me, the constructor is fine and doesn't throw any error.
Okay - I aligned as much as possible with you and updated my node to v21.6.2 - I still get the same error. I am on a MacOS so this probably explains the difference in our output logs. I am also just using the mupdf.js from NPM directly. I think we will have to wait until next week to figure this out as the main developer @ccxvii will be available then.
Okay, thank you
One problem is a typo in the DocumentWriter constructor (the option string is clobbering the format string when passing to WASM), but even if I fix that there's another problem with RuntimeError: null function or function signature mismatch
that I'm trying to track down the cause for.
Second problem is likely in the core library which doesn't like creating a PDF document writer and then closing it before writing any pages.
@RythenGlyth This should be fixed with the latest release of mupdf.js (0.2.1) on NPM - https://www.npmjs.com/package/mupdf , please confirm!
Yes it does perfectly work. Thank you!
The
DocumentWriter.close
function seems malfunction and throws WASM RuntimeError.This is the code reduced to the minimum:
It throws the following error
instead if I try to add a page:
another error is thrown:
No matter what,
outBuffer.getLength()
is always 0 after theout.close()
When recreating everything from mupdf's
muconvert.c
in JS, the second error is thrown as well.