23

I am getting the following error on few images being loaded by pdflatex. The images are in pdf files. MWE

\documentclass[10pt,notitlepage]{article}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{image}
\end{document}

pdflatex foo.tex gives

(/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/etexcmds.sty)))
(/usr/local/texlive/2015/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
! Dimension too large.
<argument> \ht \@tempboxa 

l.7 ...,height=\textheight,keepaspectratio]{image}

? 

The image.pdf is this link

It doe not matter if the image size specification is there or not, the error still shows up. i.e. \includegraphics[]{image} also generates the error.

The image pdf file has nothing in it. This is another issue. This image pdf file was created by Mathematica Export command. I was exporting a Mathematica image to pdf and it looks like Mathematica could not export the image to pdf file so it wrote an empty image pdf file. But the question is why pdflatex gives an error?

Is there a memory limit or some build in limit on size of pdf image files or dimensions?

I am using TL 2015 on linux mint 7.2

ps. Here is an example of pdf image file that is correctly read by pdflatex. It is not as large (and happened not to be empty as well).

Update:

fyi, Thanks to cfr comment in my other question How to check that image has valid size before `\includegraphics` is called? , using pdfinfo -box image.pdf gives

>pdfinfo -box image.pdf
Creator:        Wolfram Mathematica 10.1.0.0 for Microsoft Windows (64-bit) (March 23, 2015) Student Edition - Personal Use Only
Producer:       
CreationDate:   Tue Jul 21 13:15:48 2015
ModDate:        Tue Jul 21 13:15:48 2015
Tagged:         no
Form:           none
Pages:          1
Encrypted:      no
Page size:      504 x 18988 pts
Page rot:       0
MediaBox:           0.00     0.00   504.00 18988.00
CropBox:            0.00     0.00   504.00 18988.00
BleedBox:           0.00     0.00   504.00 18988.00
TrimBox:            0.00     0.00   504.00 18988.00
ArtBox:             0.00     0.00   504.00 18988.00
File size:      337034 bytes
Optimized:      no
PDF version:    1.5
>
Nasser
  • 20,220
  • That's a really large image you're trying to include! – Gonzalo Medina Jul 26 '15 at 21:50
  • Your image reports as being 7x263.722 in! So the height is nearly 6.7 meters! – Gonzalo Medina Jul 26 '15 at 21:53
  • @ChristianHupfer No; it's not a blank page; it's full of formulas and code. – Gonzalo Medina Jul 26 '15 at 21:55
  • @GonzaloMedina: I opened it with Adobe Reader and it's blank. I see only white background and it reports a totally different size compared to your values –  Jul 26 '15 at 21:56
  • @ChristianHupfer That's why I use Okular :-) – Gonzalo Medina Jul 26 '15 at 21:56
  • Somewhat related: http://tex.stackexchange.com/questions/420/whats-the-absolute-largest-paper-size-permissible-with-pdflatex –  Jul 26 '15 at 21:58
  • @GonzaloMedina: Strange: Even in Okular and Evince the file image.pdf is empty –  Jul 26 '15 at 21:59
  • @ChristianHupfer I have thousands of such pdf image files created by Mathematica. I use Mathematica Export command. Few of them are too large and give such error. The question here is., why pdflatex gives an error? Is there a limit somewhere in pdf that one should know about? – Nasser Jul 26 '15 at 22:00
  • @Nasser: Gonzalo Medina just answered it. (La)TeX can't cope with more than 2^30 − 1sp. And I believe that you don't want to have an image with a height of 6.70 m ;-) –  Jul 26 '15 at 22:01
  • 1
    It's very big and acrobat says it has invalid ids internally. You can probably load it into something else then save at half size or less, although it's not going to be readable when scale into the a4 page anyway. – David Carlisle Jul 26 '15 at 22:04
  • 1
    @Nasser the limit is not related to images it is a limit on tex dimensions. You can not have a length bigger than \maxdimen – David Carlisle Jul 26 '15 at 22:06
  • @ChristianHupfer How long did you wait? It is a big, big file and Okular took a long time to show the content for me. Initially, it looked blank but it just needed patience. – cfr Jul 26 '15 at 22:58
  • @cfr: Oh my, you're right... And all this for some formulas. Mathematica's exporter seems to be quite exaggerating ;-) –  Jul 26 '15 at 23:02

3 Answers3

15

There's a limit for graphics dimensions, bounded above by \maxdimen (16384pt); in the case of the height for images, the limit is around 574cm to 576cm for some of the images I tested. For example,

\documentclass{article}
\usepackage{graphicx}

\begin{document}

\includegraphics[height=576cm,width=2cm]{example-image-a}  

\end{document}

triggers the error message, but using 575 there's no error (just the obvious warning about overfull \vbox)

Your image is almost 670cm high! (clearly higher than \maxdimen) so the error is triggered. Besides that, what would you do with such a large image compressed to fit into an a4paper document?

Gonzalo Medina
  • 505,128
  • Thanks. Is there a way to check for this in Latex before loading the image? I have thousands of such images, generated automatically and I do not know what size they will come out as. I need a way to check then if the image is too large and not include, else the build will fail. Most the images are small, but few, due to the computation, can show up this large. – Nasser Jul 26 '15 at 22:08
  • Open the image in your viewer and check the "Properties" section. – Gonzalo Medina Jul 26 '15 at 22:09
  • This is all automated. I need a way in Latex to check if the image can be loaded correctly before issuing the includegraphics command so that my build does not fail in the middle. I can't open each image manually and check its size one by one. – Nasser Jul 26 '15 at 22:12
  • @Nasser Sounds like a topic for another question? Since you are generating the files, can't you just set a limit for the height before the images are created? – Gonzalo Medina Jul 26 '15 at 22:13
  • 1
    These are Mathematica graphics, exported to pdf using Mathematica Export. From design point of view, it is better to have the program trying to load the pdf to check if it can do it not, than trying to figure how to make Mathematica only export pdf files that Latex can load. May be later I want to use these pdf files by another program than can read them? Also it is hard to map Mathematica graphics sizes to what will show up as in pdf after export. – Nasser Jul 26 '15 at 22:38
  • @Nasser Playing devil's advocate: why should TeX worry about you (or other software) not exceeding its limits? – Gonzalo Medina Jul 26 '15 at 22:41
  • 1
    Well it obviously does care or it wouldn't go bananas when @Nasser does! Indeed, if it cared less, there wouldn't be a problem... ;). – cfr Jul 26 '15 at 22:53
  • @cfr Yes, perhaps I didn't express myself right. What I meant is why should TeX try to correct the situation when its limits are exceeded? If an object exceed's TeX's limits, TeX reports the problem, but it's the user responsability to take corrective action. – Gonzalo Medina Jul 26 '15 at 23:28
  • 2
    The issue not for latex to "correct" anything. The issue is to provide the means for the user to check if they want to load the image or not. This is called defensive programming. I should be able to write a Latex document that handle any size images by adding checks. If the image is too large, I will not load it. Now my Latex document is robust and will compile all the time. I can replace the image by a message saying image too large to include. Any way, I opened new question on this topic so this discussion may be belong to there. – Nasser Jul 26 '15 at 23:35
5

This may happen also if the image has sane size, but has declared incorrect DPI set (for example 800x600 pixels image, but with 2x2 DPI set... which makes it 1000 cm wide).

You can correct the DPI in an image editor (well, if it is not a PDF file), and it should work fine.

4

Another issue that seems to cause this problem is if the image is in CMYK colorspace (even if the dimensions are below the max limit). To fix this, you can re-save it as an RGB image using Photoshop or another image editing tool, or convert it directly using one of the many converters online such as http://www.cmykconverter.com/

This occurred with XeLateX on the Overleaf platform.

Max
  • 141