diff --git a/cpdf.ml b/cpdf.ml index 4b62539..964dfa1 100644 --- a/cpdf.ml +++ b/cpdf.ml @@ -3399,6 +3399,9 @@ let set_pdf_info_xml_many only_when_present changes value xmldata pdf = changes; !xmldata +(* Set metadata date *) +let set_metadata_date pdf only_when_present date = pdf + (* \section{Set an entry in the /Info dictionary} *) (* 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 *) let make_xmp_date_from_components d = 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 "-") ^ - 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 Cpdfstrftime.strftime ~time:{Unix.tm_sec = d.second; diff --git a/cpdf.mli b/cpdf.mli index df53565..0b88bd9 100644 --- a/cpdf.mli +++ b/cpdf.mli @@ -195,6 +195,8 @@ val get_metadata : Pdf.t -> Pdfio.bytes option (** Print metadate to stdout *) val print_metadata : Pdf.t -> unit +val set_metadata_date : Pdf.t -> string -> bool -> Pdf.t + (** {2 Stamping} *) (** [combine_pages fast under over scaletofit swap equalize] combines the page diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 0585447..e43885c 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -1589,6 +1589,9 @@ let setalsosetxmlwhenpresent () = let setjustsetxml () = args.justsetxml <- true +let setsetmetadatadate d = + args.op <- Some (SetMetadataDate d) + (* Parse a control file, make an argv, and then make Arg parse it. *) let rec make_control_argv_and_parse filename = control_args := !control_args @ parse_control_file filename @@ -2039,6 +2042,9 @@ and specs = ("-remove-metadata", Arg.Unit (setop RemoveMetadata), " Remove document metadata"); + ("-set-metadata-date", + Arg.String setsetmetadatadate, + " Set the XMP metadata date property"); ("-hide-toolbar", Arg.String hidetoolbar, " Hide the viewer's toolbar"); @@ -3698,7 +3704,7 @@ let go () = ~xmp_just_set:args.justsetxml (key, value, version) pdf) | 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 _ | FitWindow _ | CenterWindow _ | DisplayDocTitle _) as op) -> begin match args.out with