-
-
Notifications
You must be signed in to change notification settings - Fork 615
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
Missing support for embedding SVG #114
Comments
Hello @lepidotteri! This feature could definitely be added to I can't commit to delivering this feature by any specific date. There are several other important things I'm planning to work on first. But this feature is certainly on my radar. And, of course, I'm always open to somebody submitting a PR for this! |
@lepidotteri - FYI, there is now SVG path support in version So if you had an SVG like: <svg width="4cm" height="4cm" viewBox="0 0 400 400"
xmlns="http://www.w3.org/2000/svg" version="1.1">
<title>Example triangle01- simple example of a 'path'</title>
<desc>A path that draws a triangle</desc>
<rect x="1" y="1" width="398" height="398"
fill="none" stroke="blue" />
<path d="M 100 100 L 300 100 L 200 300 z"
fill="red" stroke="blue" stroke-width="3" />
</svg> You could render that in pdf-lib with this code: const pdfDoc = await PDFDocument.create();
const page = pdfDoc.addPage(PageSizes.Letter);
// 1" from upper left
const positionX = 72;
const positionY = 720;
const svgWidth = 398;
const svgHeight = 398;
const blue = rgb(0, 0, 1);
const red = rgb(1, 0, 0);
page.drawRectangle({
x: positionX,
y: positionY - svgHeight,
width: svgWidth,
height: svgHeight,
borderColor: blue,
});
page.drawSvgPath('M 100 100 L 300 100 L 200 300 z', {
x: positionX,
y: positionY,
color: red,
borderColor: blue,
borderWidth: 3
}); |
win |
It could be a very handy feature imo, right now, in a browser environment for example, you would need to parse the SVG in order to be drawn into a canvas only for the newly drawn image base64 to be taken.
Would it be possible to add this kind of feature by re-using the existing vector graphics drawing functions of pdf-lib?
The text was updated successfully, but these errors were encountered: