pdfjs
pdfjs copied to clipboard
Graphical state is not correctly reset when using templates
The test added here https://github.com/rkusa/pdfjs/commit/1c087a180f2133b49475feb75bcc42b76c6eff6c (#150) shows that the added template seem to effect the graphical state of the page content that comes on t of it:
(the text should be bigger and not mirrored)
Reseting the state via Q
or cm
operators didn't seem to work, so another solutions has to be found.
Is there already a solution in progress for this? Because I face the same problem in my project with this library.
I also ran into the upside-down issue today, did someone figure out a workaround for this?
Okay, so I played around a little with a minimal PDF created by Inkscape. It contains a single object on the page it exports, which decodes to this:
1 0 0 -1 0 841.889771 cm % Set matrix
q % Save graphics state
Q % Restore graphics state
So the issue here is that Inkscape (or rather, cairo) does not place the transformation matrix inside the graphics state, which leads to it bleeding into the objects created by pdfjs.
I'm not sure what the ideal solution to this issue might be. One option would be to explicitly set the transformation matrix in the root objects created by pdfjs. Another option would be to insert a q
operation before the template, so that a Q
operation would succeed after the template.
Just FYI: As a workaround you can use another tool to create a PDF which doesn't use a global transformation matrix.
@DASPRiD thanks for digging into this! Should be fixed on main
now. Solution was as suggested a q
before and a Q
after the template.