Added -ocg-order-all

This commit is contained in:
John Whitington 2020-03-02 13:37:39 +01:00
parent c87ce65f51
commit 7b8032a662
3 changed files with 29 additions and 1 deletions

19
cpdf.ml
View File

@ -4326,3 +4326,22 @@ let ocg_rename f t pdf =
| x -> x
)
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
| _ -> ()

View File

@ -456,3 +456,5 @@ val ocg_list : Pdf.t -> unit
val ocg_rename : string -> string -> Pdf.t -> unit
val ocg_order_all : Pdf.t -> unit

View File

@ -193,6 +193,7 @@ type op =
| OCGCoalesce
| OCGList
| OCGRename
| OCGOrderAll
let string_of_op = function
| CopyFont _ -> "CopyFont"
@ -319,6 +320,7 @@ let string_of_op = function
| OCGCoalesce -> "OCGCoalesce"
| OCGList -> "OCGList"
| OCGRename -> "OCGRename"
| OCGOrderAll -> "OCGOrderAll"
(* Inputs: filename, pagespec. *)
type input_kind =
@ -695,7 +697,7 @@ let banned banlist = function
| SetModify _|SetCreator _|SetProducer _|RemoveDictEntry _ | SetMetadata _
| ExtractText | ExtractImages | ExtractFontFile
| AddPageLabels | RemovePageLabels | OutputJSON | OCGCoalesce
| OCGRename | OCGList
| OCGRename | OCGList | OCGOrderAll
-> false (* Always allowed *)
(* Combine pages is not allowed because we would not know where to get the
-recrypt from -- the first or second file? *)
@ -2123,6 +2125,7 @@ and specs =
("-ocg-rename", Arg.Unit (setop OCGRename), "");
("-ocg-rename-from", Arg.String setocgrenamefrom, "");
("-ocg-rename-to", Arg.String setocgrenameto, "");
("-ocg-order-all", Arg.Unit (setop OCGOrderAll), "");
(* These items are undocumented *)
("-remove-unused-resources", Arg.Unit (setop RemoveUnusedResources), "");
("-stay-on-error", Arg.Unit setstayonerror, "");
@ -4484,6 +4487,10 @@ let go () =
let pdf = get_single_pdf args.op false in
Cpdf.ocg_rename args.ocgrenamefrom args.ocgrenameto 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 () =
if args.debug then