Allow page specifications for -open-at-page-{fit}

This commit is contained in:
John Whitington 2020-05-04 12:25:42 +01:00
parent 0a77fcfe3e
commit a239cf4edb
1 changed files with 16 additions and 10 deletions

View File

@ -170,8 +170,8 @@ type op =
| RemoveUnusedResources | RemoveUnusedResources
| ExtractFontFile | ExtractFontFile
| ExtractText | ExtractText
| OpenAtPage of int | OpenAtPage of string
| OpenAtPageFit of int | OpenAtPageFit of string
| AddPageLabels | AddPageLabels
| RemovePageLabels | RemovePageLabels
| PrintPageLabels | PrintPageLabels
@ -1953,10 +1953,10 @@ and specs =
Arg.String setpagemode, Arg.String setpagemode,
" Set page mode upon document opening"); " Set page mode upon document opening");
("-open-at-page", ("-open-at-page",
Arg.Int setopenatpage, Arg.String setopenatpage,
" Set initial page"); " Set initial page");
("-open-at-page-fit", ("-open-at-page-fit",
Arg.Int setopenatpagefit, Arg.String setopenatpagefit,
" Set inital page, scaling to fit"); " Set inital page, scaling to fit");
("-set-metadata", ("-set-metadata",
Arg.String setmetadata, Arg.String setmetadata,
@ -4007,10 +4007,16 @@ let go () =
let version = if args.keepversion then pdf.Pdf.minor else version in let version = if args.keepversion then pdf.Pdf.minor else version in
write_pdf false (Cpdf.set_viewer_preference (key, value, version) pdf) write_pdf false (Cpdf.set_viewer_preference (key, value, version) pdf)
end end
| Some (OpenAtPage n) -> | Some (OpenAtPage str) ->
write_pdf false (Cpdf.set_open_action (get_single_pdf args.op false) false n) let pdf = get_single_pdf args.op false in
| Some (OpenAtPageFit n) -> let range = parse_pagespec pdf str in
write_pdf false (Cpdf.set_open_action (get_single_pdf args.op false) true n) let n = match range with [x] -> x | _ -> error "open_at_page: range does not specify single page" in
write_pdf false (Cpdf.set_open_action pdf false n)
| Some (OpenAtPageFit str) ->
let pdf = get_single_pdf args.op false in
let range = parse_pagespec pdf str in
let n = match range with [x] -> x | _ -> error "open_at_page: range does not specify single page" in
write_pdf false (Cpdf.set_open_action pdf true n)
| Some (SetMetadata metadata_file) -> | Some (SetMetadata metadata_file) ->
write_pdf false (Cpdf.set_metadata args.keepversion metadata_file (get_single_pdf args.op false)) write_pdf false (Cpdf.set_metadata args.keepversion metadata_file (get_single_pdf args.op false))
| Some (SetVersion v) -> | Some (SetVersion v) ->
@ -4022,9 +4028,9 @@ let go () =
in in
write_pdf false pdf write_pdf false pdf
| Some (SetPageLayout s) -> | Some (SetPageLayout s) ->
write_pdf false (Cpdf.set_page_layout (get_single_pdf args.op false) s) write_pdf false (Cpdf.set_page_layout (get_single_pdf args.op false) s)
| Some (SetPageMode s) -> | Some (SetPageMode s) ->
write_pdf false (Cpdf.set_page_mode (get_single_pdf args.op false) s) write_pdf false (Cpdf.set_page_mode (get_single_pdf args.op false) s)
| Some Split -> | Some Split ->
begin match args.inputs, args.out with begin match args.inputs, args.out with
| [(f, ranges, _, _, _, _)], File output_spec -> | [(f, ranges, _, _, _, _)], File output_spec ->