TransWikia.com

Problem with rendering cropped eps files in pdf document

TeX - LaTeX Asked on October 4, 2021

I have a bunch of EPS files which I’m cropping by changing their Bounding Box values. I put them in a .tex document and run Latex. Now, the resulting .dvi file shows the cropped figures correctly. However, if I now convert the .dvi to .pdf, the PDF file shows the uncropped figures, with all the figures covering the text as well. How can I deal with this? Also, I’m not allowed to use pdflatex, which otherwise gives the desired result.

One Answer

I can reproduce the problem in various situations. A solution seems to be to use trim and clip from graphicx instead of modifying the bounding box directly in the .eps.

To reproduce I made a simple eps file in Inkscape consisting of a five point star with a border. Some snippets from the produced file:

%!PS-Adobe-3.0 EPSF-3.0
%%Creator: cairo 1.15.10 (http://cairographics.org)
%%CreationDate: Thu Jul 30 14:45:16 2020
%%Pages: 1
%%DocumentData: Clean7Bit
%%LanguageLevel: 2
%%BoundingBox: 0 0 185 185
%%EndComments
%%BeginProlog
50 dict begin
/q { gsave } bind def
[...]
/cairo_flush_ascii85_file { cairo_ascii85_file status { cairo_ascii85_file flushfile } if } def
/cairo_image { image cairo_flush_ascii85_file } def
/cairo_imagemask { imagemask cairo_flush_ascii85_file } def
%%EndProlog
%%BeginSetup
%%EndSetup
%%Page: 1 1
%%BeginPageSetup
%%PageBoundingBox: 0 0 185 185
%%EndPageSetup
q 0 0 185 185 rectclip
1 0 0 -1 0 185 cm q
0 1 1 rg
[...]
102.664 181.711 m S Q
Q Q
showpage
%%Trailer
end
%%EOF

There are two places where the bounding box is set, once for the file and once for the page.

I tried changing each of the two bounding boxes to 30 30 150 150, and compiling in two different ways: latex-dvipdfm and latex-dvips-ps2pdf.

I also tried using the original bounding box with the trim and clip options from graphicx: includegraphics[trim={30 30 35 35},clip]{originalfile}.

Code:

documentclass{article}
usepackage{lipsum}
usepackage{graphicx}
begin{document}
lipsum[1] textbf{Only file bounding box:}
includegraphics{staronlyfilebb}
lipsum[2] textbf{Only page bounding box:}
includegraphics{staronlypagebb}
lipsum[3] textbf{Both bounding boxes:}
includegraphics{starbothbb}
lipsum[4] texttt{graphicx} textbf{trim and clip:}
includegraphics[trim={30 30 35 35},clip]{staroriginal}
lipsum[5]
end{document}

Result in DVI file:

enter image description here

So: in the DVI file, only file BB doesn't crop, only page BB crops but is big, both BB crops and is small, graphicx does not crop.

Result after dvipdfm:

enter image description here

So: in the PDF file from dvipdfm, only file BB crops, is small, but overlaps the text, only page BB doesn't crop, both BB crops, is small, but overlaps the text, graphicx crops, is small, does not overlap.

Result after dvips-ps2pdf:

enter image description here

So: in the PDF file from dvips-ps2pdf, only file BB does not crop and overlaps the text, only page BB doesn't crop but does not overlap, both BB doesn't crop and overlaps, graphicx crops, is small, does not overlap.

As a table:

enter image description here

Correct answer by Marijn on October 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP