This commit is contained in:
John Whitington 2023-04-17 19:55:11 +01:00
parent 3cb5e13a90
commit a4c06ee03a
4 changed files with 40 additions and 2 deletions

View File

@ -171,6 +171,7 @@ type op =
| ListBookmarks | ListBookmarks
| SetPageLayout of string | SetPageLayout of string
| SetPageMode of string | SetPageMode of string
| SetNonFullScreenPageMode of string
| HideToolbar of bool | HideToolbar of bool
| HideMenubar of bool | HideMenubar of bool
| HideWindowUI of bool | HideWindowUI of bool
@ -297,6 +298,7 @@ let string_of_op = function
| ListBookmarks -> "ListBookmarks" | ListBookmarks -> "ListBookmarks"
| SetPageLayout _ -> "SetPageLayout" | SetPageLayout _ -> "SetPageLayout"
| SetPageMode _ -> "SetPageMode" | SetPageMode _ -> "SetPageMode"
| SetNonFullScreenPageMode _ -> "SetNonFullScreenPageMode"
| HideToolbar _ -> "HideToolbar" | HideToolbar _ -> "HideToolbar"
| HideMenubar _ -> "HideMenubar" | HideMenubar _ -> "HideMenubar"
| HideWindowUI _ -> "HideWindowUI" | HideWindowUI _ -> "HideWindowUI"
@ -818,7 +820,7 @@ let banned banlist = function
| PrintPageLabels | Clean | Compress | Decompress | PrintPageLabels | Clean | Compress | Decompress
| ChangeId | CopyId _ | ListSpotColours | Version | ChangeId | CopyId _ | ListSpotColours | Version
| DumpAttachedFiles | RemoveMetadata | EmbedMissingFonts | BookmarksOpenToLevel _ | CreatePDF | DumpAttachedFiles | RemoveMetadata | EmbedMissingFonts | BookmarksOpenToLevel _ | CreatePDF
| SetPageMode _ | HideToolbar _ | HideMenubar _ | HideWindowUI _ | SetPageMode _ | SetNonFullScreenPageMode _ | HideToolbar _ | HideMenubar _ | HideWindowUI _
| FitWindow _ | CenterWindow _ | DisplayDocTitle _ | FitWindow _ | CenterWindow _ | DisplayDocTitle _
| RemoveId | OpenAtPageFit _ | OpenAtPage _ | SetPageLayout _ | RemoveId | OpenAtPageFit _ | OpenAtPage _ | SetPageLayout _
| ShowBoxes | TrimMarks | CreateMetadata | SetMetadataDate _ | SetVersion _ | ShowBoxes | TrimMarks | CreateMetadata | SetMetadataDate _ | SetVersion _
@ -1039,6 +1041,7 @@ let setmetadata s = setop (SetMetadata s) ()
let setversion i = setop (SetVersion i) () let setversion i = setop (SetVersion i) ()
let setpagelayout s = setop (SetPageLayout s) () let setpagelayout s = setop (SetPageLayout s) ()
let setpagemode s = setop (SetPageMode s) () let setpagemode s = setop (SetPageMode s) ()
let setnonfullscreenpagemode s = setop (SetNonFullScreenPageMode s) ()
let hidetoolbar b = let hidetoolbar b =
try setop (HideToolbar (bool_of_string b)) () with try setop (HideToolbar (bool_of_string b)) () with
@ -2552,6 +2555,9 @@ and specs =
("-set-page-mode", ("-set-page-mode",
Arg.String setpagemode, Arg.String setpagemode,
" Set page mode upon document opening"); " Set page mode upon document opening");
("-set-non-full-page-mode",
Arg.String setnonfullscreenpagemode,
" Set non full screen page mode if page mode is FullScreen");
("-open-at-page", ("-open-at-page",
Arg.String setopenatpage, Arg.String setopenatpage,
" Set initial page"); " Set initial page");
@ -3832,6 +3838,8 @@ let go () =
write_pdf false (Cpdfmetadata.set_page_layout (get_single_pdf args.op false) s) write_pdf false (Cpdfmetadata.set_page_layout (get_single_pdf args.op false) s)
| Some (SetPageMode s) -> | Some (SetPageMode s) ->
write_pdf false (Cpdfmetadata.set_page_mode (get_single_pdf args.op false) s) write_pdf false (Cpdfmetadata.set_page_mode (get_single_pdf args.op false) s)
| Some (SetNonFullScreenPageMode s) ->
write_pdf false (Cpdfmetadata.set_non_full_screen_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 ->

View File

@ -11,6 +11,7 @@
%Document extensions to -info %Document extensions to -info
%Document Topleft2 etc. %Document Topleft2 etc.
%Test new camlpdf unit conversions %Test new camlpdf unit conversions
%Document -non-full-screen-page-mode
\documentclass{book} \documentclass{book}
% Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf, % Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf,
% dotnetcpdflibmanual.pdf, jcpdflibmanual.pdf jscpdflibmanual.pdf etc. % dotnetcpdflibmanual.pdf, jcpdflibmanual.pdf jscpdflibmanual.pdf etc.

View File

@ -655,6 +655,32 @@ let set_page_mode pdf s =
end end
| _ -> error "Unknown page mode" | _ -> error "Unknown page mode"
let set_non_full_screen_page_mode pdf s =
match s with
| "UseNone" | "UseOutlines" | "UseThumbs"
| "UseOC" | "UseAttachments" ->
begin match Pdf.lookup_direct pdf "/Root" pdf.Pdf.trailerdict with
| Some catalog ->
let viewerprefs =
match Pdf.lookup_direct pdf "/ViewerPreferences" catalog with
| Some d -> d
| None -> Pdf.Dictionary []
in
let viewerprefsnum =
Pdf.addobj pdf (Pdf.add_dict_entry viewerprefs "/NonFullScreenPageMode" (Pdf.Name ("/" ^ s)))
in
let catalog' = Pdf.add_dict_entry catalog "/ViewerPreferences" (Pdf.Indirect viewerprefsnum)in
let catalognum = Pdf.addobj pdf catalog' in
let trailerdict' =
Pdf.add_dict_entry pdf.Pdf.trailerdict "/Root" (Pdf.Indirect catalognum)
in
{pdf with
Pdf.root = catalognum;
Pdf.trailerdict = trailerdict'}
| None -> error "bad root"
end
| _ -> error "Unknown non full screen page mode"
(* Set open action *) (* Set open action *)
let set_open_action pdf fit pagenumber = let set_open_action pdf fit pagenumber =
if pagenumber > Pdfpage.endpage pdf || pagenumber < 0 then if pagenumber > Pdfpage.endpage pdf || pagenumber < 0 then

View File

@ -32,9 +32,12 @@ val set_viewer_preference : (string * Pdf.pdfobject * int) -> Pdf.t -> Pdf.t
(** Set the page layout to the given name (sans slash) e.g SinglePage *) (** Set the page layout to the given name (sans slash) e.g SinglePage *)
val set_page_layout : Pdf.t -> string -> Pdf.t val set_page_layout : Pdf.t -> string -> Pdf.t
(** Set the page layout to the given name (sans slash) e.g SinglePage *) (** Set the page mode to the given name (sans slash) e.g UseThumbs *)
val set_page_mode : Pdf.t -> string -> Pdf.t val set_page_mode : Pdf.t -> string -> Pdf.t
(** Set the non full screen page mode to the given name (sans slash) e.g UseThumbs *)
val set_non_full_screen_page_mode : Pdf.t -> string -> Pdf.t
(** Set the open action. If the boolean is true, /Fit will be used, otherwise /XYZ *) (** Set the open action. If the boolean is true, /Fit will be used, otherwise /XYZ *)
val set_open_action : Pdf.t -> bool -> int -> Pdf.t val set_open_action : Pdf.t -> bool -> int -> Pdf.t