Closed agrahn closed 1 year ago
Unfortunately, this seems to be a bit more complicated. As far as I can tell, Ghostscript and probably also mutool transform the page coordinates so that the lower left corner of the MediaBox is always located at (0,0). As a result, clipping to the original MediaBox coordinates given in the PDF can lead to undesired results.
I'll have a look if I can apply additional translations to adapt the behavior of psfile
and pdffile
. Since I haven't much time at the moment, this might take a few weeks, though.
I am going to solve this at the TeX level. The dvisvgm.def
graphics driver uses the extractbb
command to retrieve the file's MediaBox
/CropBox
coordinates from the PDF and it is easy to perform the translations based on this. So maybe we can close this issue for now.
Ok, great. Thank you for taking care of this. One less issue I have to fix. 😃
Even better: I found out that the correct way to crop PDF pages is to add a /CropBox
entry with the new bbox rect coords to the page dictionary and to leave the /MediaBox
entry untouched. The lower left coordinates of the then visible area do not get translated to (0,0) by gs
. As a result, pdffile
behaves as expected when evaluating the provided bbox options. Nothing needs to be changed/fixed.
I updated cropped.pdf
accordingly, and typesetting the code example above now produces the desired result. Thus, #231 is indeed a non-issue. :tada:
When I embed a cropped PDF graphic file (i.e. non-zero
llx
andlly
in/MediaBox [llx lly urx ury]
), then the boxing optionsllx
,lly
,urx
andury
in thepdffile
special are differently interpreted than within thePSfile
special.With
pdffile
it seems that they are measured relative to thellx
andlly
coordinates of the embedded PDF file'sMediaBox
rectangle, while they are considered as absolute coordinates in thePSfile
special, irrespective of the%%BoundingBox: ...
setting in the EPS file to be included.It would be desirable if the
pdffile
special and its boxing options would behave in the same way as thePSfile
special, that is, as absolute coordinates. This would facilitate a consistent implementation of thegraphicx
/graphics
driver filedvisvgm.def
for graphics inclusion.For demonstration, consider the following example. The original PS and PDF files,
orig.(ps|pdf)
, with0 0 150 150
bounding boxes are cropped to25 25 125 125
, which is the size of the rectangle between the filled central rectangle and the outer rectangle.For the EPS, the correct inclusion special reads
It would be nice if that worked for the
pdffile
special in the same way. But with the current version 3.0.3 ofdvisvgm
, the embedded EPS and PDF look different in the SVG output. Typeset withlatex
anddvisvgm --zoom=-1 --bbox=papersize --font-format=woff2
:Input graphic files:
orig.pdf
orig.eps
cropped.pdf
cropped.eps