more
This commit is contained in:
parent
37a11b5036
commit
9c5a905cc7
25
cpdfannot.ml
25
cpdfannot.ml
|
@ -30,6 +30,31 @@ let make_direct pdf annot =
|
|||
| None -> annot
|
||||
| Some d -> Pdf.add_dict_entry annot "/A" d
|
||||
|
||||
let rewrite_destination calculate_pagenumber d =
|
||||
match d with
|
||||
| Pdf.Array (Pdf.Indirect i::r) ->
|
||||
Pdf.Array (Pdf.Indirect (calculate_pagenumber (Pdfdest.Fit (Pdfdest.PageObject i)))::r)
|
||||
| x -> x
|
||||
|
||||
let rewrite_destinations pdf annot =
|
||||
let refnums = Pdf.page_reference_numbers pdf in
|
||||
let fastrefnums = hashtable_of_dictionary (combine refnums (indx refnums)) in
|
||||
let calculate_pagenumber = Pdfpage.pagenumber_of_target ~fastrefnums pdf in
|
||||
(* Deal with /Dest in annotation *)
|
||||
match Pdf.lookup_direct pdf "/Dest" annot with
|
||||
| Some d -> Pdf.add_dict_entry annot "/Dest" (rewrite_destination calculate_pagenumber d)
|
||||
| None ->
|
||||
(* Deal with /A --> /D dest when /A --> /S = /GoTo *)
|
||||
match Pdf.lookup_direct pdf "/A" annot with
|
||||
| Some action ->
|
||||
begin match Pdf.lookup_direct pdf "/D" action with
|
||||
| Some d ->
|
||||
Pdf.add_dict_entry
|
||||
annot "/A" (Pdf.add_dict_entry action "/D" (rewrite_destination calculate_pagenumber d))
|
||||
| None -> annot
|
||||
end
|
||||
| None -> annot
|
||||
|
||||
let annotations_json_page pdf page pagenum =
|
||||
match Pdf.lookup_direct pdf "/Annots" page.Pdfpage.rest with
|
||||
| Some (Pdf.Array annots) ->
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
open Pdfutil
|
||||
open Cpdferror
|
||||
|
||||
(* \section{Add bookmarks} *)
|
||||
(* Add bookmarks *)
|
||||
let read_lines input =
|
||||
let lines = ref [] in
|
||||
try
|
||||
|
@ -264,7 +264,7 @@ let list_bookmarks ~json encoding range pdf output =
|
|||
|
||||
(* o is the stamp, u is the main pdf page *)
|
||||
|
||||
(* \section{Split at bookmarks} *)
|
||||
(* Split at bookmarks *)
|
||||
|
||||
let get_bookmark_name pdf marks splitlevel n _ =
|
||||
let refnums = Pdf.page_reference_numbers pdf in
|
||||
|
@ -273,10 +273,6 @@ let get_bookmark_name pdf marks splitlevel n _ =
|
|||
| {Pdfmarks.text = title}::_ -> Cpdfattach.remove_unsafe_characters Cpdfmetadata.UTF8 title
|
||||
| _ -> ""
|
||||
|
||||
(* Find the stem of a filename *)
|
||||
(*let stem s =
|
||||
implode (rev (tail_no_fail (dropwhile (neq '.') (rev (explode (Filename.basename s))))))*)
|
||||
|
||||
(* Return list, in order, a *set* of page numbers of bookmarks at a given level *)
|
||||
let bookmark_pages level pdf =
|
||||
let refnums = Pdf.page_reference_numbers pdf in
|
||||
|
|
Loading…
Reference in New Issue