Skip to content

Conversation

FilipTalaga
Copy link

Using rollup as a project bundler introduces two problems with pdfmake:

  1. rollup won't allow for reassigning imported module (see issue), so there is no way to assign vfs fonts manually.
  2. rollup won't parse vfs_fonts.js, since it uses this at top level, with is by default set by rollup to undefined (see docs)

To resolve both issues, this for pdfmake needs to be set to window, with options.moduleContext in rollup config, and then fonts assignments needs to happen before importing pdfmake to rollup scope (fortunately, since this in vfs_fonts is now window, it will do the assignment automatically).

Using rollup as a project bundler introduces two problems with pdfmake:
1. rollup won't allow for reassigning imported module (see rollup/rollup#436), so there is no way to assign vfs fonts manually.
2. rollup won't parse vfs_fonts.js, since it uses `this` at top level, with is by default set by rollup to `undefined` (see https://rollupjs.org/guide/en/#error-this-is-undefined)

To resolve both issues, `this` for pdfmake needs to be set to `window`, with `options.moduleContext` in rollup config, and then fonts assignments needs to happen before importing pdfmake to rollup scope (fortunately, since `this` in vfs_fonts is now `window`, it will do the assignment automatically).
@liborm85 liborm85 merged commit 4fc8f5b into pdfmake:0.1 Jul 3, 2021
@liborm85
Copy link
Member

liborm85 commented Jul 3, 2021

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants