diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 5769cd3..c4bfa8a 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -1826,22 +1826,30 @@ let squeeze_all_content_streams pdf = Some d -> d | None -> Pdf.Dictionary [] in - let newstream = - match lookup "/Contents" dict with - Some (Pdf.Indirect i) -> + begin try + let newstream = + let content_streams = + match lookup "/Contents" dict with + Some (Pdf.Indirect i) -> + begin match Pdf.direct pdf (Pdf.Indirect i) with + Pdf.Array x -> x + | _ -> [Pdf.Indirect i] + end + | Some (Pdf.Array x) -> x + | _ -> raise Not_found + in Pdfops.stream_of_ops - (Pdfops.parse_operators pdf resources [Pdf.Indirect i]) - | Some (Pdf.Array x) -> - Pdfops.stream_of_ops - (Pdfops.parse_operators pdf resources x) - | _ -> - raise (Pdf.PDFError "squeeze_all_content_streams") - in - let newdict = - Pdf.add_dict_entry - d "/Contents" (Pdf.Indirect (Pdf.addobj pdf newstream)) + (Pdfops.parse_operators pdf resources content_streams) in - Pdf.addobj_given_num pdf (objnum, newdict) + let newdict = + Pdf.add_dict_entry + d "/Contents" (Pdf.Indirect (Pdf.addobj pdf newstream)) + in + Pdf.addobj_given_num pdf (objnum, newdict) + with + (* No /Contents, which is ok. *) + Not_found -> () + end | _ -> ()) pdf diff --git a/cpdfmanual.pdf b/cpdfmanual.pdf index b2aba40..4dbc072 100644 Binary files a/cpdfmanual.pdf and b/cpdfmanual.pdf differ diff --git a/cpdfmanual.tex b/cpdfmanual.tex index 9ba64ff..80115e4 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -943,12 +943,23 @@ PDF, use: \section{Squeezing a Document} \index{squeeze} - To \textit{squeeze} a PDF file, use: + To \textit{squeeze} a PDF file, reducing its size by an average of about twenty percent (though sometimes not at all), use: \begin{framed} \small\verb!cpdf -squeeze in.pdf -o out.pdf! \end{framed} - \noindent Adding \texttt{-squeeze} to the command line will \textit{squeeze} the file upon output. The squeezing process involves several processes which losslessly attempt to reduce the file size. The squeezing process is slow. + \noindent Adding \texttt{-squeeze} to the command line when using another operation will \textit{squeeze} the file or files upon output. + The \texttt{-squeeze} operation writes some information about the squeezing process to standard output. The squeezing process involves several processes which losslessly attempt to reduce the file size. It is slow, so should not be used without thought. + +\begin{verbatim} +$ ./cpdf -squeeze in.pdf -o out.pdf +Beginning squeeze: 123847 objects +Squeezing... Down to 114860 objects +Squeezing... Down to 114842 objects +Squeezing page data +Recompressing document +\end{verbatim} + \chapter{Bookmarks} \begin{framed} \small\noindent\verb!cpdf -list-bookmarks [-utf8 | -raw] in.pdf!