-stamp-on, -stamp-under now work via -relative-to-cropbox command line switch

This commit is contained in:
John Whitington 2016-01-08 12:28:07 +00:00
parent 18aea65d7e
commit 632b739958
3 changed files with 15 additions and 14 deletions

20
cpdf.ml
View File

@ -2140,7 +2140,7 @@ let stamp_shift_of_position topline midline sw sh w h p =
| Diagonal | ReverseDiagonal | Centre -> | Diagonal | ReverseDiagonal | Centre ->
half w -. half sw, half h -. half sh -. dy 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 *) (* Scale page stamp o to fit page u *)
let sxmin, symin, sxmax, symax = let sxmin, symin, sxmax, symax =
Pdf.parse_rectangle 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 = let scale_op =
Pdfops.Op_cm Pdfops.Op_cm
(Pdftransform.matrix_of_transform (Pdftransform.matrix_of_transform
[Pdftransform.Translate (dx, dy); ([Pdftransform.Translate (dx, dy)] @
Pdftransform.Translate (txmin, tymin); (if relative_to_cropbox then [Pdftransform.Translate (txmin, tymin)] else []) @
Pdftransform.Scale ((sxmin, symin), scale, scale)]) [Pdftransform.Scale ((sxmin, symin), scale, scale)]))
in in
Pdfpage.prepend_operators pdf [scale_op] ~fast o Pdfpage.prepend_operators pdf [scale_op] ~fast o
else else
@ -2180,8 +2180,8 @@ let do_stamp fast position topline midline scale_to_fit isover pdf o u opdf =
let translate_op = let translate_op =
Pdfops.Op_cm Pdfops.Op_cm
(Pdftransform.matrix_of_transform (Pdftransform.matrix_of_transform
[Pdftransform.Translate (txmin, tymin); ((if relative_to_cropbox then [Pdftransform.Translate (txmin, tymin)] else []) @
Pdftransform.Translate (dx, dy)]) [Pdftransform.Translate (dx, dy)]))
in in
Pdfpage.prepend_operators pdf [translate_op] ~fast o Pdfpage.prepend_operators pdf [translate_op] ~fast o
in in
@ -2218,7 +2218,7 @@ let change_bookmark t m =
{m with Pdfmarks.target = {m with Pdfmarks.target =
try change_destination t m.Pdfmarks.target with Not_found -> m.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 = Pdfmarks.read_bookmarks pdf in
let marks_refnumbers = Pdf.page_reference_numbers pdf in let marks_refnumbers = Pdf.page_reference_numbers pdf in
let pdf = Pdfmarks.remove_bookmarks 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 = let new_pages =
map2 map2
(fun pageseq under_page -> (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 (if mem pageseq range then over_page else
Pdfpage.blankpage Pdfpaper.a4) Pdfpage.blankpage Pdfpaper.a4)
under_page over) under_page over)
@ -2302,7 +2302,7 @@ let combine_pages (fast : bool) under over scaletofit swap equalize =
let new_pages = let new_pages =
map2 map2
(fun o u -> (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 over_pages
under_pages under_pages
in in
@ -2356,7 +2356,7 @@ let nobble_page pdf _ page =
] ]
} }
in 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} *) (* \section{Set media box} *)
let set_mediabox x y w h pdf range = let set_mediabox x y w h pdf range =

View File

@ -204,10 +204,10 @@ swapped. If [fast] is true, the PDFs are assumed to be well-formed and no
fixes are done. *) fixes are done. *)
val combine_pages : bool -> Pdf.t -> Pdf.t -> bool -> bool -> bool -> Pdf.t 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 [over] over each page of the PDF. The arguments have the same meaning as in
[combine_pages]. *) [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} *) (** {2 Splitting PDFs} *)

View File

@ -1,3 +1,4 @@
(* Added -relative-to-cropbox for stamps *)
(* cpdf command line tools *) (* cpdf command line tools *)
let demo = false let demo = false
let noncomp = false let noncomp = false
@ -3568,7 +3569,7 @@ let go () =
let range = parse_pagespec pdf (get_pagespec ()) in let range = parse_pagespec pdf (get_pagespec ()) in
let pdf = let pdf =
Cpdf.stamp 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 args.scale_stamp_to_fit true range overpdf pdf
in in
write_pdf false pdf write_pdf false pdf
@ -3582,7 +3583,7 @@ let go () =
let range = parse_pagespec pdf (get_pagespec ()) in let range = parse_pagespec pdf (get_pagespec ()) in
let pdf = let pdf =
Cpdf.stamp 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 args.scale_stamp_to_fit false range underpdf pdf
in in
write_pdf false pdf write_pdf false pdf