first complete replace_obj
This commit is contained in:
parent
a147fb6f62
commit
094a0d01b5
|
@ -3450,8 +3450,9 @@ let extract_stream pdf decomp objnum =
|
||||||
(* Empty string is trailerdict. Begins with / and it's a chain separated by
|
(* Empty string is trailerdict. Begins with / and it's a chain separated by
|
||||||
commas. Begins with P and it's a page number then a (possibly empty) chain.
|
commas. Begins with P and it's a page number then a (possibly empty) chain.
|
||||||
Otherwise it's an object number (0 = trailerdict). *)
|
Otherwise it's an object number (0 = trailerdict). *)
|
||||||
|
let split_chain str = map (fun x -> "/" ^ x) (tl (String.split_on_char '/' str))
|
||||||
|
|
||||||
let print_obj pdf objspec =
|
let print_obj pdf objspec =
|
||||||
let split str = map (fun x -> "/" ^ x) (tl (String.split_on_char '/' str)) in
|
|
||||||
let simple_obj obj =
|
let simple_obj obj =
|
||||||
let obj = if obj = 0 then pdf.Pdf.trailerdict else Pdf.lookup_obj pdf obj in
|
let obj = if obj = 0 then pdf.Pdf.trailerdict else Pdf.lookup_obj pdf obj in
|
||||||
Printf.printf "%S\n" (Pdfwrite.string_of_pdf obj)
|
Printf.printf "%S\n" (Pdfwrite.string_of_pdf obj)
|
||||||
|
@ -3467,34 +3468,36 @@ let print_obj pdf objspec =
|
||||||
let number, chain =
|
let number, chain =
|
||||||
let digits, rest = cleavewhile isdigit more in
|
let digits, rest = cleavewhile isdigit more in
|
||||||
List.nth (Pdf.page_reference_numbers pdf) (int_of_string (implode digits) - 1),
|
List.nth (Pdf.page_reference_numbers pdf) (int_of_string (implode digits) - 1),
|
||||||
begin match split (implode rest) with [""] -> [] | x -> x end
|
begin match split_chain (implode rest) with [""] -> [] | x -> x end
|
||||||
in
|
in
|
||||||
chain_obj number chain
|
chain_obj number chain
|
||||||
| '/'::more -> chain_obj 0 (split (implode ('/'::more)))
|
| '/'::more -> chain_obj 0 (split_chain (implode ('/'::more)))
|
||||||
| [] -> simple_obj 0
|
| [] -> simple_obj 0
|
||||||
| _ -> simple_obj (int_of_string objspec)
|
| _ -> simple_obj (int_of_string objspec)
|
||||||
|
|
||||||
(* Empty string is trailerdict. Begins with / and it's a chain separated by
|
(* Empty string is trailerdict. Begins with / and it's a chain separated by commas. *)
|
||||||
commas. Begins with P and it's a page number then a (possibly empty) chain.
|
|
||||||
Otherwise it's an object number (0 = trailerdict). *)
|
|
||||||
let replace_obj pdf objspec obj =
|
let replace_obj pdf objspec obj =
|
||||||
let key, rest =
|
let key, chain =
|
||||||
let r, rest = cleavewhile (neq '/') (rev (explode objspec)) in
|
let r, rest = cleavewhile (neq '/') (rev (explode objspec)) in
|
||||||
(implode ('/'::rev r), implode (rev (tl rest)))
|
(implode ('/'::rev r), split_chain (implode (rev (tl rest))))
|
||||||
in
|
in
|
||||||
()
|
let rec find_max_existing to_fake chain =
|
||||||
(*match .... rest .... with
|
if chain = [] then (chain, to_fake) else
|
||||||
| ...not objnum... ->
|
match Pdf.lookup_chain pdf pdf.Pdf.trailerdict chain with
|
||||||
(* 1. It's not an object number *)
|
| None -> find_max_existing (hd chain::to_fake) (tl chain)
|
||||||
let chain =
|
| _ -> (chain, to_fake)
|
||||||
(* 1. Chain with /s *)
|
in
|
||||||
(* 2. P plus possibly empty chain *)
|
let rec wrap_obj obj = function
|
||||||
[]
|
| [] -> obj
|
||||||
in
|
| h::t -> Pdf.Dictionary [(h, wrap_obj obj t)]
|
||||||
Pdf.replace_chain pdf chain (k, obj)
|
in
|
||||||
(* 2. It is an object number *)
|
let chain, to_fake = find_max_existing [] chain in
|
||||||
| _ ->
|
let obj = wrap_obj obj to_fake in
|
||||||
(* Replace chain within object. How? *)*)
|
Printf.printf "obj is %s\n" (Pdfwrite.string_of_pdf obj);
|
||||||
|
Printf.printf "chain is:\n";
|
||||||
|
iter (Printf.printf "%s ") chain;
|
||||||
|
Printf.printf "\n";
|
||||||
|
Pdf.replace_chain pdf chain (key, obj)
|
||||||
|
|
||||||
(* Main function *)
|
(* Main function *)
|
||||||
let go () =
|
let go () =
|
||||||
|
@ -4522,7 +4525,8 @@ let go () =
|
||||||
print_obj pdf s
|
print_obj pdf s
|
||||||
| Some (ReplaceObj (a, b)) ->
|
| Some (ReplaceObj (a, b)) ->
|
||||||
let pdf = get_single_pdf args.op false in
|
let pdf = get_single_pdf args.op false in
|
||||||
replace_obj pdf a b
|
let pdfobj = Cpdfjson.object_of_json (Cpdfyojson.Safe.from_string b) in
|
||||||
|
replace_obj pdf a pdfobj
|
||||||
| Some (Verify standard) ->
|
| Some (Verify standard) ->
|
||||||
begin match standard with
|
begin match standard with
|
||||||
| "PDF/UA-1(matterhorn)" ->
|
| "PDF/UA-1(matterhorn)" ->
|
||||||
|
|
Loading…
Reference in New Issue