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

✨ Support including images by URL #94

Merged
merged 1 commit into from
Dec 15, 2024
Merged

✨ Support including images by URL #94

merged 1 commit into from
Dec 15, 2024

Conversation

ralfstx
Copy link
Member

@ralfstx ralfstx commented Dec 15, 2024

Images used to be registered in the document definition. In v0.5.4, support for loading images directly from the file system was added. However, this feature gives the library access to all files on the system, which may be a security concern.

This commit adds support for including images by a URL. The image property of an image block now supports data:, file:, and http(s): URLs. File names are interpreted as relative to a resource root that must be set by the setResourceRoot() method on the PdfMaker class. Compatibility with the previous API is maintained, but the images property in a document definition is deprecated.

An fs module is introduced to read files from the file system. Since this module is not available in browser environments, it is loaded using dynamic imports to prevent runtime errors. This required to raise the minimal ES version to 2020.

@ralfstx ralfstx force-pushed the image-url branch 3 times, most recently from 0186543 to 4495b17 Compare December 15, 2024 17:27
Images used to be registered in the document definition. In v0.5.4,
support for loading images directly from the file system was added.
However, this feature gives the library access to all files on the
system, which may be a security concern.

This commit adds support for including images by a URL. The `image`
property of an image block now supports `data:`, `file:`, and `http(s):`
URLs. File names are interpreted as relative to a resource root that
must be set by the `setResourceRoot()` method on the `PdfMaker` class.
Compatibility with the previous API is maintained, but the `images`
property in a document definition is deprecated.

A new `fs` module is introduced to read files from the file system.
Since the `node:` modules are not available in browser environments,
they are loaded using dynamic imports. This required to raise the
minimal runtime version to ES2022. The build has been updated to target
the browser platform and ES2022. This ensures that the library can be
used in the browser, but still can access the file system in Node.
@ralfstx ralfstx merged commit cac00d2 into main Dec 15, 2024
1 check passed
@ralfstx ralfstx deleted the image-url branch December 15, 2024 17:53
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.

1 participant