This commit is contained in:
John Whitington 2023-03-06 16:56:46 +00:00
parent 0af6af567d
commit 51472da1fa
1 changed files with 13 additions and 12 deletions

View File

@ -3376,28 +3376,29 @@ let warn_prerotate range pdf =
let prerotate range pdf = let prerotate range pdf =
Cpdfpage.upright ~fast:args.fast range pdf Cpdfpage.upright ~fast:args.fast range pdf
let find_images pdf = let find_composition pdf =
let imageobjs = ref [] in let marked = null_hash () in
let size = ref 0 in let images = ref 0 in
let content_streams = ref 0 in
Pdf.objiter Pdf.objiter
(fun i obj -> (fun i obj ->
match Hashtbl.find marked i with _ -> () | exception Not_found ->
match Pdf.lookup_direct pdf "/Subtype" obj with match Pdf.lookup_direct pdf "/Subtype" obj with
| Some (Pdf.Name "/Image") -> | Some (Pdf.Name "/Image") ->
size += String.length (Pdfwrite.string_of_pdf_including_data obj); images += String.length (Pdfwrite.string_of_pdf_including_data obj);
imageobjs =| i Hashtbl.add marked i ()
| _ -> ()) | _ -> ())
pdf; pdf;
(!size, !imageobjs) (!images, !content_streams)
(* First go: images, fonts, content streams, structure info, link annotations, embedded files *) (* First go: images, fonts, content streams, structure info, link annotations, embedded files *)
let show_composition_json filesize pdf = let show_composition_json filesize pdf =
let perc x = float_of_int x /. float_of_int filesize *. 100. in let perc x = float_of_int x /. float_of_int filesize *. 100. in
let marked = null_hash () in let images, content_streams = find_composition pdf in
let images, objs = find_images pdf in let r = images + content_streams in
iter (fun o -> Hashtbl.add marked o ()) objs; `List [`Tuple [`String "Images"; `Int images; `Float (perc images)];
let r = images in `Tuple [`String "Content streams"; `Int content_streams; `Float (perc content_streams)];
`List [`Tuple [`String "Images"; `Int images; `Float (perc images)]; `Tuple [`String "Unclassified"; `Int (filesize - r); `Float (perc (filesize - r))]]
`Tuple [`String "Unclassified"; `Int (filesize - r); `Float (perc (filesize - r))]]
let show_composition filesize json pdf = let show_composition filesize json pdf =
let module J = Cpdfyojson.Safe in let module J = Cpdfyojson.Safe in