Implement -print-page-labels-json

This commit is contained in:
John Whitington 2023-10-31 17:28:07 +00:00
parent 122285db59
commit 45c8213e80
1 changed files with 13 additions and 3 deletions

View File

@ -4149,9 +4149,19 @@ let go () =
write_pdf false pdf write_pdf false pdf
| Some PrintPageLabels -> | Some PrintPageLabels ->
let pdf = get_single_pdf args.op true in let pdf = get_single_pdf args.op true in
iter if args.format_json then
print_string let json_of_pagelabel l =
(map Pdfpagelabels.string_of_pagelabel (Pdfpagelabels.read pdf)) `Assoc
[("labelstyle", `String (Pdfpagelabels.string_of_labelstyle l.Pdfpagelabels.labelstyle));
("labelprefix", begin match l.Pdfpagelabels.labelprefix with None -> `Null | Some s -> `String s end);
("startpage", `Int l.Pdfpagelabels.startpage);
("startvalue", `Int l.Pdfpagelabels.startvalue)]
in
flprint (Cpdfyojson.Safe.pretty_to_string (`List (map json_of_pagelabel (Pdfpagelabels.read pdf))))
else
iter
print_string
(map Pdfpagelabels.string_of_pagelabel (Pdfpagelabels.read pdf))
| Some (RemoveDictEntry key) -> | Some (RemoveDictEntry key) ->
let pdf = get_single_pdf args.op true in let pdf = get_single_pdf args.op true in
Cpdftweak.remove_dict_entry pdf key args.dict_entry_search; Cpdftweak.remove_dict_entry pdf key args.dict_entry_search;