-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Error when trying to create a dotted line #1060
Comments
@floyd-may , can you take a look at it? |
Downgrading to |
@PascalPixel do mind creating a PR with an unit test (basically the code from OP)? |
@blikblum sorry I didn't see this earlier! I switched jobs and my subscription to this repo was pointed at my work email address =( I agree that this appears to be over-zealous validation. I was able to use this code to produce a dotted line that renders correctly in MS Edge: doc
.moveTo(0, 10)
.lineTo(100, 10)
.lineCap('round')
.addContent('[0 2] 0 d')
.stroke(); I don't know that I have the bandwidth to make a PR for at least a week, but if this is still unaddressed by that time, please ping me here and I'll try to carve out a couple hours. |
Google Chrome renders without issues as well 🎉 Referring to your PR @floyd-may #969, do you remember which renderers specifically had an issue? |
@PascalPixel it was MS Edge and Adobe Reader that had issues. |
Ok Adobe Reader is pretty important 😅 |
In PDFKit >=0.10.0, calling dash() with any 0s in the dash array/length will throw an error. For more info see foliojs/pdfkit#1060 foliojs/pdfkit#949 foliojs/pdfkit#969 A number of SVG editors, I believe including inkscape, will happily generate `stroke-dasharray` attributes with 0s in them, and then running them through SVG-to-PDFKit will cause the conversion to fail completely. So, this commit does a bunch of math to rewrite dash arrays containing 0s to eliminate the zeros, but still achieve the same result. This commit also updates the version of PDFKit the examples use to the latest (0.13.0) and adds a test that exercises a bunch of `stroke-dasharray` scenarios with 0s in them.
In PDFKit >=0.10.0, calling dash() with any 0s in the dash array/length will throw an error. For more info see foliojs/pdfkit#1060 foliojs/pdfkit#949 foliojs/pdfkit#969 A number of SVG editors, I believe including inkscape, will happily generate `stroke-dasharray` attributes with 0s in them, and then running them through SVG-to-PDFKit will cause the conversion to fail completely. So, this commit does a bunch of math to rewrite dash arrays containing 0s to eliminate the zeros, but still achieve the same result. This commit also updates the version of PDFKit the examples use to the latest (0.13.0) and adds a test that exercises a bunch of `stroke-dasharray` scenarios with 0s in them.
In PDFKit >=0.10.0, calling dash() with any 0s in the dash array/length will throw an error. For more info see foliojs/pdfkit#1060 foliojs/pdfkit#949 foliojs/pdfkit#969 A number of SVG editors, I believe including inkscape, will happily generate `stroke-dasharray` attributes with 0s in them, and then running them through SVG-to-PDFKit will cause the conversion to fail completely. So, this commit does a bunch of math to rewrite dash arrays containing 0s to eliminate the zeros, but still achieve the same result. This commit also updates the version of PDFKit the examples use to the latest (0.13.0) and adds a test that exercises a bunch of `stroke-dasharray` scenarios with 0s in them.
In PDFKit >=0.10.0, calling dash() with any 0s in the dash array/length will throw an error. For more info see foliojs/pdfkit#1060 foliojs/pdfkit#949 foliojs/pdfkit#969 A number of SVG editors, I believe including inkscape, will happily generate `stroke-dasharray` attributes with 0s in them, and then running them through SVG-to-PDFKit will cause the conversion to fail completely. So, this commit does a bunch of math to rewrite dash arrays containing 0s to eliminate the zeros, but still achieve the same result. This commit also updates the version of PDFKit the examples use to the latest (0.13.0) and adds a test that exercises a bunch of `stroke-dasharray` scenarios with 0s in them.
In PDFKit >=0.10.0, calling dash() with any 0s in the dash array/length will throw an error. For more info see foliojs/pdfkit#1060 foliojs/pdfkit#949 foliojs/pdfkit#969 A number of SVG editors, I believe including inkscape, will happily generate `stroke-dasharray` attributes with 0s in them, and then running them through SVG-to-PDFKit will cause the conversion to fail completely. So, this commit does a bunch of math to rewrite dash arrays containing 0s to eliminate the zeros, but still achieve the same result. This commit also updates the version of PDFKit the examples use to the latest (0.13.0) and adds a test that exercises a bunch of `stroke-dasharray` scenarios with 0s in them.
Bug Report
Description of the problem
I get an
Error: dash([0,2], {}) invalid, lengths must be numeric and greater than zero
Error when tying to create a dotted line unsing.lineCap('round').dash(0, { space: 2 })
.From some research I found this was introduced because of #949 in #969. This bit of the PDF spec was mentioned there:
The way I interpret that is that the length and the space can't both be zero.
So
[0 2] 0 d
would be valid whereas[0] 0 d
or[0 0] 0 d
would be invalid.As far as I understand it, this is the only way to create a dotted line.
Workaround
Do it manually:
Code sample
Your environment
The text was updated successfully, but these errors were encountered: