From ed90fb4c92b51e36d02af4a280d301305306da68 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Sat, 20 Sep 2014 20:16:08 +0100 Subject: [PATCH] Use -objstm-create for squeeze --- cpdfcommand.ml | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index a374996..fef215a 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -1014,7 +1014,8 @@ let setscalecontents f = args.position <- Cpdf.Diagonal (* Will be center *) let setsqueeze () = - args.squeeze <- true + args.squeeze <- true; + args.create_objstm <- true (* Parsing the control file *) let rec getuntilendquote prev = function @@ -1772,9 +1773,17 @@ let pdfobjeq pdf x y = and y = Pdf.lookup_obj pdf y in begin match x with Pdf.Stream _ -> Pdf.getstream x | _ -> () end; begin match y with Pdf.Stream _ -> Pdf.getstream y | _ -> () end; - compare x y + match x with + (*Pdf.Dictionary _ + when + Pdf.lookup_direct pdf "/Type" x = Some (Pdf.Name "/Page") + -> + (-1)*) (* FIXME *) + | _ -> compare x y -let squeeze pdf = +(* FIXME: We need to be able to do squeeze on encrypted files, which at the + * moment thinks it has a permissions problem. *) +let really_squeeze pdf = let objs = ref [] in Pdf.objiter (fun objnum _ -> objs := objnum :: !objs) pdf; let toprocess = @@ -1802,6 +1811,16 @@ let squeeze pdf = pdf.Pdf.objects <- !pdfr.Pdf.objects; pdf.Pdf.trailerdict <- !pdfr.Pdf.trailerdict +(* We run squeeze enough times to reach a fixed point in the cardinality of the + * object map *) +let squeeze pdf = + let n = ref (Pdf.objcard pdf) in + Printf.printf "Beginning squeeze: %i objects\n%!" (Pdf.objcard pdf); + while !n > (ignore (really_squeeze pdf); Pdf.objcard pdf) do + n := Pdf.objcard pdf; + Printf.printf "Squeezing... Down to %i objects\n%!" (Pdf.objcard pdf); + done + let write_pdf mk_id pdf = if args.create_objstm && not args.keepversion then pdf.Pdf.minor <- max pdf.Pdf.minor 5;