bpampuch / pdfmake

Client/server side PDF printing in pure JavaScript
http://pdfmake.org
Other
11.7k stars 2.04k forks source link

Pdfmake in QuickJS #2795

Closed sallmann closed 6 hours ago

sallmann commented 1 month ago

Hello together, first I have to thank you for a great, well documented library. After hopping through the examples, I decided that pdfmake would be a great addition to a small C++project embedding a quickjs (https://github.com/bellard/quickjs) javascript environment for scripting capabilities I'm currently working on. I hoped I can use QuickJS to execute pdfmake for creating some pdfs.

But at least using the pdfmake.js in the build folder seems not to be the right approach... Looks like it is designed for web-client use only. I've never went for Node.js or related projects, so hopefully there is any way to bundle the pdfmake relevant code for using in a QuickJS environment.

Perhaps anyone has a small hint achieving this?

import { require } from '/home/user/quickjs-require/require.js'

import * as std from "std";

import * as pdfmake from '../build/pdfmake.js';

var Roboto = require('../fonts/Roboto');
pdfmake.addFonts(Roboto);

[...]
~/pdfmake/examples $ /home/user/quickjs/qjs absolute.js    
TypeError: cannot read property 'navigator' of undefined
    at <anonymous> (../build/pdfmake.js)
    at apply (native)
    at <anonymous> (../build/pdfmake.js:60339)
    at 6549 (../build/pdfmake.js:60340)
    at call (native)
    at __webpack_require__ (../build/pdfmake.js:73301)
    at 428 (../build/pdfmake.js:6099)
    at call (native)
    at __webpack_require__ (../build/pdfmake.js:73301)
    at 2736 (../build/pdfmake.js:6365)
    at call (native)
    at __webpack_require__ (../build/pdfmake.js:73301)
    at 9921 (../build/pdfmake.js:27865)
    at call (native)
    at __webpack_require__ (../build/pdfmake.js:73301)
    at <anonymous> (../build/pdfmake.js:73366)
    at <anonymous> (../build/pdfmake.js:73369)
    at webpackUniversalModuleDefinition (../build/pdfmake.js:8)
    at <anonymous> (../build/pdfmake.js:73371)
liborm85 commented 3 days ago

According to post author of quickjs library https://github.com/bellard/quickjs/issues/205#issuecomment-1854636382, navigator will not be supported.

You can try use server-side pdfmake, see documentation.