more
This commit is contained in:
parent
d7ab57a22d
commit
c711e3aa77
34
cpdf.ml
34
cpdf.ml
|
@ -1965,38 +1965,6 @@ let remove_unused_resources_page pdf n page =
|
||||||
let remove_unused_resources pdf =
|
let remove_unused_resources pdf =
|
||||||
Cpdfpage.process_pages (ppstub (remove_unused_resources_page pdf)) pdf (ilist 1 (Pdfpage.endpage pdf))
|
Cpdfpage.process_pages (ppstub (remove_unused_resources_page pdf)) pdf (ilist 1 (Pdfpage.endpage pdf))
|
||||||
|
|
||||||
(* Indent bookmarks in each file by one and add a title bookmark pointing to the first page. *)
|
|
||||||
let add_bookmark_title filename use_title pdf =
|
|
||||||
let title =
|
|
||||||
if use_title then
|
|
||||||
match Cpdfmetadata.get_info_utf8 pdf "/Title", Cpdfmetadata.get_xmp_info pdf "/Title" with
|
|
||||||
"", x | x, "" | _, x -> x
|
|
||||||
else
|
|
||||||
Filename.basename filename
|
|
||||||
in
|
|
||||||
let marks = Pdfmarks.read_bookmarks pdf in
|
|
||||||
let page1objnum =
|
|
||||||
match Pdfpage.page_object_number pdf 1 with
|
|
||||||
None -> error "add_bookmark_title: page not found"
|
|
||||||
| Some x -> x
|
|
||||||
in
|
|
||||||
let newmarks =
|
|
||||||
{Pdfmarks.level = 0;
|
|
||||||
Pdfmarks.text = title;
|
|
||||||
Pdfmarks.target = Pdfdest.XYZ (Pdfdest.PageObject page1objnum, None, None, None);
|
|
||||||
Pdfmarks.isopen = false}
|
|
||||||
::map (function m -> {m with Pdfmarks.level = m.Pdfmarks.level + 1}) marks
|
|
||||||
in
|
|
||||||
Pdfmarks.add_bookmarks newmarks pdf
|
|
||||||
|
|
||||||
let bookmarks_open_to_level n pdf =
|
|
||||||
let marks = Pdfmarks.read_bookmarks pdf in
|
|
||||||
let newmarks =
|
|
||||||
map
|
|
||||||
(fun m -> {m with Pdfmarks.isopen = m.Pdfmarks.level < n})
|
|
||||||
marks
|
|
||||||
in
|
|
||||||
Pdfmarks.add_bookmarks newmarks pdf
|
|
||||||
|
|
||||||
let create_pdf pages pagesize =
|
let create_pdf pages pagesize =
|
||||||
let page =
|
let page =
|
||||||
|
@ -2006,5 +1974,3 @@ let create_pdf pages pagesize =
|
||||||
in
|
in
|
||||||
let pdf, pageroot = Pdfpage.add_pagetree (many page pages) (Pdf.empty ()) in
|
let pdf, pageroot = Pdfpage.add_pagetree (many page pages) (Pdf.empty ()) in
|
||||||
Pdfpage.add_root pageroot [] pdf
|
Pdfpage.add_root pageroot [] pdf
|
||||||
|
|
||||||
|
|
||||||
|
|
3
cpdf.mli
3
cpdf.mli
|
@ -138,10 +138,9 @@ val image_resolution : Pdf.t -> int list -> float -> (int * string * int * int *
|
||||||
|
|
||||||
val copy_box : string -> string -> bool -> Pdf.t -> int list -> Pdf.t
|
val copy_box : string -> string -> bool -> Pdf.t -> int list -> Pdf.t
|
||||||
|
|
||||||
val add_bookmark_title : string -> bool -> Pdf.t -> Pdf.t
|
|
||||||
|
|
||||||
val remove_unused_resources : Pdf.t -> Pdf.t
|
val remove_unused_resources : Pdf.t -> Pdf.t
|
||||||
|
|
||||||
val bookmarks_open_to_level : int -> Pdf.t -> Pdf.t
|
|
||||||
|
|
||||||
val create_pdf : int -> Pdfpaper.t -> Pdf.t
|
val create_pdf : int -> Pdfpaper.t -> Pdf.t
|
||||||
|
|
|
@ -359,3 +359,37 @@ let name_of_spec encoding marks (pdf : Pdf.t) splitlevel spec n filename startpa
|
||||||
else
|
else
|
||||||
process_others encoding marks pdf splitlevel filename n startpage endpage
|
process_others encoding marks pdf splitlevel filename n startpage endpage
|
||||||
(implode before ^ fill (length percents) n ^ implode after)
|
(implode before ^ fill (length percents) n ^ implode after)
|
||||||
|
|
||||||
|
(* Indent bookmarks in each file by one and add a title bookmark pointing to the first page. *)
|
||||||
|
let add_bookmark_title filename use_title pdf =
|
||||||
|
let title =
|
||||||
|
if use_title then
|
||||||
|
match Cpdfmetadata.get_info_utf8 pdf "/Title", Cpdfmetadata.get_xmp_info pdf "/Title" with
|
||||||
|
"", x | x, "" | _, x -> x
|
||||||
|
else
|
||||||
|
Filename.basename filename
|
||||||
|
in
|
||||||
|
let marks = Pdfmarks.read_bookmarks pdf in
|
||||||
|
let page1objnum =
|
||||||
|
match Pdfpage.page_object_number pdf 1 with
|
||||||
|
None -> error "add_bookmark_title: page not found"
|
||||||
|
| Some x -> x
|
||||||
|
in
|
||||||
|
let newmarks =
|
||||||
|
{Pdfmarks.level = 0;
|
||||||
|
Pdfmarks.text = title;
|
||||||
|
Pdfmarks.target = Pdfdest.XYZ (Pdfdest.PageObject page1objnum, None, None, None);
|
||||||
|
Pdfmarks.isopen = false}
|
||||||
|
::map (function m -> {m with Pdfmarks.level = m.Pdfmarks.level + 1}) marks
|
||||||
|
in
|
||||||
|
Pdfmarks.add_bookmarks newmarks pdf
|
||||||
|
|
||||||
|
let bookmarks_open_to_level n pdf =
|
||||||
|
let marks = Pdfmarks.read_bookmarks pdf in
|
||||||
|
let newmarks =
|
||||||
|
map
|
||||||
|
(fun m -> {m with Pdfmarks.isopen = m.Pdfmarks.level < n})
|
||||||
|
marks
|
||||||
|
in
|
||||||
|
Pdfmarks.add_bookmarks newmarks pdf
|
||||||
|
|
||||||
|
|
|
@ -16,3 +16,6 @@ val list_bookmarks : json:bool -> Cpdfmetadata.encoding -> int list -> Pdf.t ->
|
||||||
val name_of_spec : Cpdfmetadata.encoding ->
|
val name_of_spec : Cpdfmetadata.encoding ->
|
||||||
Pdfmarks.t list ->
|
Pdfmarks.t list ->
|
||||||
Pdf.t -> int -> string -> int -> string -> int -> int -> string
|
Pdf.t -> int -> string -> int -> string -> int -> int -> string
|
||||||
|
|
||||||
|
val add_bookmark_title : string -> bool -> Pdf.t -> Pdf.t
|
||||||
|
val bookmarks_open_to_level : int -> Pdf.t -> Pdf.t
|
||||||
|
|
|
@ -3038,7 +3038,7 @@ let go () =
|
||||||
let pdfs =
|
let pdfs =
|
||||||
if args.merge_add_bookmarks then
|
if args.merge_add_bookmarks then
|
||||||
map2
|
map2
|
||||||
(fun filename pdf -> Cpdf.add_bookmark_title filename args.merge_add_bookmarks_use_titles pdf)
|
(fun filename pdf -> Cpdfbookmarks.add_bookmark_title filename args.merge_add_bookmarks_use_titles pdf)
|
||||||
(map (function InFile s -> s | StdIn -> "" | AlreadyInMemory _ -> "") names)
|
(map (function InFile s -> s | StdIn -> "" | AlreadyInMemory _ -> "") names)
|
||||||
pdfs
|
pdfs
|
||||||
else
|
else
|
||||||
|
@ -3852,7 +3852,7 @@ let go () =
|
||||||
Cpdffont.embed_missing_fonts args.path_to_ghostscript args.gs_quiet fi fo
|
Cpdffont.embed_missing_fonts args.path_to_ghostscript args.gs_quiet fi fo
|
||||||
| Some (BookmarksOpenToLevel n) ->
|
| Some (BookmarksOpenToLevel n) ->
|
||||||
let pdf = get_single_pdf args.op false in
|
let pdf = get_single_pdf args.op false in
|
||||||
write_pdf false (Cpdf.bookmarks_open_to_level n pdf)
|
write_pdf false (Cpdfbookmarks.bookmarks_open_to_level n pdf)
|
||||||
| Some CreatePDF ->
|
| Some CreatePDF ->
|
||||||
let pdf = Cpdf.create_pdf args.createpdf_pages args.createpdf_pagesize in
|
let pdf = Cpdf.create_pdf args.createpdf_pages args.createpdf_pagesize in
|
||||||
write_pdf false pdf
|
write_pdf false pdf
|
||||||
|
|
Loading…
Reference in New Issue