From 45c8213e80734528b75f82d9297cdc26a6704cc5 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Tue, 31 Oct 2023 17:28:07 +0000 Subject: [PATCH] Implement -print-page-labels-json --- cpdfcommand.ml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index ee8eaf2..5efe50b 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -4149,9 +4149,19 @@ let go () = write_pdf false pdf | Some PrintPageLabels -> let pdf = get_single_pdf args.op true in - iter - print_string - (map Pdfpagelabels.string_of_pagelabel (Pdfpagelabels.read pdf)) + if args.format_json then + let json_of_pagelabel l = + `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) -> let pdf = get_single_pdf args.op true in Cpdftweak.remove_dict_entry pdf key args.dict_entry_search;