62

I'm generating a PDF document with pdflatex (more precisely, latexmk invoked from TexMaker 3.4. My LaTeX install is TeXLive 20120719). I can read the document fine in Okular and Gmail's attachment preview, but a colleague that runs Acrobat Reader on Windows reports: "There was a problem reading this document (131)".

EDIT: The error disappears when using \usepackage[demo]{graphicx}, which puts black boxes instead of the real images. They are all PDFs, PNGs and JPGs. Instead of using demo, I added the code for a \demoincludegraphics command, which makes the file work in Reader when using it to replace the logo in the headers, as shown below. But enabling it (using \includegraphics instead of \demoincludegraphics) and removing everything else also works in Reader! There is some strange global interaction that makes the file appear broken to Reader when enabling all the graphics...

My code compiles fine, reason why I only attach the preamble and a simple text for a Minimal Working Example:

\documentclass[12pt,lettersize,twoside]{article}

\usepackage[utf8]{inputenc}
\usepackage[spanish,es-tabla]{babel}  
\usepackage[fixlanguage]{babelbib}
\usepackage{amssymb,amsmath}
\usepackage{graphicx}   
\usepackage{array}   
\usepackage{caption}
\usepackage{subfig}
\usepackage{rotating}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{calc}
\usepackage{stfloats}
\usepackage{fixltx2e}
\usepackage{url}
\usepackage[colorlinks=true,linkcolor=blue,citecolor=red]{hyperref}
\usepackage[all]{hypcap}

% Margins
\usepackage[top=2cm, bottom=2cm, left=3cm, right=2cm]{geometry}

% Make header show up in the first page
\makeatletter
\renewcommand\maketitle{\par
\begingroup
    \renewcommand\thefootnote{\@fnsymbol\c@footnote}%
    \def\@makefnmark{\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
    \long\def\@makefntext##1{\parindent 1em\noindent
            \hb@xt@1.8em{%
                \hss\@textsuperscript{\normalfont\@thefnmark}}##1}%
    \if@twocolumn
    \ifnum \col@number=\@ne
        \@maketitle
    \else
        \twocolumn[\@maketitle]%
    \fi
    \else
    \newpage
    \global\@topnum\z@   % Prevents figures from going at top of page.
    \@maketitle
    \fi
    \thispagestyle{fancy}\@thanks % was {empty}
\endgroup
\setcounter{footnote}{0}%
\global\let\thanks\relax
\global\let\maketitle\relax
\global\let\@maketitle\relax
\global\let\@thanks\@empty
\global\let\@author\@empty
\global\let\@date\@empty
\global\let\@title\@empty
\global\let\title\relax
\global\let\author\relax
\global\let\date\relax
\global\let\and\relax
}
\makeatother

% Remove date field in title; Remove preceding vertical space
\makeatletter
\renewcommand{\@maketitle}{
\vspace{-3cm}
\begin{center}%
{\LARGE \@title}\\
\vspace{2mm}%
{\@author}
\end{center}%
\par} \makeatother
\makeatletter

% Demo includegraphic boxes
\newcommand{\demoincludegraphics}[2][]{%
  \setlength{\fboxsep}{-\fboxrule}% Remove frame separator/gap
  \framebox{\rule{0pt}{100pt}\rule{150pt}{0pt}}% Framed box of 150pt x 100pt
}

% Headers Config 
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{}
\renewcommand{\headrulewidth}{0.4pt}
\setlength{\headheight}{2.2cm} 
\addtolength{\textheight}{-1.62cm}
\fancyhead[LO,RE]{\demoincludegraphics[height=1.6cm]{logo-slogan}}
\fancyhead[LE,RO]{}

% Footers Config
\fancyfoot{}
\renewcommand{\footrulewidth}{0pt}
\fancyfoot[C]{\thepage}

% Notas al pie etiquetadas por simbolos  
\renewcommand{\thefootnote}{\fnsymbol{footnote}}

\title{Doc Title}
\author{My name}

\begin{document}

\maketitle

This is a test. It includes graphics and other floats.


\end{document}

EDIT: I found a workaround: Processing the generated pdf file through Ghostscript, as follows:

 gs -dSAFER -dBATCH -dNOPAUSE  -sDEVICE=pdfwrite -sOutputFile=output.pdf input.pdf

where input.pdf is the file generated by pdfLaTeX, and output.pdf the one that will be readable by Adobe Reader and the rest of the PDF readers.

David Carlisle
  • 757,742
Luis E.
  • 983
  • 3
    No problem here with Adobe Reader 10.1.3 (in Windows 7). A search with your favorite searching machine should give you among others this match: http://helpx.adobe.com/x-productkb/multi/error-problem-reading-document-131.html – Speravir Jul 23 '12 at 22:05
  • Yes I saw that page before, not particularly illuminating, as it points to some "LiveCycle" software that I'm obviously not using. It tells about some "usage rights", and having looked for how to set that with LaTeX commands, I came out empty... – Luis E. Jul 24 '12 at 12:33
  • 3
    I can not recommend your workaround. The pdf is most likely fine; fix your problems with Adobe Reader. Also please add a minimal working example (MWE) that illustrates your problem. – Martin Schröder Jul 24 '12 at 15:49
  • I don't really know how to go about the MWE, as I would need to attach the images that go along the document. I understand your reasons, and that's precisely why I put the workaround as an edit. However, not being a LaTeX guru, I don't have much more control over the pdf generation process. The workaround also shrunk the file size, from 5.2 Mb to 1.4 Mb with no quality loss whatsoever, so it is a plus... – Luis E. Jul 24 '12 at 16:13
  • Did you check if each of your pdf included images are OK for Adobe Acrobat? – JLDiaz Jul 24 '12 at 17:55
  • Yes, I've checked. the PDFs at least. And anyways, since Reader fails only with all images embedded, but not if I take out either the logo image or everything except the logo, this indicates there is something about the PDF generation that Reader does not like afterwards. – Luis E. Jul 24 '12 at 18:42
  • 1
    I have asked a similar question, and I recommend the given answer, works great (although it's not a problem solution, it's just a workaround, like Martin Schröder pointed out). Take a look at http://tex.stackexchange.com/questions/78248/how-to-force-pdfminorversion-globally – Piotr Zierhoffer Oct 20 '12 at 08:16
  • @Speravir That link is utterly useless. It is a pity comment's can't be down voted. Does anyone actually understand what this error means? That link talks about saving the file, but why is reader even trying to save anything? – tacaswell Dec 10 '13 at 21:52
  • I got this issue after removing \setbeameroption{show notes on second screen=right}. Luckily, reverting to PDF 1.4 helped. – honey_badger Aug 09 '17 at 00:42
  • This solution was effective for me, but I think @zakkak's answer is preferable in cases where there is a faulty image and it can be identified and fixed. – EL_DON Sep 25 '18 at 16:42

3 Answers3

60

I solved a similar problem by generating a PDF 1.4 only with pdflatex using \pdfminorversion=4. I'm also only using png's and 1.4 pdf images in my latex document. It worked before with evince but now acroread also reads the file just fine and I preserve the same quality level. The ghostscript workaround resampled my images to jpeg which derogated the quality.

jmartinez
  • 773
  • 7
    Thanks for the answer. I had to place \pdfminorversion=4 before \documentclass{beamer}. – stali Dec 01 '12 at 03:25
  • 20
    If you don't want to decrease the pdf version setting \pdfobjcompresslevel=0 or \pdfobjcompresslevel=1 also solves the problem – ergoen Jun 03 '13 at 12:47
  • FYI, it turns out this is related to the problem "Warning: File(s) failed to convert" when submitting a paper to an IEEE journal over the ScholarOne Manuscript Central. Accidentally and luckily, I found out this also causes the error 131 in Acrobat Reader. The above \pdfminorversion=4 fixes it. – henrikz Aug 01 '13 at 10:46
  • 1
    This answer should be the accepted one, it worked for me too – lauhub May 13 '14 at 18:31
  • Awesome, adobe was giving me a different error about a damaged file. Setting pdfobjcompresslevel fixed the problem. – Maxime Jun 10 '14 at 13:10
  • Data point: This did not work for me, but Luis' workaround did. My issue seems to be with included 1.4 PDFs. – Andrew D. King Sep 08 '14 at 23:03
  • This wasn't enough, but got me closer. I had to follow these instructions as well: http://tex.stackexchange.com/questions/78248/how-to-force-pdfminorversion-globally – Matthew Turner Sep 08 '15 at 17:37
  • This solution does not function with recent versions of TexLive. – Luís de Sousa Mar 27 '17 at 07:27
13

As a workaround, you may also use pdftk uncompress/compress method:

pdftk original.pdf output uncompressed-original.pdf uncompress

and

pdftk uncompressed-original.pdf output original2.pdf compress

In addition to Linux packages, pdftk also has Windows and OS X builds.

gkcn
  • 231
7

In my case it was a png file causing the problem. Converting it to pdf resolved the issue.

convert faulty.png faulty.pdf
zakkak
  • 387
  • 2
    How did you find out which png file was the cause? – bluenote10 Apr 21 '15 at 10:25
  • It was the only file not being generated by pdflatex. Unfortunately I cannot provide a methodology or what was the problem in the png file. – zakkak Apr 22 '15 at 11:37
  • 4
    In my case it was also a faulty file, however, for me it was a PDF file that was the cause. The PDF in question was a plot from matplotlib that had been cropped using the boundingbox option in pyplot.savefig – regdoug May 15 '15 at 23:42
  • 1
    @regdoug, do you have a solution to this problem with matplotlib? I have the same issue when using boundingbox with pyplot.savefig. Did you just output png instead of pdf and lose the vector graphic? Or did you do something else? – Scott B May 27 '15 at 02:48
  • 1
    I output eps instead of pdf. That way it is still vector graphics – regdoug May 28 '15 at 04:55
  • This was my problem, too. I was able to identify which image was a problem because the error was associated with a specific page, and that page had only two images on it. Tthe gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=output.pdf input.pdf workaround left the problematic page blank, while newer versions of Adobe displayed the page as black in the original document. – EL_DON Sep 25 '18 at 16:41