diff --git a/cpdf.ml b/cpdf.ml index cdff1c1..07745ef 100644 --- a/cpdf.ml +++ b/cpdf.ml @@ -2140,7 +2140,7 @@ let stamp_shift_of_position topline midline sw sh w h p = | Diagonal | ReverseDiagonal | Centre -> half w -. half sw, half h -. half sh -. dy -let do_stamp fast position topline midline scale_to_fit isover pdf o u opdf = +let do_stamp relative_to_cropbox fast position topline midline scale_to_fit isover pdf o u opdf = (* Scale page stamp o to fit page u *) let sxmin, symin, sxmax, symax = Pdf.parse_rectangle @@ -2166,9 +2166,9 @@ let do_stamp fast position topline midline scale_to_fit isover pdf o u opdf = let scale_op = Pdfops.Op_cm (Pdftransform.matrix_of_transform - [Pdftransform.Translate (dx, dy); - Pdftransform.Translate (txmin, tymin); - Pdftransform.Scale ((sxmin, symin), scale, scale)]) + ([Pdftransform.Translate (dx, dy)] @ + (if relative_to_cropbox then [Pdftransform.Translate (txmin, tymin)] else []) @ + [Pdftransform.Scale ((sxmin, symin), scale, scale)])) in Pdfpage.prepend_operators pdf [scale_op] ~fast o else @@ -2180,8 +2180,8 @@ let do_stamp fast position topline midline scale_to_fit isover pdf o u opdf = let translate_op = Pdfops.Op_cm (Pdftransform.matrix_of_transform - [Pdftransform.Translate (txmin, tymin); - Pdftransform.Translate (dx, dy)]) + ((if relative_to_cropbox then [Pdftransform.Translate (txmin, tymin)] else []) @ + [Pdftransform.Translate (dx, dy)])) in Pdfpage.prepend_operators pdf [translate_op] ~fast o in @@ -2218,7 +2218,7 @@ let change_bookmark t m = {m with Pdfmarks.target = try change_destination t m.Pdfmarks.target with Not_found -> m.Pdfmarks.target} -let stamp position topline midline fast scale_to_fit isover range over pdf = +let stamp relative_to_cropbox position topline midline fast scale_to_fit isover range over pdf = let marks = Pdfmarks.read_bookmarks pdf in let marks_refnumbers = Pdf.page_reference_numbers pdf in let pdf = Pdfmarks.remove_bookmarks pdf in @@ -2248,7 +2248,7 @@ let stamp position topline midline fast scale_to_fit isover range over pdf = let new_pages = map2 (fun pageseq under_page -> - do_stamp fast position topline midline scale_to_fit isover renamed_pdf + do_stamp relative_to_cropbox fast position topline midline scale_to_fit isover renamed_pdf (if mem pageseq range then over_page else Pdfpage.blankpage Pdfpaper.a4) under_page over) @@ -2302,7 +2302,7 @@ let combine_pages (fast : bool) under over scaletofit swap equalize = let new_pages = map2 (fun o u -> - do_stamp fast (BottomLeft 0.) false false scaletofit (not swap) renamed_pdf o u over) + do_stamp false fast (BottomLeft 0.) false false scaletofit (not swap) renamed_pdf o u over) over_pages under_pages in @@ -2356,7 +2356,7 @@ let nobble_page pdf _ page = ] } in - do_stamp false (BottomLeft 0.) false false false true pdf page' page (Pdf.empty ()) + do_stamp false false (BottomLeft 0.) false false false true pdf page' page (Pdf.empty ()) (* \section{Set media box} *) let set_mediabox x y w h pdf range = diff --git a/cpdf.mli b/cpdf.mli index 4345f71..3a4c6e9 100644 --- a/cpdf.mli +++ b/cpdf.mli @@ -204,10 +204,10 @@ swapped. If [fast] is true, the PDFs are assumed to be well-formed and no fixes are done. *) val combine_pages : bool -> Pdf.t -> Pdf.t -> bool -> bool -> bool -> Pdf.t -(** [stamp position topline midline scale_to_fit fast isover range over pdf] stamps the first page of +(** [stamp relative_to_cropbox position topline midline scale_to_fit fast isover range over pdf] stamps the first page of [over] over each page of the PDF. The arguments have the same meaning as in [combine_pages]. *) -val stamp : position -> bool -> bool -> bool -> bool -> bool -> int list -> Pdf.t -> Pdf.t -> Pdf.t +val stamp : bool -> position -> bool -> bool -> bool -> bool -> bool -> int list -> Pdf.t -> Pdf.t -> Pdf.t (** {2 Splitting PDFs} *) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 6b325bf..1365997 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -1,3 +1,4 @@ +(* Added -relative-to-cropbox for stamps *) (* cpdf command line tools *) let demo = false let noncomp = false @@ -3568,7 +3569,7 @@ let go () = let range = parse_pagespec pdf (get_pagespec ()) in let pdf = Cpdf.stamp - args.position args.topline args.midline args.fast + args.relative_to_cropbox args.position args.topline args.midline args.fast args.scale_stamp_to_fit true range overpdf pdf in write_pdf false pdf @@ -3582,7 +3583,7 @@ let go () = let range = parse_pagespec pdf (get_pagespec ()) in let pdf = Cpdf.stamp - args.position args.topline args.midline args.fast + args.relative_to_cropbox args.position args.topline args.midline args.fast args.scale_stamp_to_fit false range underpdf pdf in write_pdf false pdf