Beginning work on -set-metadata-date

This commit is contained in:
John Whitington 2019-06-29 15:03:22 +01:00
parent 872491f60e
commit 44fdb93574
3 changed files with 15 additions and 3 deletions

View File

@ -3399,6 +3399,9 @@ let set_pdf_info_xml_many only_when_present changes value xmldata pdf =
changes; changes;
!xmldata !xmldata
(* Set metadata date *)
let set_metadata_date pdf only_when_present date = pdf
(* \section{Set an entry in the /Info dictionary} *) (* \section{Set an entry in the /Info dictionary} *)
(* We must parse the date to get its components, then use strftime to build the (* We must parse the date to get its components, then use strftime to build the
@ -3429,10 +3432,11 @@ let default_date () =
(* XMP date format is YYYY-MM-DDThh:mm:ssTZD *) (* XMP date format is YYYY-MM-DDThh:mm:ssTZD *)
let make_xmp_date_from_components d = let make_xmp_date_from_components d =
let tzd = let tzd =
if d.ut_relationship = 0 && d.offset_hours = 0 && d.offset_minutes = 0 then "Z" else
(if d.ut_relationship >=0 then "+" else "-") ^ (if d.ut_relationship >=0 then "+" else "-") ^
Printf.sprintf "%2i" d.offset_hours ^ Printf.sprintf "%02i" d.offset_hours ^
":" ^ ":" ^
Printf.sprintf "%2i" d.offset_minutes Printf.sprintf "%02i" d.offset_minutes
in in
Cpdfstrftime.strftime Cpdfstrftime.strftime
~time:{Unix.tm_sec = d.second; ~time:{Unix.tm_sec = d.second;

View File

@ -195,6 +195,8 @@ val get_metadata : Pdf.t -> Pdfio.bytes option
(** Print metadate to stdout *) (** Print metadate to stdout *)
val print_metadata : Pdf.t -> unit val print_metadata : Pdf.t -> unit
val set_metadata_date : Pdf.t -> string -> bool -> Pdf.t
(** {2 Stamping} *) (** {2 Stamping} *)
(** [combine_pages fast under over scaletofit swap equalize] combines the page (** [combine_pages fast under over scaletofit swap equalize] combines the page

View File

@ -1589,6 +1589,9 @@ let setalsosetxmlwhenpresent () =
let setjustsetxml () = let setjustsetxml () =
args.justsetxml <- true args.justsetxml <- true
let setsetmetadatadate d =
args.op <- Some (SetMetadataDate d)
(* Parse a control file, make an argv, and then make Arg parse it. *) (* Parse a control file, make an argv, and then make Arg parse it. *)
let rec make_control_argv_and_parse filename = let rec make_control_argv_and_parse filename =
control_args := !control_args @ parse_control_file filename control_args := !control_args @ parse_control_file filename
@ -2039,6 +2042,9 @@ and specs =
("-remove-metadata", ("-remove-metadata",
Arg.Unit (setop RemoveMetadata), Arg.Unit (setop RemoveMetadata),
" Remove document metadata"); " Remove document metadata");
("-set-metadata-date",
Arg.String setsetmetadatadate,
" Set the XMP metadata date property");
("-hide-toolbar", ("-hide-toolbar",
Arg.String hidetoolbar, Arg.String hidetoolbar,
" Hide the viewer's toolbar"); " Hide the viewer's toolbar");
@ -3698,7 +3704,7 @@ let go () =
~xmp_just_set:args.justsetxml ~xmp_just_set:args.justsetxml
(key, value, version) pdf) (key, value, version) pdf)
| Some (SetMetadataDate date) -> | Some (SetMetadataDate date) ->
failwith "SetMetadataDate unimplemented" write_pdf false (Cpdf.set_metadata_date (get_single_pdf args.op false) date args.alsosetxmlwhenpresent)
| Some ((HideToolbar _ | HideMenubar _ | HideWindowUI _ | Some ((HideToolbar _ | HideMenubar _ | HideWindowUI _
| FitWindow _ | CenterWindow _ | DisplayDocTitle _) as op) -> | FitWindow _ | CenterWindow _ | DisplayDocTitle _) as op) ->
begin match args.out with begin match args.out with