more
This commit is contained in:
parent
c532281c81
commit
0af6af567d
|
@ -3376,9 +3376,6 @@ 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
|
||||||
|
|
||||||
(* Size of a single object *)
|
|
||||||
let object_size o = 0
|
|
||||||
|
|
||||||
let find_images pdf =
|
let find_images pdf =
|
||||||
let imageobjs = ref [] in
|
let imageobjs = ref [] in
|
||||||
let size = ref 0 in
|
let size = ref 0 in
|
||||||
|
@ -3386,24 +3383,30 @@ let find_images pdf =
|
||||||
(fun i obj ->
|
(fun i obj ->
|
||||||
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 += object_size obj;
|
size += String.length (Pdfwrite.string_of_pdf_including_data obj);
|
||||||
imageobjs =| i
|
imageobjs =| i
|
||||||
| _ -> ())
|
| _ -> ())
|
||||||
pdf;
|
pdf;
|
||||||
(!size, !imageobjs)
|
(!size, !imageobjs)
|
||||||
|
|
||||||
let show_composition filesize json pdf =
|
(* First go: images, fonts, content streams, structure info, link annotations, embedded files *)
|
||||||
let perc x = int_of_float (float_of_int x /. float_of_int filesize *. 100.) in
|
let show_composition_json filesize pdf =
|
||||||
|
let perc x = float_of_int x /. float_of_int filesize *. 100. in
|
||||||
let marked = null_hash () in
|
let marked = null_hash () in
|
||||||
let images, objs = find_images pdf in
|
let images, objs = find_images pdf in
|
||||||
iter (fun o -> Hashtbl.add marked o ()) objs;
|
iter (fun o -> Hashtbl.add marked o ()) objs;
|
||||||
(*Printf.printf "Fonts: %i bytes (%i%%)\n" !fonts (perc !fonts);*)
|
|
||||||
Printf.printf "Images: %i bytes (%i%%)\n" images (perc images);
|
|
||||||
(*Printf.printf "Page data: %i bytes (%i%%)\n" !page_data (perc !page_data);
|
|
||||||
Printf.printf "XMP metadata: %i bytes (%i%%)\n" !xmp_metadata (perc !xmp_metadata);
|
|
||||||
let r = !fonts + !images + !page_data + !xmp_metadata in*)
|
|
||||||
let r = images in
|
let r = images in
|
||||||
Printf.printf "Unclassified: %i bytes (%i%%)\n" r (perc (filesize - r))
|
`List [`Tuple [`String "Images"; `Int images; `Float (perc images)];
|
||||||
|
`Tuple [`String "Unclassified"; `Int (filesize - r); `Float (perc (filesize - r))]]
|
||||||
|
|
||||||
|
let show_composition filesize json pdf =
|
||||||
|
let module J = Cpdfyojson.Safe in
|
||||||
|
let j = show_composition_json filesize pdf in
|
||||||
|
if json then (flprint (J.pretty_to_string j); flprint "\n") else
|
||||||
|
match j with
|
||||||
|
| `List js ->
|
||||||
|
iter (function `Tuple [`String a; `Int b; `Float c] -> Printf.printf "%s: %i bytes (%.1f%%)\n" a b c | _ -> ()) js
|
||||||
|
| _ -> ()
|
||||||
|
|
||||||
let embed_font () =
|
let embed_font () =
|
||||||
match args.font with
|
match args.font with
|
||||||
|
|
Loading…
Reference in New Issue