Scaffolding for -mark-as

This commit is contained in:
John Whitington 2024-05-30 17:49:23 +01:00
parent 6735a824f3
commit eb121fee74
4 changed files with 21 additions and 1 deletions

View File

@ -220,6 +220,7 @@ type op =
| ExtractStream of int | ExtractStream of int
| PrintObj of int | PrintObj of int
| Verify of string | Verify of string
| MarkAs of string
let string_of_op = function let string_of_op = function
| PrintFontEncoding _ -> "PrintFontEncoding" | PrintFontEncoding _ -> "PrintFontEncoding"
@ -363,6 +364,7 @@ let string_of_op = function
| ExtractStream _ -> "ExtractStream" | ExtractStream _ -> "ExtractStream"
| PrintObj _ -> "PrintObj" | PrintObj _ -> "PrintObj"
| Verify _ -> "Verify" | Verify _ -> "Verify"
| MarkAs _ -> "MarkAs"
(* Inputs: filename, pagespec. *) (* Inputs: filename, pagespec. *)
type input_kind = type input_kind =
@ -883,7 +885,7 @@ let banned banlist = function
| AddPageLabels | RemovePageLabels | OutputJSON | OCGCoalesce | AddPageLabels | RemovePageLabels | OutputJSON | OCGCoalesce
| OCGRename | OCGList | OCGOrderAll | PrintFontEncoding _ | TableOfContents | Typeset _ | Composition _ | OCGRename | OCGList | OCGOrderAll | PrintFontEncoding _ | TableOfContents | Typeset _ | Composition _
| TextWidth _ | SetAnnotations _ | CopyAnnotations _ | ExtractStream _ | PrintObj _ | TextWidth _ | SetAnnotations _ | CopyAnnotations _ | ExtractStream _ | PrintObj _
| Verify _ | Verify _ | MarkAs _
-> 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? *)
@ -2807,6 +2809,7 @@ and specs =
("-obj", Arg.Int setprintobj, "Print object"); ("-obj", Arg.Int setprintobj, "Print object");
("-json", Arg.Unit (fun () -> args.format_json <- true), "Format output as JSON"); ("-json", Arg.Unit (fun () -> args.format_json <- true), "Format output as JSON");
("-verify", Arg.String (fun s -> setop (Verify s) ()), "Verify conformance to a standard"); ("-verify", Arg.String (fun s -> setop (Verify s) ()), "Verify conformance to a standard");
("-marks-as", Arg.String (fun s -> setop (MarkAs s) ()), "Mark as conforming to a standard");
(* These items are undocumented *) (* These items are undocumented *)
("-debug", Arg.Unit setdebug, ""); ("-debug", Arg.Unit setdebug, "");
("-debug-crypt", Arg.Unit (fun () -> args.debugcrypt <- true), ""); ("-debug-crypt", Arg.Unit (fun () -> args.debugcrypt <- true), "");
@ -4442,6 +4445,14 @@ let go () =
else Cpdfua.test_matterhorn_print pdf else Cpdfua.test_matterhorn_print pdf
| _ -> error "Unknown verification type." | _ -> error "Unknown verification type."
end end
| Some (MarkAs standard) ->
begin match standard with
| "PDF/UA-1" ->
let pdf = get_single_pdf args.op false in
Cpdfua.mark pdf;
write_pdf false pdf
| _ -> error "Unknown standard"
end
(* Advise the user if a combination of command line flags makes little sense, (* Advise the user if a combination of command line flags makes little sense,
or error out if it make no sense at all. *) or error out if it make no sense at all. *)

View File

@ -56,6 +56,11 @@ let xmp_template =
<?xpacket end='r'?>|} <?xpacket end='r'?>|}
let pdfua_marker =
{|<rdf:Description rdf:about="" xmlns:pdfuaid="http://www.aiim.org/pdfua/ns/id/">
<pdfuaid:part>1</pdfuaid:part>
</rdf:Description>"|}
(* Set or replace metadata *) (* Set or replace metadata *)
let set_metadata_from_bytes keepversion data pdf = let set_metadata_from_bytes keepversion data pdf =
let metadata_stream = let metadata_stream =

View File

@ -230,3 +230,5 @@ let test_matterhorn_json pdf =
(fun (name, error, section, extra) -> (fun (name, error, section, extra) ->
`Assoc [("name", `String name); ("section", `String section); ("error", `String error); ("extra", extra)]) `Assoc [("name", `String name); ("section", `String section); ("error", `String error); ("extra", extra)])
(test_matterhorn pdf)) (test_matterhorn pdf))
let mark pdf = ()

View File

@ -2,3 +2,5 @@
val test_matterhorn_print : Pdf.t -> unit val test_matterhorn_print : Pdf.t -> unit
val test_matterhorn_json : Pdf.t -> Cpdfyojson.Safe.t val test_matterhorn_json : Pdf.t -> Cpdfyojson.Safe.t
val mark : Pdf.t -> unit