First successful chop
This commit is contained in:
parent
d3449af2c0
commit
428f037a51
21
cpdfchop.ml
21
cpdfchop.ml
|
@ -1,22 +1,29 @@
|
||||||
open Pdfutil
|
open Pdfutil
|
||||||
open Cpdferror
|
open Cpdferror
|
||||||
|
|
||||||
(* Resources - what to do with each. Bookmarks? Annotations - must be duplicated... *)
|
(* FIXME Resources - what to do with each. Bookmarks? Annotations - must be duplicated... *)
|
||||||
(* Test how the sharing affects other cpdf operations - especially with -fast! *)
|
(* FIXME Test how the sharing affects other cpdf operations - especially with -fast! *)
|
||||||
(* Allow different orders - btt / ltr etc. *)
|
|
||||||
|
|
||||||
(* Chop a single page into pieces. We prefer the cropbox when available. We set
|
(* Chop a single page into pieces. We prefer the cropbox when available. We set
|
||||||
mediabox only, and delete any other boxes. *)
|
mediabox only, and delete any other boxes. *)
|
||||||
(* FIXME check non-zero based boxes *)
|
(* FIXME check non-zero based boxes *)
|
||||||
|
(* FIXME erase boxes *)
|
||||||
|
(* FIXME Get mediabox / cropbox properly *)
|
||||||
|
(* FIXME Check rotated pages just work *)
|
||||||
|
(* FIXME btt / rtl *)
|
||||||
let chop_boxes x y p =
|
let chop_boxes x y p =
|
||||||
if x < 1 || y < 1 then Cpdferror.error "chop_boxes bad specification" else
|
if x < 1 || y < 1 then Cpdferror.error "chop_boxes bad specification" else
|
||||||
let move_page p dx dy = Printf.printf "move_page %f %f\n" dx dy; p in
|
let move_page p w h dx dy =
|
||||||
|
(*Printf.printf "move_page %f %f\n" dx dy;*)
|
||||||
|
let nminx, nminy, nmaxx, nmaxy = (0. +. dx, 0. +. dy, w +. dx, h +. dy) in
|
||||||
|
{p with Pdfpage.mediabox = Pdf.Array [Pdf.Real nminx; Pdf.Real nminy; Pdf.Real nmaxx; Pdf.Real nmaxy]}
|
||||||
|
in
|
||||||
let minx, miny, maxx, maxy = 0., 0., 540., 666. in
|
let minx, miny, maxx, maxy = 0., 0., 540., 666. in
|
||||||
let w, h = (maxx -. minx) /. float_of_int x, (maxy -. miny) /. float_of_int y in
|
let w, h = (maxx -. minx) /. float_of_int x, (maxy -. miny) /. float_of_int y in
|
||||||
let ps = ref [] in
|
let ps = ref [] in
|
||||||
for ty = 0 to x do
|
for ty = y - 1 downto 0 do
|
||||||
for tx = 0 to y do
|
for tx = 0 to x - 1 do
|
||||||
ps =| move_page p (w *. float_of_int tx) (h *. float_of_int ty *. ~-.1.)
|
ps =| move_page p w h (w *. float_of_int tx) (h *. float_of_int ty)
|
||||||
done
|
done
|
||||||
done;
|
done;
|
||||||
rev !ps
|
rev !ps
|
||||||
|
|
Loading…
Reference in New Issue