pyx-project / pyx

Repository of PyX, a Python package for the creation of PostScript, PDF, and SVG files.
https://pyx-project.org/
GNU General Public License v2.0
109 stars 18 forks source link

Unwanted black bounding box when writePDFfile is used (writeSVGfile works as expected) #30

Closed canberkgurel closed 3 years ago

canberkgurel commented 3 years ago

I'm seeing an unexpected black bounding box around the canvas when the use c.writePDFfile(parsed.output).

However, it doesn't exist when I use c.writeSVGfile(parsed.output).

See: apriltag_id0.zip

What might be the reason? How can I fix it?

gertingold commented 3 years ago

I took a look at your two files and could not spot any difference. Should the difference be obvious or is it difficult to spot?

May be you can produce a minimal example showing the effect and share the code so that we can have a closer look.

canberkgurel commented 3 years ago

@gertingold When I open the two files, the SVG file doesn't have a black rectangle on the edge, whereas the PDF file does. Can you confirm?

wobsta commented 3 years ago

I can indeed see it. And this rectangle can be found in the SVG file and the PDF file. Here is the SVG snippet:

<g stroke-width="0.000028"><path d="M0 -0L297.638 -0L297.638 -297.638L0 -297.638Z" stroke="#000"/></g>

In PDF you can decompress the streams (for example by mutool clean -d apriltag_id0.pdf apriltag_id0_decompressed.pdf) and the page stream starts with:

7 0 obj
<<
  /Length 5342
>>
stream
0.566929 w
q
q
0.000028 w
0.000000 0.000000 0.000000 1.000000 K
0.000000 0.000000 0.000000 1.000000 k
0.000000 0.000000 m
297.637795 0.000000 l
297.637795 297.637795 l
0.000000 297.637795 l
h
S
Q
...

If you do not want the rectangle, just do not add it to the canvas. Using a thin line, a hair line, will result in the thinnest line available on the output device for PDF (and PostScript) whereas for SVG it might not be rendered (or just not be visible) at all. (You could also change the color or make it transparent, but it will remain hackish.) Maybe you want to set the bounding box to define the area to use.