This commit is contained in:
John Whitington 2023-05-01 16:19:09 +01:00
parent 0cfc6f0afd
commit a8d8f447bf
2 changed files with 34 additions and 23 deletions

View File

@ -213,33 +213,33 @@ let pagelabel pdf num =
num num
(Pdfpagelabels.complete (Pdfpagelabels.read pdf)) (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 let addtext
time lines linewidth outline fast colour fontname encoding bates batespad time lines linewidth outline fast colour fontname encoding bates batespad
fontsize font fontpdfobj underneath position hoffset voffset text pages fontsize font fontpdfobj underneath position hoffset voffset text pages
cropbox opacity justification filename extract_text_font_size shift pdf cropbox opacity justification filename extract_text_font_size shift pdf
= =
let endpage = Pdfpage.endpage pdf in 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 shifts = Cpdfcoord.parse_coordinates pdf shift in
let addtext_page num page = let addtext_page num page =
let shift_x, shift_y = List.nth shifts (num - 1) in let shift_x, shift_y = List.nth shifts (num - 1) in
@ -298,13 +298,13 @@ let addtext
in in
let unique_fontname = Pdf.unique_key "F" fontdict in let unique_fontname = Pdf.unique_key "F" fontdict in
let ops, urls, x, y, hoffset, voffset, text, joffset = 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 text, urls = get_urls_line text in
let expanded_lines = let expanded_lines =
map map
(function text -> (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 lines
in in
let expanded_lines = (* process URLs for justification too *) let expanded_lines = (* process URLs for justification too *)

View File

@ -45,6 +45,17 @@ val addtexts :
Pdf.t ->(*pdf*) Pdf.t ->(*pdf*)
Pdf.t 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 *) (* Add a rectangle to the page *)
val addrectangle : val addrectangle :
bool -> bool ->