diff --git a/cpdfbookmarks.ml b/cpdfbookmarks.ml index 1d6cef8..9039775 100644 --- a/cpdfbookmarks.ml +++ b/cpdfbookmarks.ml @@ -262,7 +262,10 @@ let list_bookmarks ~json encoding range pdf output = (output_string_of_target pdf fastrefnums mark.Pdfmarks.target))) inrange -(* o is the stamp, u is the main pdf page *) +let get_bookmarks_json pdf = + let o, br = Pdfio.input_output_of_bytes (20 * 1024) in + list_bookmarks ~json:true Cpdfmetadata.UTF8 (ilist 1 (Pdfpage.endpage pdf)) pdf o; + Pdfio.extract_bytes_from_input_output o br (* Split at bookmarks *) diff --git a/cpdfbookmarks.mli b/cpdfbookmarks.mli index 79723ba..ef77870 100644 --- a/cpdfbookmarks.mli +++ b/cpdfbookmarks.mli @@ -14,6 +14,9 @@ output in the format specified in cpdfmanual.pdf. In the new JSON format if chosen. *) val list_bookmarks : json:bool -> Cpdfmetadata.encoding -> int list -> Pdf.t -> Pdfio.output -> unit +(** Get bookmarks in JSON format. *) +val get_bookmarks_json : Pdf.t -> Pdfio.bytes + (** [name_of_spec encoding marks pdf splitlevel spec n filename startpage endpage] expands a bookmark specifiation filename. *) val name_of_spec : Cpdfmetadata.encoding ->