diff --git a/cpdfmanual.pdf b/cpdfmanual.pdf index ec9e342..d348dac 100644 Binary files a/cpdfmanual.pdf and b/cpdfmanual.pdf differ diff --git a/cpdfmanual.tex b/cpdfmanual.tex index 1e0dc85..3284451 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -1465,7 +1465,7 @@ Y factors given. This scales both the page contents, and the page size itself. I \noindent Scale a file's pages to fit A4 portrait, scaling the page 90\% of its possible size. \end{framed} -\noindent NB: \texttt{-scale-to-fit} operates with respect to the media box not the crop box. If necessary, set the media box to be equal to the crop box first. In addition, \texttt{-scale-to-fit} presently requires that the origin of the media box be (0, 0). This can be assured by preprocessing with \texttt{-upright} (described elsewhere in this chapter) or by adding the \texttt{-prerotate} option to the command. +\noindent NB: \texttt{-scale-to-fit} presently requires that the origin of the media box be (0, 0). This can be assured by preprocessing with \texttt{-upright} (described elsewhere in this chapter) or by adding the \texttt{-prerotate} option to the command. The \texttt{-scale-contents} operation scales the contents about the center of the crop box (or, if absent, the media box), leaving the page dimensions diff --git a/cpdfpage.ml b/cpdfpage.ml index f20c6d8..6140479 100644 --- a/cpdfpage.ml +++ b/cpdfpage.ml @@ -517,7 +517,6 @@ let scale_to_fit_pdf ?(fast=false) position input_scale xylist op pdf range = let x, y = List.nth xylist (pnum - 1) in let matrix = let (minx, miny, maxx, maxy) = - (* Use cropbox if available *) Pdf.parse_rectangle pdf (match Pdf.lookup_direct pdf "/CropBox" page.Pdfpage.rest with @@ -525,7 +524,7 @@ let scale_to_fit_pdf ?(fast=false) position input_scale xylist op pdf range = | None -> page.Pdfpage.mediabox) in if maxx <= 0. || maxy <= 0. then failwith "Zero-sized pages are invalid" else - let fx = x /. maxx in let fy = y /. maxy in + let fx = x /. (maxx -. minx) in let fy = y /. (maxy -. miny) in let scale = fmin fx fy *. input_scale in let trans_x = match position with @@ -538,8 +537,11 @@ let scale_to_fit_pdf ?(fast=false) position input_scale xylist op pdf range = | Cpdfposition.Bottom _ -> 0. | _ -> (y -. (maxy *. scale)) /. 2. in + let fixup_trans_x = -. (minx *. scale) /. 2. in + let fixup_trans_y = -. (miny *. scale) /. 2. in (Pdftransform.matrix_of_transform - [Pdftransform.Translate (trans_x, trans_y); + [Pdftransform.Translate (fixup_trans_x, fixup_trans_y); + Pdftransform.Translate (trans_x, trans_y); Pdftransform.Scale ((0., 0.), scale, scale)]) in let page =