SVG line stroke-dasharray not print properly to PDF
Asked Answered
M

1

16

Print line with stroke-dasharray to PDF create different behavior, please look at the image here.

Picture A, a screenshot I took directly from the browser (Chrome). Picture B is the printed PDF from the same page.

Notice the difference in Picture B, there's a thin line between the dash, this happens in Chrome or PhantomJS (probably WebKit related?) and not happen in Firefox.

What I trying to do is export this kind of chart to PDF, but as you can see strokoe-dasharray not printed properly.

That picture above I took from this MDN page, Is there anything I can do to fix this?

Marcelinomarcell answered 26/5, 2015 at 6:22 Comment(2)
On my system (OS X/Chrome), I'm seeing the extra strokes in the print preview, but not in the exported PDF. What workarounds have you tried so far? The SVG sample you're working with contains invalid markup, so fixing that might help. Try using Inkscape instead?Cassation
Ah, stupid me. I forgot to add attribute fill="none", thanks for point it out. Now it's fixed.Marcelinomarcell
C
20

It seems that this is caused by some default value for the fill attribute. You can fix it by setting fill="none", like this:

<line x1="0" x2="100" y1="0" y2="0"
  stroke="black" stroke-dasharray="1, 2"
  fill="none"
/>
Cable answered 28/11, 2017 at 0:30 Comment(5)
This looks like Chrome bug #123072, but that was closed in 2012 so I'm not sure why I'm seeing this problem now.Cable
This still exists in chrome v65. fill='none' fixed the issue.Donoho
Bug still exists in chrome v71. fill='none' fixed itDumpcart
Thanks a lot for posting this, adding fill='none' did the trick for me as well.Indelicacy
what would be the fix here if you need both stroke and fill ?Linders

© 2022 - 2024 — McMap. All rights reserved.