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

Path element cannot be exported to PDF #269

Closed
cuixiping opened this issue Aug 2, 2018 · 11 comments
Closed

Path element cannot be exported to PDF #269

cuixiping opened this issue Aug 2, 2018 · 11 comments
Labels

Comments

@cuixiping
Copy link
Member

cuixiping commented Aug 2, 2018

Currently, only line, rect, ellipse, circle, text elements can be exported to pdf.
see jspdf.plugin.svgToPdf.js.

Any <path> element in the svg document cannot be exported to pdf.

The following svg document will be exported as an empty pdf.
2 path elements are ignored.

<svg width="640" height="480" xmlns="http://www.w3.org/2000/svg">
  <path d="m100,229c191,97 173,-94 379,45" fill="#FF0000" stroke="#000000" stroke-width="5"/>
  <path d="m223,101a114,62 0 1 0 219,2" fill="#FF0000" stroke="#000000" stroke-width="5"/>
</svg>

image

@brettz9
Copy link
Contributor

brettz9 commented Aug 2, 2018

As per #51 , we really should see about updating jsPDF (possibly requiring an update to the fork I was using for the SVG plugin or resuming use of upstream)... PRs welcome!

@brettz9
Copy link
Contributor

brettz9 commented Aug 2, 2018

Btw, which browser were you testing in? In my case, when I test in Firefox (as Chrome is not working for me), I see nothing at all in the PDF... FWIW, exporting to PNG works fine...

@brettz9 brettz9 added the bug label Aug 2, 2018
@cuixiping
Copy link
Member Author

cuixiping commented Aug 3, 2018

jsPDF supports bezier curves. But jspdf.plugin.svgToPdf.js (from CBiX/svgToPdf.js) does not support path element.

Maybe svgedit should use alafr/SVG-to-PDFKit which has much more features:

  • shapes: rect, circle, path, ellipse, line, polyline, polygon
  • special elements: use, nested svg
  • text elements: text, tspan, textPath
  • text attributes: x, y, dx, dy, rotate, text-anchor, textLength, word-spacing, letter-spacing, font-size
  • styling: with attributes only
  • colors: fill, stroke & color (rgb, rgba, hex, string), fill-opacity, stroke-opacity & opacity
  • units: all standard units
  • transformations: transform, viewBox & preserveAspectRatio attributes
  • clip paths & masks
  • images
  • fonts
  • gradients
  • patterns
  • links

@cuixiping
Copy link
Member Author

I fixed it partially. But have not send PR.

It can export normal curves to PDF.
It supports MmLlQqCcZz commands but not HhVvAaTtSs yet.
It doen't support holes in path. All holes will be treated as normal shape.
I have no ideas to handle with holes.

cuixiping added a commit to cuixiping/svgedit that referenced this issue Jan 14, 2020
@cuixiping
Copy link
Member Author

Update: Path with holes has been ok.
Here is a pdf screenshot:

image

@cuixiping
Copy link
Member Author

cuixiping commented Jan 16, 2020

I am solving the HhVv commands and find another bug: convertPath function in path.js handle HhVv commands incorrectly.

@cuixiping
Copy link
Member Author

cuixiping commented Jan 16, 2020

I tried to write a cypress case for convertPath . It is a waste of life for me. 😂 😭
It's very difficult to make it work correctly for me.

@brettz9
Copy link
Contributor

brettz9 commented Jan 16, 2020

Awww.. Hopefully learned at least what not to do. :-) You tried a PDF parser or what?

cuixiping added a commit to cuixiping/svgedit that referenced this issue Jan 16, 2020
cuixiping added a commit to cuixiping/svgedit that referenced this issue Jan 16, 2020
@cuixiping
Copy link
Member Author

cuixiping commented Jan 16, 2020

Awww.. Hopefully learned at least what not to do. :-) You tried a PDF parser or what?

Not PDF. I just tried to test the convertPath function. The feature of exporting pdf needs this function.

@cuixiping
Copy link
Member Author

cuixiping commented Jan 16, 2020

My fix now supports all path commands except arc commands(A,a) to be exported to pdf.

@klesun-misc
Copy link

@cuixiping you rock!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants