Closed edemaine closed 11 months ago
With "works in the playground", are you saying that the PDF is displayed properly in the browser, or that downloading the PDF and then opening it in illustrator also differs from your local test results?
What happens if you open the PDF in other PDF renderers (Acrobat, Firefox, etc.)? It seems the implementations do not fully agree on these details.
I did not see any discrepancy between Chrome, Illustrator, or Acrobat in this test case. The playground PDF works everywhere, while the buggy PDF works nowhere.
I was showing the Illustrator view because it makes it clear how things are getting clipped.
The playground PDF works everywhere, while the buggy PDF works nowhere.
Sorry, I cannot reproduce, for me the PDF viewer in the playground shows the pdf, properly, this is in the current version of Edge. Also opening the PDF from the playground in Edge, again, properly shows the PDF. So the PDF viewers seem to disagree, but I take it at least the Adobe tools show the cropping behavior? What version of Chrome are you seeing the clipping behavior in?
The example works fine in the playground; I agree. What doesn't work is if you use the reproduction above with the .html file.
Interesting. The playground (for some reason, that's not ideal, actually) uses version 2.0.0 of JsPDF which is a lot older than the version you are using. Maybe this is a regression? The svg2pdf version is a slightly newer, unreleased version, but should only differ in third party dependencies during build time.
Could you try your sampel with 2.0.0 and then maybe bisecting the versions to find the version that changes the behavior?
I dug into this and it turns out:
unit: 'pt'
to the jsPDF constructor.1
. If the option is omitted, the default unit is 'mm', resulting in a scaling factor of 72 / 25.4
. As a consequence, the bounding box of the PDF form object (created by the <use>
-tag) is wrong. This is definitively a bug in jsPDF:called by
called by
The width and height of the passed bounding box are scaled by the inverse scaling factor and x and y are not.
However, the correct behavior should be that x, y, width, height should all be scaled by the normal (not inverse) scaling factor, so the values passed to beginFormObject
are interpreted with the correct unit.
To summarize:
unit: 'pt'
to the jsPDF constructor as workaround. This should not make a big difference, if you're not using the jsPDF API for other things as svg2pdf.Similar issue as #95.
Awesome, thanks @HackbrettXXX! Adding unit: 'pt'
fixed this issue and #245.
Closing in favor of https://github.com/parallax/jsPDF/issues/3627
Describe the bug Rendering this SVG with a nested
<svg>
tag ends up with a weird clipping box.To Reproduce Put the following into a
.html
file, then open in a web browser. (Warning: It will immediately trigger a download of filetest.pdf
)Expected behavior
The example works in the playground. It looks like this:
Is there something not yet released to NPM?
Screenshots Instead the path is mostly clipped. Here are some Illustrator screenshots:
I'm not really sure where that rectangular bounding box is coming from. Perhaps a
transform
issue?Desktop (please complete the following information):