diff --git a/Changes b/Changes index 6fef52f..c36e1b5 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,8 @@ o New -center-to-fit centres pages on a given paper size o Allow bold, italic, colours for bookmarks +o Clean up @B implementation for -split-on-bookmarks +o Add @b for trimmed bookmarks 2.7.2 (October 2024) diff --git a/cpdfbookmarks.ml b/cpdfbookmarks.ml index eca9ee2..52c7a2a 100644 --- a/cpdfbookmarks.ml +++ b/cpdfbookmarks.ml @@ -143,7 +143,6 @@ let parse_bookmark_file verify pdf input = !currline (Printexc.to_string e)) - let add_bookmarks ~json verify input pdf = let parsed = (if json then parse_bookmark_file_json else parse_bookmark_file) verify pdf input in @@ -273,10 +272,10 @@ let get_bookmark_name encoding pdf marks splitlevel n _ = (* @S means start page of this section *) (* @E means end page of this section *) (* @B means bookmark name at start page *) -(* @b52| means bookmark name at start page truncated to 52 characters using crude UTF8 truncation. *) +(* @b52@ means bookmark name at start page truncated to 52 characters using crude UTF8 truncation. *) let process_others encoding marks pdf splitlevel filename sequence startpage endpage s = let trim_utf8 len l = - Printf.printf "trim_uff input $%S$\n" (implode l); + let l = try take l len with _ -> l in (* This truncator is far from perfect, but it does yield a valid UTF8 string, when given one. *) match rev l with | b2::b1::b0::t -> @@ -327,8 +326,9 @@ let process_others encoding marks pdf splitlevel filename sequence startpage end procss (rev (explode (get_bookmark_name encoding pdf marks splitlevel startpage pdf)) @ prev) t | '@'::'b'::t -> let number, rest = cleavewhile (function '0'..'9' -> true | _ -> false) t in + begin try ignore (int_of_string (implode number)) with _ -> error "Bad @b spec" end; let text = trim_utf8 (int_of_string (implode number)) (explode (get_bookmark_name encoding pdf marks splitlevel startpage pdf)) in - procss ((rev text) @ prev) (tl rest) + procss (rev text @ prev) (if rest = [] then [] else tl rest) | h::t -> procss (h::prev) t in implode (procss [] (explode s)) diff --git a/cpdfmanual.pdf b/cpdfmanual.pdf index 4ac18a6..7db6b3a 100644 Binary files a/cpdfmanual.pdf and b/cpdfmanual.pdf differ diff --git a/cpdfmanual.tex b/cpdfmanual.tex index 13a9b9a..47b9c8f 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -1304,6 +1304,7 @@ the result is unspecified. The following format operators may be used: \texttt{@S} & Start page of this chunk \\ \texttt{@E} & End page of this chunk \\ \texttt{@B} & Bookmark name at this page, if any. \\ + \texttt{@b@} & Bookmark name at this page, if any, truncated to \texttt{} characters.\\ \end{tabular} \end{center} @@ -1346,6 +1347,16 @@ one of the output files. \verb! / ? < > \ : * | " ^ + =! \end{framed} +\noindent The bookmark may be truncated by using the \texttt{@b} variant: + + \begin{framed}\small + \noindent\verb!cpdf -split-bookmarks 0 a.pdf -o @b10@.pdf! + + \vspace{2.5mm} + \noindent Split \texttt{a.pdf} on bookmark boundaries, using the first 10 characters of bookmark text as the filename. + + \end{framed} + \section{Splitting to Maximum Size} The \texttt{-split-max} operation splits a file into chunks of no more than the given size, starting at the beginning. The suffixes kB, KiB, MB, MiB, GB, and GiB may be used to give the size. For example: