diff --git a/Changes b/Changes index 1f3d66d..fb65968 100644 --- a/Changes +++ b/Changes @@ -28,6 +28,7 @@ o More PNGs - greyscale 1, 2, 4, 8, 16bpp and RGB 16bpp o -pages -fast to print number of pages from /Count o Report number of annotations in -page-info o Specify image based only on file extension +o -squeeze updates old compression methods Fixes: @@ -36,7 +37,6 @@ o Fixed -set-annotations with page links o Allow Exif JPEGs as well as JFIF ones in -jpeg and -draw-jpeg o Only compress a stream if it actually makes it smaller - 2.6.1 (September 2023) o Fixed regression in UTF8 text with -add-text diff --git a/cpdfsqueeze.ml b/cpdfsqueeze.ml index 8e1de1a..dad29c2 100644 --- a/cpdfsqueeze.ml +++ b/cpdfsqueeze.ml @@ -13,14 +13,19 @@ let report_pdf_size pdf = (* Recompress anything which isn't compressed, unless it's metadata. *) let recompress_stream pdf = function - (* If there is no compression, compress with /FlateDecode *) + (* If there is no compression, or bad compression with /FlateDecode *) | Pdf.Stream {contents = (dict, _)} as stream -> begin match Pdf.lookup_direct pdf "/Filter" dict, Pdf.lookup_direct pdf "/Type" dict with | _, Some (Pdf.Name "/Metadata") -> () - | (None | Some (Pdf.Array [])), _ -> + | ( None + | Some (Pdf.Name ("/ASCIIHexDecode" | "/ASCII85Decode" | "/LZWDecode" | "/RunLengthDecode")) + | Some (Pdf.Array [] + | Pdf.Array (Pdf.Name ("/ASCIIHexDecode" | "/ASCII85Decode" | "/LZWDecode" | "/RunLengthDecode")::_) + )), _ -> + Pdfcodec.decode_pdfstream_until_unknown pdf stream; Pdfcodec.encode_pdfstream ~only_if_smaller:true pdf Pdfcodec.Flate stream | _ -> () end