diff --git a/cpdf.ml b/cpdf.ml index f188eb5..21eb6e5 100644 --- a/cpdf.ml +++ b/cpdf.ml @@ -1094,23 +1094,27 @@ let list_font pdf page (name, dict) = in (page, name, subtype, basefont, encoding) -let list_fonts pdf = +let list_fonts pdf range = let pages = Pdfpage.pages_of_pagetree pdf in flatten (map (fun (num, page) -> - match Pdf.lookup_direct pdf "/Font" page.Pdfpage.resources with - | Some (Pdf.Dictionary fontdict) -> - map (list_font pdf num) fontdict - | _ -> []) + if mem num range then + begin match Pdf.lookup_direct pdf "/Font" page.Pdfpage.resources with + | Some (Pdf.Dictionary fontdict) -> + map (list_font pdf num) fontdict + | _ -> [] + end + else + []) (combine (ilist 1 (length pages)) pages)) let string_of_font (p, n, s, b, e) = Printf.sprintf "%i %s %s %s %s\n" p n s b e -let print_fonts pdf = +let print_fonts pdf range = flprint - (fold_left ( ^ ) "" (map string_of_font (list_fonts pdf))) + (fold_left ( ^ ) "" (map string_of_font (list_fonts pdf range))) (* \section{Superimpose text, page numbers etc.} *) diff --git a/cpdf.mli b/cpdf.mli index 71797d1..e73beae 100644 --- a/cpdf.mli +++ b/cpdf.mli @@ -149,10 +149,10 @@ val split_on_bookmarks : Pdf.t -> int -> Pdf.t list (** {2 Listing fonts} *) (** Print font list to stdout *) -val print_fonts : Pdf.t -> unit +val print_fonts : Pdf.t -> int list -> unit (** Return font list. Page number, name, subtype, basefont, encoding. *) -val list_fonts : Pdf.t -> (int * string * string * string * string) list +val list_fonts : Pdf.t -> int list -> (int * string * string * string * string) list (** {2 Adding text} *) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 83f69fa..d8c7cd1 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -3532,7 +3532,13 @@ let go () = | Some Metadata -> Cpdf.print_metadata (get_single_pdf (Some Metadata) true) | Some Fonts -> - Cpdf.print_fonts (get_single_pdf (Some Fonts) true) + begin match args.inputs, args.out with + | (_, pagespec, _, _, _, _)::_, _ -> + let pdf = get_single_pdf (Some Fonts) true in + let range = parse_pagespec_allow_empty pdf pagespec in + Cpdf.print_fonts pdf range + | _ -> error "-list-fonts: bad command line" + end | Some ListBookmarks -> begin match args.inputs, args.out with | (_, pagespec, _, _, _, _)::_, _ ->