Add piece info to composition

This commit is contained in:
John Whitington 2024-11-05 11:51:47 +00:00
parent ca01631140
commit bddda88b71
4 changed files with 29 additions and 6 deletions

View File

@ -1,9 +1,10 @@
2.7.3 (to come) 2.7.3 (to come)
o New -center-to-fit centres pages on a given paper size o New -center-to-fit centres pages on a given paper size
o Allow bold, italic, colours for bookmarks o Allow bold, italic, colours for JSON bookmarks
o Clean up @B implementation for -split-on-bookmarks o Clean up @B implementation for -split-on-bookmarks
o Add @b<n>@ for trimming bookmark text to given length o Add @b<n>@ for trimming bookmark text to given length
o Add Piece Info to -composition[-json]
2.7.2 (October 2024) 2.7.2 (October 2024)

View File

@ -18,6 +18,23 @@ let find_composition_structure_info pdf marked =
end end
| _ -> [] | _ -> []
let find_composition_piece_info pdf marked =
let l = ref [] in
Pdf.objiter
(fun i obj ->
match Pdf.lookup_direct pdf "/PieceInfo" obj with
| Some x ->
let objs = Pdf.objects_referenced [] [] pdf x in
iter
(fun i ->
match Hashtbl.find marked i with
| () -> ()
| exception Not_found -> l := i::!l; Hashtbl.add marked i ())
objs
| None -> ())
pdf;
!l
let find_composition_images pdf i obj marked = let find_composition_images pdf i obj marked =
match Hashtbl.find marked i with () -> [] | exception Not_found -> 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
@ -91,7 +108,8 @@ let find_composition pdf =
fonts := find_composition_fonts pdf i obj marked @ !fonts) fonts := find_composition_fonts pdf i obj marked @ !fonts)
pdf; pdf;
let structure_info = find_composition_structure_info pdf marked in let structure_info = find_composition_structure_info pdf marked in
(!images, !fonts, !content_streams, structure_info) let piece_info = find_composition_piece_info pdf marked in
(!images, !fonts, !content_streams, structure_info, piece_info)
let size pdf i = let size pdf i =
String.length (Pdfwrite.string_of_pdf_including_data (Pdf.lookup_obj pdf i)) String.length (Pdfwrite.string_of_pdf_including_data (Pdf.lookup_obj pdf i))
@ -119,22 +137,24 @@ let compressed_xref_table_size pdf =
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 o_images, o_fonts, o_content_streams, o_structure_info = find_composition pdf in let o_images, o_fonts, o_content_streams, o_structure_info, o_piece_info = find_composition pdf in
let images, fonts, content_streams, structure_info, attached_files, xref_table = let images, fonts, content_streams, structure_info, attached_files, piece_info, xref_table =
compressed_size pdf o_images, compressed_size pdf o_images,
compressed_size pdf o_fonts, compressed_size pdf o_fonts,
compressed_size pdf o_content_streams, compressed_size pdf o_content_streams,
compressed_size pdf o_structure_info, compressed_size pdf o_structure_info,
Cpdfattach.size_attached_files pdf, Cpdfattach.size_attached_files pdf,
compressed_size pdf o_piece_info,
compressed_xref_table_size pdf compressed_xref_table_size pdf
in in
let r = images + fonts + content_streams + structure_info + attached_files + xref_table in let r = images + fonts + content_streams + structure_info + attached_files + xref_table + piece_info in
`List [`List [`String "Images"; `Int images; `Float (perc images)]; `List [`List [`String "Images"; `Int images; `Float (perc images)];
`List [`String "Fonts"; `Int fonts; `Float (perc fonts)]; `List [`String "Fonts"; `Int fonts; `Float (perc fonts)];
`List [`String "Content streams"; `Int content_streams; `Float (perc content_streams)]; `List [`String "Content streams"; `Int content_streams; `Float (perc content_streams)];
`List [`String "Structure Info"; `Int structure_info; `Float (perc structure_info)]; `List [`String "Structure Info"; `Int structure_info; `Float (perc structure_info)];
`List [`String "Attached Files"; `Int attached_files; `Float (perc attached_files)]; `List [`String "Attached Files"; `Int attached_files; `Float (perc attached_files)];
`List [`String "XRef Table"; `Int xref_table; `Float (perc xref_table)]; `List [`String "XRef Table"; `Int xref_table; `Float (perc xref_table)];
`List [`String "Piece Info"; `Int piece_info; `Float (perc piece_info)];
`List [`String "Unclassified"; `Int (filesize - r); `Float (perc (filesize - r))]] `List [`String "Unclassified"; `Int (filesize - r); `Float (perc (filesize - r))]]
let show_composition_json_blob filesize pdf = let show_composition_json_blob filesize pdf =

Binary file not shown.

View File

@ -3600,6 +3600,7 @@ Content streams: 132767 bytes (42.85%)
Structure Info: 0 bytes (0.00%) Structure Info: 0 bytes (0.00%)
Attached Files: 0 bytes (0.00%) Attached Files: 0 bytes (0.00%)
XRef Table: 21082 bytes (6.80%) XRef Table: 21082 bytes (6.80%)
Piece Info: 0 bytes (0.00%)
Unclassified: 11229 bytes (3.62%) Unclassified: 11229 bytes (3.62%)
\end{verbatim} \end{verbatim}
\end{framed}\pagestyle{empty}\thispagestyle{fancy} \end{framed}\pagestyle{empty}\thispagestyle{fancy}
@ -3614,12 +3615,13 @@ Unclassified: 11229 bytes (3.62%)
("Structure Info", 0, 0.0), ("Structure Info", 0, 0.0),
("Attached Files", 0, 0.0), ("Attached Files", 0, 0.0),
("XRef Table", 21082, 6.8048378194306816), ("XRef Table", 21082, 6.8048378194306816),
("Piece Info", 0, 0.0),
("Unclassified", 11229, 3.6244912187831857) ("Unclassified", 11229, 3.6244912187831857)
] ]
\end{verbatim} \end{verbatim}
\end{framed}\pagestyle{empty}\thispagestyle{fancy} \end{framed}\pagestyle{empty}\thispagestyle{fancy}
\noindent Note that, due to small inaccuracies in the method, it is possible for the \texttt{Unclassified} number to be negative. \noindent Note that, due to small inaccuracies in the method, it is possible for the \texttt{Unclassified} numbers to be negative.
\begin{cpdflib} \begin{cpdflib}
\clearpage \clearpage