mirror of
https://github.com/johnwhitington/cpdf-source.git
synced 2025-04-15 18:57:31 +02:00
more
This commit is contained in:
parent
974025f7ac
commit
83d484a15c
@ -192,17 +192,7 @@ let output_json_marks ch calculate_page_number pdf fastrefnums marks =
|
|||||||
let json = `List (map json_of_mark marks) in
|
let json = `List (map json_of_mark marks) in
|
||||||
J.pretty_to_channel ch json
|
J.pretty_to_channel ch json
|
||||||
|
|
||||||
(* List the bookmarks in the given range to the given output *)
|
let process_string encoding s =
|
||||||
let list_bookmarks ~json encoding range pdf output =
|
|
||||||
let process_stripped escaped =
|
|
||||||
let b = Buffer.create 200 in
|
|
||||||
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 rec replace c x y = function
|
let rec replace c x y = function
|
||||||
| [] -> []
|
| [] -> []
|
||||||
| h::t when h = c -> x::y::replace c x y t
|
| h::t when h = c -> x::y::replace c x y t
|
||||||
@ -216,12 +206,22 @@ let list_bookmarks ~json encoding range pdf output =
|
|||||||
and n = int_of_char 'n'
|
and n = int_of_char 'n'
|
||||||
and q = int_of_char '\"' in
|
and q = int_of_char '\"' in
|
||||||
replace q bs q (replace nl bs n (replace bs bs bs codepoints))
|
replace q bs q (replace nl bs n (replace bs bs bs codepoints))
|
||||||
|
in
|
||||||
|
let process_stripped escaped =
|
||||||
|
let b = Buffer.create 200 in
|
||||||
|
iter
|
||||||
|
(fun x ->
|
||||||
|
if x <= 127 then Buffer.add_char b (char_of_int x))
|
||||||
|
escaped;
|
||||||
|
Buffer.contents b
|
||||||
in
|
in
|
||||||
match encoding with
|
match encoding with
|
||||||
| Cpdfmetadata.UTF8 -> Pdftext.utf8_of_codepoints escaped
|
| Cpdfmetadata.UTF8 -> Pdftext.utf8_of_codepoints escaped
|
||||||
| Cpdfmetadata.Stripped -> process_stripped escaped
|
| Cpdfmetadata.Stripped -> process_stripped escaped
|
||||||
| Cpdfmetadata.Raw -> s
|
| Cpdfmetadata.Raw -> s
|
||||||
in
|
|
||||||
|
(* List the bookmarks in the given range to the given output *)
|
||||||
|
let list_bookmarks ~json encoding range pdf output =
|
||||||
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 rangetable = hashset_of_list range in
|
let rangetable = hashset_of_list range in
|
||||||
@ -256,7 +256,7 @@ let list_bookmarks ~json encoding range pdf output =
|
|||||||
output.Pdfio.output_string
|
output.Pdfio.output_string
|
||||||
(Printf.sprintf "%i \"%s\" %i%s %s\n"
|
(Printf.sprintf "%i \"%s\" %i%s %s\n"
|
||||||
mark.Pdfmarks.level
|
mark.Pdfmarks.level
|
||||||
(process_string mark.Pdfmarks.text)
|
(process_string encoding mark.Pdfmarks.text)
|
||||||
(calculate_page_number mark)
|
(calculate_page_number mark)
|
||||||
(if mark.Pdfmarks.isopen then " open" else "")
|
(if mark.Pdfmarks.isopen then " open" else "")
|
||||||
(output_string_of_target pdf fastrefnums mark.Pdfmarks.target)))
|
(output_string_of_target pdf fastrefnums mark.Pdfmarks.target)))
|
||||||
|
BIN
cpdfmanual.pdf
BIN
cpdfmanual.pdf
Binary file not shown.
@ -1562,6 +1562,9 @@ There are two options which turn off parts of the squeezer. They are \texttt{-sq
|
|||||||
\begin{framed}
|
\begin{framed}
|
||||||
\small\noindent\verb!cpdf -list-bookmarks [-utf8 | -raw] in.pdf!
|
\small\noindent\verb!cpdf -list-bookmarks [-utf8 | -raw] in.pdf!
|
||||||
|
|
||||||
|
\vspace{1.5mm}
|
||||||
|
\small\noindent\verb!cpdf -list-bookmarks-json in.pdf!
|
||||||
|
|
||||||
\vspace{1.5mm}
|
\vspace{1.5mm}
|
||||||
\small\noindent\verb!cpdf -remove-bookmarks in.pdf -o out.pdf!
|
\small\noindent\verb!cpdf -remove-bookmarks in.pdf -o out.pdf!
|
||||||
|
|
||||||
@ -1608,6 +1611,24 @@ the ASCII range. To prevent this, and return unicode UTF8 output, add the
|
|||||||
\texttt{-utf8} option to the command. To prevent any processing, use the
|
\texttt{-utf8} option to the command. To prevent any processing, use the
|
||||||
\texttt{-raw} option. See Section \ref{textencodings} for more information. A newline in a bookmark is represented as \texttt{"\textbackslash n"}.
|
\texttt{-raw} option. See Section \ref{textencodings} for more information. A newline in a bookmark is represented as \texttt{"\textbackslash n"}.
|
||||||
|
|
||||||
|
By using \texttt{-list-bookmarks-json} instead, the bookmarks are formatted as a JSON array, in order, of dictionaries formatted thus:
|
||||||
|
|
||||||
|
\begin{verbatim}
|
||||||
|
{ "level": 0,
|
||||||
|
"text": "1 Basic Usage",
|
||||||
|
"page": 17,
|
||||||
|
"open": false,
|
||||||
|
"target":
|
||||||
|
[ { "I": 17 },
|
||||||
|
{ "N": "/XYZ" },
|
||||||
|
{ "F": 85.039 },
|
||||||
|
{ "F": 609.307 },
|
||||||
|
null ]
|
||||||
|
}
|
||||||
|
\end{verbatim}
|
||||||
|
|
||||||
|
See chapter 15 for more details of cpdf's JSON formatting. Bookmark text in JSON bookmarks, however, is in UTF8 for ease of use.
|
||||||
|
|
||||||
\subsection{Destinations}
|
\subsection{Destinations}
|
||||||
|
|
||||||
The destination is an extended description of where the bookmark should point to (i.e it can be more detailed than just giving the page). For example, it may point to a section heading halfway down a page. Here are the possibilities:
|
The destination is an extended description of where the bookmark should point to (i.e it can be more detailed than just giving the page). For example, it may point to a section heading halfway down a page. Here are the possibilities:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user