Beginning chop implementation

This commit is contained in:
John Whitington 2023-11-20 12:53:51 +02:00
parent ddf149254e
commit f573ba8e09
2 changed files with 21 additions and 9 deletions

View File

@ -1,12 +1,22 @@
open Pdfutil
open Cpdferror
(* Prevent duplication of content by sharing content streams *)
(* Resources - patterns etc. - pattern matrices *)
(* Bookmarks: merge/duplicate them *)
(* Annotations: merge/duplicate them *)
(* Page boxes - mediabox or cropbox used? Output modifies all boxes? *)
(* fast/slow *)
(* Resources - what to do with each. Bookmarks? Annotations - must be duplicated... *)
(* Test how the sharing affects other cpdf operations. *)
(* Chop pages into pieces *)
let chop ~x ~y pdf range = pdf
(* Chop a single page into pieces. We prefer the cropbox when available. We set
mediabox only, and delete any other boxes. *)
let chop_boxes x y p = [p; p]
(* Chop pages in the range into pieces *)
let chop ~x ~y pdf range =
let pages = Pdfpage.pages_of_pagetree pdf in
let pages =
flatten
(map2
(fun n p -> if mem n range then (chop_boxes x y p) else [p])
(ilist 1 (Pdfpage.endpage pdf))
pages)
in
let changes = [] in (* FIXME *)
Pdfpage.change_pages ~changes true pdf pages

View File

@ -4379,7 +4379,9 @@ let go () =
in
Cpdfcomposition.show_composition filesize json pdf
| Some (Chop (x, y)) ->
()
let pdf = get_single_pdf args.op false in
let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in
write_pdf false (Cpdfchop.chop ~x ~y pdf range)
(* Advise the user if a combination of command line flags makes little sense,
or error out if it make no sense at all. *)