Added -ocg-order-all
This commit is contained in:
parent
c87ce65f51
commit
7b8032a662
19
cpdf.ml
19
cpdf.ml
|
@ -4326,3 +4326,22 @@ let ocg_rename f t pdf =
|
||||||
| x -> x
|
| x -> x
|
||||||
)
|
)
|
||||||
pdf
|
pdf
|
||||||
|
|
||||||
|
let ocg_order_all pdf =
|
||||||
|
match Pdf.lookup_direct pdf "/OCProperties" (Pdf.catalog_of_pdf pdf) with
|
||||||
|
None -> ()
|
||||||
|
| Some ocpdict ->
|
||||||
|
match Pdf.lookup_direct pdf "/OCGs" ocpdict with
|
||||||
|
Some (Pdf.Array elts) ->
|
||||||
|
begin match Pdf.lookup_direct pdf "/D" ocpdict with
|
||||||
|
Some (Pdf.Dictionary d) ->
|
||||||
|
let newd = Pdf.add_dict_entry (Pdf.Dictionary d) "/Order" (Pdf.Array elts) in
|
||||||
|
let new_ocproperties = Pdf.add_dict_entry ocpdict "/D" newd in
|
||||||
|
let ocp_objnum = Pdf.addobj pdf new_ocproperties in
|
||||||
|
let new_catalog = Pdf.addobj pdf (Pdf.add_dict_entry (Pdf.catalog_of_pdf pdf) "/OCProperties" (Pdf.Indirect ocp_objnum)) in
|
||||||
|
pdf.Pdf.trailerdict <- Pdf.add_dict_entry pdf.Pdf.trailerdict "/Root" (Pdf.Indirect new_catalog);
|
||||||
|
pdf.Pdf.root <- new_catalog
|
||||||
|
| _ -> ()
|
||||||
|
end
|
||||||
|
| _ -> ()
|
||||||
|
|
||||||
|
|
2
cpdf.mli
2
cpdf.mli
|
@ -456,3 +456,5 @@ val ocg_list : Pdf.t -> unit
|
||||||
|
|
||||||
val ocg_rename : string -> string -> Pdf.t -> unit
|
val ocg_rename : string -> string -> Pdf.t -> unit
|
||||||
|
|
||||||
|
val ocg_order_all : Pdf.t -> unit
|
||||||
|
|
||||||
|
|
|
@ -193,6 +193,7 @@ type op =
|
||||||
| OCGCoalesce
|
| OCGCoalesce
|
||||||
| OCGList
|
| OCGList
|
||||||
| OCGRename
|
| OCGRename
|
||||||
|
| OCGOrderAll
|
||||||
|
|
||||||
let string_of_op = function
|
let string_of_op = function
|
||||||
| CopyFont _ -> "CopyFont"
|
| CopyFont _ -> "CopyFont"
|
||||||
|
@ -319,6 +320,7 @@ let string_of_op = function
|
||||||
| OCGCoalesce -> "OCGCoalesce"
|
| OCGCoalesce -> "OCGCoalesce"
|
||||||
| OCGList -> "OCGList"
|
| OCGList -> "OCGList"
|
||||||
| OCGRename -> "OCGRename"
|
| OCGRename -> "OCGRename"
|
||||||
|
| OCGOrderAll -> "OCGOrderAll"
|
||||||
|
|
||||||
(* Inputs: filename, pagespec. *)
|
(* Inputs: filename, pagespec. *)
|
||||||
type input_kind =
|
type input_kind =
|
||||||
|
@ -695,7 +697,7 @@ let banned banlist = function
|
||||||
| SetModify _|SetCreator _|SetProducer _|RemoveDictEntry _ | SetMetadata _
|
| SetModify _|SetCreator _|SetProducer _|RemoveDictEntry _ | SetMetadata _
|
||||||
| ExtractText | ExtractImages | ExtractFontFile
|
| ExtractText | ExtractImages | ExtractFontFile
|
||||||
| AddPageLabels | RemovePageLabels | OutputJSON | OCGCoalesce
|
| AddPageLabels | RemovePageLabels | OutputJSON | OCGCoalesce
|
||||||
| OCGRename | OCGList
|
| OCGRename | OCGList | OCGOrderAll
|
||||||
-> false (* Always allowed *)
|
-> false (* Always allowed *)
|
||||||
(* Combine pages is not allowed because we would not know where to get the
|
(* Combine pages is not allowed because we would not know where to get the
|
||||||
-recrypt from -- the first or second file? *)
|
-recrypt from -- the first or second file? *)
|
||||||
|
@ -2123,6 +2125,7 @@ and specs =
|
||||||
("-ocg-rename", Arg.Unit (setop OCGRename), "");
|
("-ocg-rename", Arg.Unit (setop OCGRename), "");
|
||||||
("-ocg-rename-from", Arg.String setocgrenamefrom, "");
|
("-ocg-rename-from", Arg.String setocgrenamefrom, "");
|
||||||
("-ocg-rename-to", Arg.String setocgrenameto, "");
|
("-ocg-rename-to", Arg.String setocgrenameto, "");
|
||||||
|
("-ocg-order-all", Arg.Unit (setop OCGOrderAll), "");
|
||||||
(* These items are undocumented *)
|
(* These items are undocumented *)
|
||||||
("-remove-unused-resources", Arg.Unit (setop RemoveUnusedResources), "");
|
("-remove-unused-resources", Arg.Unit (setop RemoveUnusedResources), "");
|
||||||
("-stay-on-error", Arg.Unit setstayonerror, "");
|
("-stay-on-error", Arg.Unit setstayonerror, "");
|
||||||
|
@ -4484,6 +4487,10 @@ let go () =
|
||||||
let pdf = get_single_pdf args.op false in
|
let pdf = get_single_pdf args.op false in
|
||||||
Cpdf.ocg_rename args.ocgrenamefrom args.ocgrenameto pdf;
|
Cpdf.ocg_rename args.ocgrenamefrom args.ocgrenameto pdf;
|
||||||
write_pdf false pdf
|
write_pdf false pdf
|
||||||
|
| Some OCGOrderAll ->
|
||||||
|
let pdf = get_single_pdf args.op false in
|
||||||
|
Cpdf.ocg_order_all pdf;
|
||||||
|
write_pdf false pdf
|
||||||
|
|
||||||
let parse_argv () =
|
let parse_argv () =
|
||||||
if args.debug then
|
if args.debug then
|
||||||
|
|
Loading…
Reference in New Issue