Work on making -scale-to-fit / nonzero box origins
This commit is contained in:
parent
128f9361ff
commit
66c42fc621
BIN
cpdfmanual.pdf
BIN
cpdfmanual.pdf
Binary file not shown.
|
@ -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.
|
\noindent Scale a file's pages to fit A4 portrait, scaling the page 90\% of its possible size.
|
||||||
\end{framed}
|
\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
|
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
|
of the crop box (or, if absent, the media box), leaving the page dimensions
|
||||||
|
|
|
@ -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 x, y = List.nth xylist (pnum - 1) in
|
||||||
let matrix =
|
let matrix =
|
||||||
let (minx, miny, maxx, maxy) =
|
let (minx, miny, maxx, maxy) =
|
||||||
(* Use cropbox if available *)
|
|
||||||
Pdf.parse_rectangle
|
Pdf.parse_rectangle
|
||||||
pdf
|
pdf
|
||||||
(match Pdf.lookup_direct pdf "/CropBox" page.Pdfpage.rest with
|
(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)
|
| None -> page.Pdfpage.mediabox)
|
||||||
in
|
in
|
||||||
if maxx <= 0. || maxy <= 0. then failwith "Zero-sized pages are invalid" else
|
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 scale = fmin fx fy *. input_scale in
|
||||||
let trans_x =
|
let trans_x =
|
||||||
match position with
|
match position with
|
||||||
|
@ -538,8 +537,11 @@ let scale_to_fit_pdf ?(fast=false) position input_scale xylist op pdf range =
|
||||||
| Cpdfposition.Bottom _ -> 0.
|
| Cpdfposition.Bottom _ -> 0.
|
||||||
| _ -> (y -. (maxy *. scale)) /. 2.
|
| _ -> (y -. (maxy *. scale)) /. 2.
|
||||||
in
|
in
|
||||||
|
let fixup_trans_x = -. (minx *. scale) /. 2. in
|
||||||
|
let fixup_trans_y = -. (miny *. scale) /. 2. in
|
||||||
(Pdftransform.matrix_of_transform
|
(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)])
|
Pdftransform.Scale ((0., 0.), scale, scale)])
|
||||||
in
|
in
|
||||||
let page =
|
let page =
|
||||||
|
|
Loading…
Reference in New Issue