Optional absolute rectangles
This commit is contained in:
parent
6495daba8c
commit
b676ab4923
4
Changes
4
Changes
|
@ -19,6 +19,10 @@ New features:
|
||||||
o -stretch scales without preserving aspect ratio
|
o -stretch scales without preserving aspect ratio
|
||||||
o -redact removes whole pages
|
o -redact removes whole pages
|
||||||
|
|
||||||
|
Extended features:
|
||||||
|
|
||||||
|
o Rectangle may be specified as x y x2 y2 rather than x y w h
|
||||||
|
|
||||||
* = Supported by a grant from NLnet
|
* = Supported by a grant from NLnet
|
||||||
|
|
||||||
2.7.1 (July 2024)
|
2.7.1 (July 2024)
|
||||||
|
|
17
cpdfcoord.ml
17
cpdfcoord.ml
|
@ -207,20 +207,33 @@ let parse_units_string pdf page s =
|
||||||
fs
|
fs
|
||||||
|
|
||||||
let parse_rectangle pdf s =
|
let parse_rectangle pdf s =
|
||||||
|
(* If it begins with ? it's absolute *)
|
||||||
|
let s, absolute =
|
||||||
|
match explode s with
|
||||||
|
| '?'::r -> implode r, true
|
||||||
|
| _ -> s, false
|
||||||
|
in
|
||||||
try
|
try
|
||||||
match parse_units_string pdf emptypage s with
|
match parse_units_string pdf emptypage s with
|
||||||
| [x; y; w; h] -> x, y, w, h
|
| [x; y; w; h] ->
|
||||||
|
if absolute then x, y, w -. x, h -. y else x, y, w, h
|
||||||
| _ -> error ("Bad rectangle specification " ^ s)
|
| _ -> error ("Bad rectangle specification " ^ s)
|
||||||
with
|
with
|
||||||
e -> error ("Bad rectangle specification " ^ s ^ " : " ^ Printexc.to_string e)
|
e -> error ("Bad rectangle specification " ^ s ^ " : " ^ Printexc.to_string e)
|
||||||
|
|
||||||
let parse_rectangles pdf s =
|
let parse_rectangles pdf s =
|
||||||
|
(* If it begins with ? it's absolute *)
|
||||||
|
let s, absolute =
|
||||||
|
match explode s with
|
||||||
|
| '?'::r -> implode r, true
|
||||||
|
| _ -> s, false
|
||||||
|
in
|
||||||
try
|
try
|
||||||
let pages = Pdfpage.pages_of_pagetree pdf in
|
let pages = Pdfpage.pages_of_pagetree pdf in
|
||||||
let groups = List.map (fun page -> parse_units_string pdf page s) pages in
|
let groups = List.map (fun page -> parse_units_string pdf page s) pages in
|
||||||
List.map
|
List.map
|
||||||
(function
|
(function
|
||||||
| [x; y; w; h] -> (x, y, w, h)
|
| [x; y; w; h] -> if absolute then x, y, w -. x, h -. y else x, y, w, h
|
||||||
| _ -> error ("Bad rectangle specification " ^ s))
|
| _ -> error ("Bad rectangle specification " ^ s))
|
||||||
groups
|
groups
|
||||||
with
|
with
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
%Document -stretch
|
%Document -stretch
|
||||||
%Document -redact
|
%Document -redact
|
||||||
|
%Document ?x0 y0 x1 y1 rectangle specifications
|
||||||
\documentclass{book}
|
\documentclass{book}
|
||||||
% Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf,
|
% Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf,
|
||||||
% dotnetcpdflibmanual.pdf, jcpdflibmanual.pdf jscpdflibmanual.pdf etc.
|
% dotnetcpdflibmanual.pdf, jcpdflibmanual.pdf jscpdflibmanual.pdf etc.
|
||||||
|
|
Loading…
Reference in New Issue