More bookmark efficiency

This commit is contained in:
John Whitington 2017-05-28 19:58:30 +01:00
parent 8e90da9c62
commit 88a40cb51f
1 changed files with 10 additions and 1 deletions

11
cpdf.ml
View File

@ -1169,6 +1169,14 @@ let remove_metadata pdf =
(* List the bookmarks, optionally deunicoding the text, in the given range to the given output *) (* List the bookmarks, optionally deunicoding the text, in the given range to the given output *)
let list_bookmarks encoding range pdf output = let list_bookmarks encoding range pdf output =
let process_stripped escaped =
let b = Buffer.create 200 in
List.iter
(fun x ->
if x <= 127 then Buffer.add_char b (char_of_int x))
escaped;
Buffer.contents b
in
let process_string s = let process_string s =
let rec replace c x y = function let rec replace c x y = function
| [] -> [] | [] -> []
@ -1186,12 +1194,13 @@ let list_bookmarks encoding range pdf output =
in in
match encoding with match encoding with
| UTF8 -> Pdftext.utf8_of_codepoints escaped | UTF8 -> Pdftext.utf8_of_codepoints escaped
| Stripped -> implode (map char_of_int (lose (fun x -> x > 127) escaped)) | Stripped -> process_stripped escaped
| Raw -> s | Raw -> s
in in
let bookmarks = Pdfmarks.read_bookmarks pdf in let bookmarks = Pdfmarks.read_bookmarks pdf in
let refnums = Pdf.page_reference_numbers pdf in let refnums = Pdf.page_reference_numbers pdf in
let inrange = let inrange =
(* n ^ 2 here too? *)
keep keep
(function x -> (function x ->
x.Pdfmarks.target = Pdfdest.NullDestination || x.Pdfmarks.target = Pdfdest.NullDestination ||