This commit is contained in:
John Whitington 2023-01-17 13:37:54 +08:00
parent 0bd9853d99
commit d148d8fedf
3 changed files with 11 additions and 11 deletions

View File

@ -1705,14 +1705,14 @@ let setprintdictentry s =
let setreplacedictentryvalue s =
try
let pdfobj = Cpdfjson.object_of_json ~utf8:false (Cpdfyojson.Safe.from_string s) in
let pdfobj = Cpdfjson.object_of_json ~utf8:(args.encoding = Cpdfmetadata.UTF8) (Cpdfyojson.Safe.from_string s) in
args.replace_dict_entry_value <- pdfobj
with
e -> error (Printf.sprintf "Failed to parse replacement value: %s\n" (Printexc.to_string e))
let setdictentrysearch s =
try
let pdfobj = Cpdfjson.object_of_json ~utf8:false (Cpdfyojson.Safe.from_string s) in
let pdfobj = Cpdfjson.object_of_json ~utf8:(args.encoding = Cpdfmetadata.UTF8) (Cpdfyojson.Safe.from_string s) in
args.dict_entry_search <- Some pdfobj
with
e -> error (Printf.sprintf "Failed to parse search term: %s\n" (Printexc.to_string e))
@ -3332,7 +3332,7 @@ let write_json output pdf =
| Stdout ->
Cpdfjson.to_output
(Pdfio.output_of_channel stdout)
~utf8:false
~utf8:(args.encoding = Cpdfmetadata.UTF8)
~parse_content:args.jsonparsecontentstreams
~no_stream_data:args.jsonnostreamdata
~decompress_streams:args.jsondecompressstreams
@ -3342,7 +3342,7 @@ let write_json output pdf =
let f = open_out filename in
Cpdfjson.to_output
(Pdfio.output_of_channel f)
~utf8:false
~utf8:(args.encoding = Cpdfmetadata.UTF8)
~parse_content:args.jsonparsecontentstreams
~no_stream_data:args.jsonnostreamdata
~decompress_streams:args.jsondecompressstreams
@ -4258,7 +4258,7 @@ let go () =
write_pdf false pdf
| Some (PrintDictEntry key) ->
let pdf = get_single_pdf args.op true in
Cpdftweak.print_dict_entry pdf key
Cpdftweak.print_dict_entry ~utf8:(args.encoding = Cpdfmetadata.UTF8) pdf key
| Some ListSpotColours ->
let pdf = get_single_pdf args.op false in
Cpdfspot.list_spot_colours pdf

View File

@ -264,12 +264,12 @@ let replace_dict_entry pdf key value search =
pdf.Pdf.trailerdict <- dict_entry_single_object f pdf pdf.Pdf.trailerdict
(* FIXME no need to self map here, since nothing changes *)
let print_dict_entry pdf key =
let print_dict_entry ~utf8 pdf key =
let f d =
match Pdf.lookup_direct pdf key d with
| Some v ->
(* We use a double newline as a separator. *)
Printf.printf "%s\n\n" (Cpdfyojson.Safe.to_string (Cpdfjson.json_of_object ~utf8:false ~clean_strings:true pdf (fun _ -> ()) ~no_stream_data:false ~parse_content:false v));
Printf.printf "%s\n\n" (Cpdfyojson.Safe.to_string (Cpdfjson.json_of_object ~utf8 ~clean_strings:true pdf (fun _ -> ()) ~no_stream_data:false ~parse_content:false v));
d
| None -> d
in
@ -277,11 +277,11 @@ let print_dict_entry pdf key =
pdf.Pdf.trailerdict <- dict_entry_single_object f pdf pdf.Pdf.trailerdict
(* For cpdflib. *)
let get_dict_entries pdf key =
let get_dict_entries ~utf8 pdf key =
let es = ref [] in
let f d =
match Pdf.lookup_direct pdf key d with
| Some v -> es := Cpdfjson.json_of_object ~utf8:false ~clean_strings:true pdf (fun _ -> ()) ~no_stream_data:false ~parse_content:false v::!es; d
| Some v -> es := Cpdfjson.json_of_object ~utf8 ~clean_strings:true pdf (fun _ -> ()) ~no_stream_data:false ~parse_content:false v::!es; d
| None -> d
in
Pdf.objselfmap (dict_entry_single_object f pdf) pdf;

View File

@ -22,10 +22,10 @@ val remove_dict_entry : Pdf.t -> string -> Pdf.pdfobject option -> unit
val replace_dict_entry : Pdf.t -> string -> Pdf.pdfobject -> Pdf.pdfobject option -> unit
(** Print a dictionary entry. *)
val print_dict_entry : Pdf.t -> string -> unit
val print_dict_entry : utf8:bool -> Pdf.t -> string -> unit
(** Get dictionary entries in JSON format *)
val get_dict_entries : Pdf.t -> string -> Pdfio.bytes
val get_dict_entries : utf8:bool -> Pdf.t -> string -> Pdfio.bytes
(** Remove clipping. *)
val remove_clipping : Pdf.t -> int list -> Pdf.t