Beginning of -remove-clipping

This commit is contained in:
John Whitington 2016-11-09 15:42:47 +00:00
parent 796f6afb66
commit f6e158ee07
3 changed files with 27 additions and 4 deletions

View File

@ -3242,7 +3242,6 @@ let process_xobject f pdf resources i =
end end
| Some _ -> () | Some _ -> ()
let process_xobjects pdf page f = let process_xobjects pdf page f =
match Pdf.lookup_direct pdf "/XObject" page.Pdfpage.resources with match Pdf.lookup_direct pdf "/XObject" page.Pdfpage.resources with
| Some (Pdf.Dictionary elts) -> | Some (Pdf.Dictionary elts) ->
@ -3250,7 +3249,7 @@ let process_xobjects pdf page f =
(fun (k, v) -> (fun (k, v) ->
match v with match v with
| Pdf.Indirect i -> process_xobject f pdf page.Pdfpage.resources i | Pdf.Indirect i -> process_xobject f pdf page.Pdfpage.resources i
| _ -> raise (Pdf.PDFError "blacktext")) | _ -> raise (Pdf.PDFError "process_xobject"))
elts elts
| _ -> () | _ -> ()

View File

@ -473,6 +473,8 @@ val draft : bool -> int list -> Pdf.t -> Pdf.t
(** Squeeze a PDF *) (** Squeeze a PDF *)
val squeeze : ?logto:string -> Pdf.t -> unit val squeeze : ?logto:string -> Pdf.t -> unit
val process_xobjects : Pdf.t -> Pdfpage.t -> (Pdf.t -> Pdf.pdfobject -> Pdf.pdfobject list -> Pdf.pdfobject list) -> unit
(**/**) (**/**)
(** Custom CSP1 *) (** Custom CSP1 *)

View File

@ -1,4 +1,4 @@
(* Added -relative-to-cropbox for stamps *) (* FIXME DOC Added -relative-to-cropbox for stamps *)
(* cpdf command line tools *) (* cpdf command line tools *)
let demo = false let demo = false
let noncomp = false let noncomp = false
@ -165,6 +165,7 @@ type op =
| Revisions | Revisions
| RemoveDictEntry of string | RemoveDictEntry of string
| ListSpotColours | ListSpotColours
| RemoveClipping
let string_of_op = function let string_of_op = function
| CopyFont _ -> "CopyFont" | CopyFont _ -> "CopyFont"
@ -268,6 +269,7 @@ let string_of_op = function
| Revisions -> "Revisions" | Revisions -> "Revisions"
| RemoveDictEntry _ -> "RemoveDictEntry" | RemoveDictEntry _ -> "RemoveDictEntry"
| ListSpotColours -> "ListSpotColours" | ListSpotColours -> "ListSpotColours"
| RemoveClipping -> "RemoveClipping"
(* Inputs: filename, pagespec. *) (* Inputs: filename, pagespec. *)
type input_kind = type input_kind =
@ -607,7 +609,8 @@ let banned banlist = function
BlackText|BlackLines|BlackFills|CopyFont _|CSP2 _|StampOn _|StampUnder _| BlackText|BlackLines|BlackFills|CopyFont _|CSP2 _|StampOn _|StampUnder _|
AddText _|ScaleContents _|AttachFile _|CopyAnnotations _|SetMetadata _| AddText _|ScaleContents _|AttachFile _|CopyAnnotations _|SetMetadata _|
ThinLines _|SetAuthor _|SetTitle _|SetSubject _|SetKeywords _|SetCreate _| ThinLines _|SetAuthor _|SetTitle _|SetSubject _|SetKeywords _|SetCreate _|
SetModify _|SetCreator _|SetProducer _|SetVersion _|RemoveDictEntry _ -> SetModify _|SetCreator _|SetProducer _|SetVersion _|RemoveDictEntry _ |
RemoveClipping ->
mem Pdfcrypt.NoEdit banlist mem Pdfcrypt.NoEdit banlist
let operation_allowed pdf banlist op = let operation_allowed pdf banlist op =
@ -2005,6 +2008,9 @@ and specs =
("-thinlines", ("-thinlines",
Arg.String setthinlines, Arg.String setthinlines,
" Set minimum line thickness to the given width"); " Set minimum line thickness to the given width");
("-remove-clipping",
Arg.Unit (setop RemoveClipping),
" Remove clipping paths");
("-clean", ("-clean",
Arg.Unit (setop Clean), Arg.Unit (setop Clean),
" Garbage-collect a file"); " Garbage-collect a file");
@ -3155,6 +3161,18 @@ let list_spot_colours pdf =
| _ -> ()) | _ -> ())
pdf pdf
let remove_clipping_ops pdf resources content = content
let remove_clipping pdf range =
let remove_clipping_page _ page =
let content' =
remove_clipping_ops pdf page.Pdfpage.resources page.Pdfpage.content
in
Cpdf.process_xobjects pdf page remove_clipping_ops;
{page with Pdfpage.content = content'}
in
Cpdf.process_pages remove_clipping_page pdf range
(* Main function *) (* Main function *)
let go () = let go () =
match args.op with match args.op with
@ -3901,6 +3919,10 @@ let go () =
| Some ListSpotColours -> | Some ListSpotColours ->
let pdf = get_single_pdf args.op false in let pdf = get_single_pdf args.op false in
list_spot_colours pdf list_spot_colours pdf
| Some RemoveClipping ->
let pdf = get_single_pdf args.op false in
let range = parse_pagespec pdf (get_pagespec ()) in
write_pdf false (remove_clipping pdf range)
let parse_argv () = let parse_argv () =
if args.debug then if args.debug then