Pdfmake: svg support

Created on 27 Oct 2014  Â·  43Comments  Â·  Source: bpampuch/pdfmake

Is there a plan to add support for svg elements?
It would be nice to be able to generate pdfs also from svg

canvas feature request

Most helpful comment

any update ? ...it would be important to import images in format svg

All 43 comments

This will be quite easy in pdfmake 0.2.0, which will provide access to low-level methods

cool :+1:

for now you can convert svg to png quite easy client side / server side and use that in your pdf.

Well with png, you lose the advantages svg has (scaling, etc...)

well, with svg pdfmake needs to implement an svg parser - which is non trivial as you can imagine. So don't hope for it any time soon.

Yes I know... But generating PDFs from svg opens so many applications! It would be the beginning of doc converters in pure JavaScript (docx to svg to pdf)

Happy to accept pull requests ;-)
Am 05.05.2015 18:35 schrieb "natcohen" [email protected]:

Yes I know... But generating PDFs from svg opens so many applications! It
would be the beginning of doc converters in pure JavaScript (docx to svg to
pdf)

—
Reply to this email directly or view it on GitHub
https://github.com/bpampuch/pdfmake/issues/121#issuecomment-99134088.

Is it possible to draw objects (lines, text, etc...) based on coordinates of the page? with this I could start working on svg...

Look here for object drawing: https://github.com/bpampuch/pdfmake/blob/master/examples/vectors.js

For text you can use the normal text - maybe in combination with this #222

I guess it's time to introduce extensibility, I'll add another Issue with a proposal for PluginAPI

Plugins would definitely open to new features!
@jthoenes I get it for text and vectors but how can I define the size of a page in pixels?

@bpampuch I was thinking along the same lines recently.

@natcohen page sizes in pixels don'r make sense. The easiest way would be, to define a transformation, e.g. 1px = 0.75 points

https://github.com/CBiX/svgToPdf.js/ something to look at . it is a plugin for jspdf

Any chance we can implement this on pdfmake?

+1 for this feature, we would need it too.

+1 useful to get scalable lightweight symbols in PDF

+1

+1

+1

+1

Relevant pdfkit issue https://github.com/devongovett/pdfkit/issues/270.

Will not be included in pdfkit, is in new libraray: https://github.com/devongovett/svgkit.

+1

+1

Any updates?

any update ? ...it would be important to import images in format svg

https://github.com/alafr/SVG-to-PDFKit

This seems like a working solution specifically compatible with PDFKit and the API is pretty straight forward.

https://github.com/alafr/SVG-to-PDFKit

This seems like a working solution specifically compatible with PDFKit and the API is pretty straight forward.

How would I use this client-side? All code examples seem to rely on Node.js using the printer which requires 'fs'.

@zxlin How do you integrate https://github.com/alafr/SVG-to-PDFKit into the document definition of pdfmake?

@zxlin How do you integrate https://github.com/alafr/SVG-to-PDFKit into the document definition of pdfmake?

+1

@zxlin How do you integrate https://github.com/alafr/SVG-to-PDFKit into the document definition of pdfmake?

+1

+1

@liborm85 any updates on this?

+1

+1

canvg is a decent SVG parser.

I'm not sure how to integrate SVGtoPDFKit into this particular package, but I use it directly in pdfkit without issue.

@liborm85 @bpampuch If there's a way to expose the pdfkit doc object to the user, it could be hacked for now at least until a good solution is integrated into this package.

I have created a PR that adds svg support in the document definition: https://github.com/bpampuch/pdfmake/pull/1682.

It works similar to images except you cannot use the images library or file paths.

Example usage:

content: [
    {
        svg: '<svg viewBox="0 0 500 500"><circle cx="250" cy="250" r="100" stroke="black" stroke-width="3" fill="red" /></svg>',
        width: 100
    },
    {
        svg: '<svg viewBox="0 0 500 500"><circle cx="250" cy="250" r="100" stroke="black" stroke-width="3" fill="red" /></svg>',
        fit: [500, 250]
    }
]

@cyrixmorten Any reason you did not submit a PR for it?

@manu-st thought it would require a bit more work before it could be accepted but that discussion might as well happen in a PR. Have created a PR here: https://github.com/bpampuch/pdfmake/pull/1682

Thanks so much @cyrixmorten, this helps me a ton! I was struggling to use SVGtoPDFKit with pdfmake, since it seemed like we needed to specify the pdf page number and x, y coordinates to properly place the image in between pdfmake content, which was quickly becoming a pain. Your PR seems to be exactly what I needed

@cyrixmorten Any guidance on how to get this to work would be appreciated. Added the PR but still getting

Unrecognized document structure: {"svg":....

Hi Bryan. Am not sure that there has been a new release to npm that the
includes svg nodes yet.

tir. 16. jul. 2019 02.12 skrev Bryan notifications@github.com:

Any idea on how to get this to work? Added the PR but still getting

Unrecognized document structure: {"svg":....

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/bpampuch/pdfmake/issues/121?email_source=notifications&email_token=ABSXSOC6YDYEQJFB7LCB5P3P7UHAVA5CNFSM4AWMYKN2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZ7J7EY#issuecomment-511614867,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABSXSODAJ7YS2QN7TALO5K3P7UHAVANCNFSM4AWMYKNQ
.

Hi @cyrixmorten, any idea when this will be released?

@thompsondave I do not know, is up to the owner of this project

Experimental SVG support added in version 0.1.58+ via SVG-to-PDFKit library.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kumarandena picture kumarandena  Â·  3Comments

kamilkp picture kamilkp  Â·  3Comments

dgrice picture dgrice  Â·  3Comments

sayjeyhi picture sayjeyhi  Â·  3Comments

einfallstoll picture einfallstoll  Â·  3Comments