From a8d8f447bf11c320fb2c1ddcfc89e40caf33d092 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Mon, 1 May 2023 16:19:09 +0100 Subject: [PATCH] more --- cpdfaddtext.ml | 46 +++++++++++++++++++++++----------------------- cpdfaddtext.mli | 11 +++++++++++ 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/cpdfaddtext.ml b/cpdfaddtext.ml index d822234..b0da4d3 100644 --- a/cpdfaddtext.ml +++ b/cpdfaddtext.ml @@ -213,33 +213,33 @@ let pagelabel pdf num = num (Pdfpagelabels.complete (Pdfpagelabels.read pdf)) +let replace_pairs pdf endpage extract_text_font_size filename bates batespad num page = + [ + "%PageDiv2", (fun () -> string_of_int ((num + 1) / 2)); + "%Page", (fun () -> string_of_int num); + "%Roman", (fun () -> roman_upper num); + "%roman", (fun () -> roman_lower num); + "%filename", (fun () -> filename); + "%Label", (fun () -> pagelabel pdf num); + "%EndPage", (fun () -> string_of_int endpage); + "%EndLabel", (fun () -> pagelabel pdf endpage); + "%ExtractedText", (fun () -> Cpdfextracttext.extract_page_text extract_text_font_size pdf num page); + "%Bates", + (fun () -> + (let numstring = string_of_int (bates + num - 1) in + match batespad with + None -> numstring + | Some w -> + if String.length numstring >= w + then numstring + else implode (many '0' (w - String.length numstring)) ^ numstring))] + let addtext time lines linewidth outline fast colour fontname encoding bates batespad fontsize font fontpdfobj underneath position hoffset voffset text pages cropbox opacity justification filename extract_text_font_size shift pdf = let endpage = Pdfpage.endpage pdf in - let replace_pairs pdf filename bates batespad num page = - [ - "%PageDiv2", (fun () -> string_of_int ((num + 1) / 2)); - "%Page", (fun () -> string_of_int num); - "%Roman", (fun () -> roman_upper num); - "%roman", (fun () -> roman_lower num); - "%filename", (fun () -> filename); - "%Label", (fun () -> pagelabel pdf num); - "%EndPage", (fun () -> string_of_int endpage); - "%EndLabel", (fun () -> pagelabel pdf endpage); - "%ExtractedText", (fun () -> Cpdfextracttext.extract_page_text extract_text_font_size pdf num page); - "%Bates", - (fun () -> - (let numstring = string_of_int (bates + num - 1) in - match batespad with - None -> numstring - | Some w -> - if String.length numstring >= w - then numstring - else implode (many '0' (w - String.length numstring)) ^ numstring))] - in let shifts = Cpdfcoord.parse_coordinates pdf shift in let addtext_page num page = let shift_x, shift_y = List.nth shifts (num - 1) in @@ -298,13 +298,13 @@ let addtext in let unique_fontname = Pdf.unique_key "F" fontdict in let ops, urls, x, y, hoffset, voffset, text, joffset = - let text = process_text time text (replace_pairs pdf filename bates batespad num page) in + let text = process_text time text (replace_pairs pdf endpage extract_text_font_size filename bates batespad num page) in let text, urls = get_urls_line text in let expanded_lines = map (function text -> - process_text time text (replace_pairs pdf filename bates batespad num page)) + process_text time text (replace_pairs pdf endpage extract_text_font_size filename bates batespad num page)) lines in let expanded_lines = (* process URLs for justification too *) diff --git a/cpdfaddtext.mli b/cpdfaddtext.mli index d170b47..5b8e744 100644 --- a/cpdfaddtext.mli +++ b/cpdfaddtext.mli @@ -45,6 +45,17 @@ val addtexts : Pdf.t ->(*pdf*) Pdf.t +val replace_pairs : + Pdf.t -> + int -> + float option -> + string -> + int -> + int option -> int -> Pdfpage.t -> (string * (unit -> string)) list + +val process_text : + Cpdfstrftime.t -> string -> (string * (unit -> string)) list -> string + (* Add a rectangle to the page *) val addrectangle : bool ->