From e6afa6e8f2daee03b8509a396a8c0ad73befb370 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Thu, 19 Mar 2020 16:23:16 +0000 Subject: [PATCH] More apparatus for -stamp-as-xobject --- cpdf.ml | 21 +++++++++++++++++---- cpdf.mli | 2 +- cpdfcommand.ml | 3 ++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/cpdf.ml b/cpdf.ml index 31e0285..81dff9c 100644 --- a/cpdf.ml +++ b/cpdf.ml @@ -2533,10 +2533,23 @@ let stamp relative_to_cropbox position topline midline fast scale_to_fit isover let new_marks = map (change_bookmark changetable) marks in Pdfmarks.add_bookmarks new_marks changed -let add_page_as_xobject pdf page name = - pdf +let add_page_as_xobject pdf range page name = + let xobject_data = bytes_of_string "0 0 m 0 100 l 100 100 l 100 0 l f" in + let xobject_dict = + ["/Type", Pdf.Name "/XObject"; + "/Subtype", Pdf.Name "/Form"; + "/BBox", Pdf.Array [Pdf.Real 0.; Pdf.Real 0.; Pdf.Real 1000.; Pdf.Real 1000.]; + "/Resources", Pdf.Dictionary []; + "/Length", Pdf.Integer (bytes_size xobject_data); + ] + in + let xobject = + Pdf.Stream {contents = (Pdf.Dictionary xobject_dict, Pdf.Got xobject_data)} + in + let xobject_objnum = Pdf.addobj pdf xobject in + pdf -let stamp_as_xobject pdf over = +let stamp_as_xobject pdf range over = let prefix = Pdfpage.shortest_unused_prefix pdf in Pdfpage.add_prefix over prefix; let marks = Pdfmarks.read_bookmarks pdf in @@ -2573,7 +2586,7 @@ let stamp_as_xobject pdf over = let new_marks = map (change_bookmark changetable) marks in let pdf = Pdfmarks.add_bookmarks new_marks changed in let name = "/X0" in - (add_page_as_xobject pdf over_page name, name) + (add_page_as_xobject pdf range over_page name, name) (* Combine pages from two PDFs. For now, assume equal length. *) diff --git a/cpdf.mli b/cpdf.mli index 0e47fcd..34217cc 100644 --- a/cpdf.mli +++ b/cpdf.mli @@ -458,5 +458,5 @@ val ocg_rename : string -> string -> Pdf.t -> unit val ocg_order_all : Pdf.t -> unit -val stamp_as_xobject : Pdf.t -> Pdf.t -> Pdf.t * string +val stamp_as_xobject : Pdf.t -> int list -> Pdf.t -> Pdf.t * string diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 266c67f..80dce5f 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -4504,8 +4504,9 @@ let go () = | x -> pdfread_pdf_of_file None None x in let pdf = get_single_pdf args.op false in + let range = parse_pagespec pdf (get_pagespec ()) in let pdf, xobj_name = - Cpdf.stamp_as_xobject pdf stamp_pdf + Cpdf.stamp_as_xobject pdf range stamp_pdf in Printf.printf "%s\n" xobj_name; flush stdout;