Prepend contents

This commit is contained in:
John Whitington 2019-10-02 13:41:56 +01:00
parent 922ab94c1e
commit 219b58e466
3 changed files with 16 additions and 13 deletions

12
cpdf.ml
View File

@ -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

View File

@ -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

View File

@ -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