More apparatus for -stamp-as-xobject

This commit is contained in:
John Whitington 2020-03-19 16:23:16 +00:00
parent 2e8683dfa1
commit e6afa6e8f2
3 changed files with 20 additions and 6 deletions

21
cpdf.ml
View File

@ -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. *)

View File

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

View File

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