From 219b58e466e9805ef3a4e7ef700fc68f6a0ed5e6 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Wed, 2 Oct 2019 13:41:56 +0100 Subject: [PATCH] Prepend contents --- cpdf.ml | 12 ++++++++++++ cpdf.mli | 3 +++ cpdfcommand.ml | 14 +------------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/cpdf.ml b/cpdf.ml index ad9d11c..1fa43c1 100644 --- a/cpdf.ml +++ b/cpdf.ml @@ -4196,4 +4196,16 @@ let add_page_labels pdf style prefix startval range = ranges; Pdfpagelabels.write pdf !labels +(* Parse the new content to make sure syntactically ok, append + * as required. Rewrite the content *) +let append_page_content_page fast s before pdf n page = + let ops = + Pdfops.parse_stream pdf page.Pdfpage.resources [bytes_of_string s] + in + (if before then Pdfpage.prepend_operators else Pdfpage.postpend_operators) + pdf ops ~fast page + +let append_page_content s before fast range pdf = + process_pages (append_page_content_page fast s before pdf) pdf range + diff --git a/cpdf.mli b/cpdf.mli index e602d47..e9de765 100644 --- a/cpdf.mli +++ b/cpdf.mli @@ -447,3 +447,6 @@ val call_cpdflin : string -> string -> string -> string -> int val debug : bool ref val extract_text : float option -> Pdf.t -> int list -> string + +val append_page_content : string -> bool -> bool -> int list -> Pdf.t -> Pdf.t + diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 5c94f7c..a941483 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -3524,18 +3524,6 @@ let trim_marks_page pdf n page = let trim_marks range pdf = Cpdf.process_pages (trim_marks_page pdf) pdf range -(* Parse the new content to make sure syntactically ok, append - * as required. Rewrite the content *) -let append_page_content_page s before pdf n page = - let ops = - Pdfops.parse_stream pdf page.Pdfpage.resources [bytes_of_string s] - in - (if before then Pdfpage.prepend_operators else Pdfpage.postpend_operators) - pdf ops ~fast:args.fast page - -let append_page_content s before range pdf = - Cpdf.process_pages (append_page_content_page s before pdf) pdf range - (* Main function *) let go () = match args.op with @@ -4418,7 +4406,7 @@ let go () = let pdf = get_single_pdf args.op false in let range = parse_pagespec pdf (get_pagespec ()) in let before = match x with Prepend _ -> true | _ -> false in - write_pdf false (append_page_content s before range pdf) + write_pdf false (Cpdf.append_page_content s before args.fast range pdf) let parse_argv () = if args.debug then