From 332ff6c6b891e15ce0c04595b1327597b0aaecbc Mon Sep 17 00:00:00 2001 From: John Whitington Date: Tue, 28 Nov 2023 16:40:50 +0000 Subject: [PATCH] restructuring chop --- cpdfchop.ml | 20 +++++++++----------- cpdfmanual.tex | 1 + 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/cpdfchop.ml b/cpdfchop.ml index e2e2557..df3f8f1 100644 --- a/cpdfchop.ml +++ b/cpdfchop.ml @@ -2,13 +2,10 @@ open Pdfutil open Cpdferror (* 1. FIXME btt / rtl / columns *) -(* 2. FIXME Test/document how the sharing affects other cpdf operations - especially with -fast! What do we do with fast/slow, and what does it affect, and does -fast need documentation about what happens in general with shared content streams. *) -(* 3. Annotations must be duplicated *) -(* 4. What is the effect on bookmarks and links annotations? *) -(* 5. Any other page meta items? *) (* 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. We delete /Annots, since + duplicate annotations are not allowed. *) let get_box pdf page = match Pdf.lookup_direct pdf "/CropBox" page.Pdfpage.rest with | Some r -> Pdf.parse_rectangle pdf r @@ -16,7 +13,12 @@ let get_box pdf page = let erase_boxes d = let f = Pdf.remove_dict_entry in - f (f (f (f d "/CropBox") "/BleedBox") "/TrimBox") "/ArtBox" + f (f (f (f (f d "/CropBox") "/BleedBox") "/TrimBox") "/ArtBox") "/Annots" + +let make_pages x y columns btt rtl w h ps move_page = + for ty = y - 1 downto 0 do for tx = 0 to x - 1 do + ps =| move_page (w *. float_of_int tx) (h *. float_of_int ty) + done done let chop_boxes pdf x y columns btt rtl p = if x < 1 || y < 1 then Cpdferror.error "chop_boxes bad specification" else @@ -32,11 +34,7 @@ let chop_boxes pdf x y columns btt rtl p = (*Printf.printf "minx, miny, maxx, maxy = %f, %f, %f, %f\n" minx miny maxx maxy;*) let w, h = (maxx -. minx) /. float_of_int x, (maxy -. miny) /. float_of_int y in let ps = ref [] in - let move_page = move_page minx miny p w h in - (* columns, btt, rtl *) - for ty = y - 1 downto 0 do for tx = 0 to x - 1 do - ps =| move_page (w *. float_of_int tx) (h *. float_of_int ty) - done done; + make_pages x y columns btt rtl w h ps (move_page minx miny p w h); rev !ps (* Chop pages in the range into pieces *) diff --git a/cpdfmanual.tex b/cpdfmanual.tex index cbb76e4..b8dd9d7 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -4,6 +4,7 @@ %Document subformat information %Document -list-images[-json], -list-image-uses[-json], -image-resolution-json %Document -raw for -extract-images +%Add note to -fast about content sharing (with reference to -chop, but in general too) \documentclass{book} % Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf, % dotnetcpdflibmanual.pdf, jcpdflibmanual.pdf jscpdflibmanual.pdf etc.