Added -prepend-content, -postpend-content
This commit is contained in:
parent
380296a4fa
commit
922ab94c1e
1
Changes
1
Changes
|
@ -1,6 +1,7 @@
|
||||||
Version 2.4 (in development)
|
Version 2.4 (in development)
|
||||||
|
|
||||||
o Allow -shift with -add-text for additional adjustment
|
o Allow -shift with -add-text for additional adjustment
|
||||||
|
o Prepend and postpend directly to page content streams
|
||||||
|
|
||||||
Version 2.3 (October 2019)
|
Version 2.3 (October 2019)
|
||||||
|
|
||||||
|
|
|
@ -187,6 +187,8 @@ type op =
|
||||||
| RemoveAllText
|
| RemoveAllText
|
||||||
| ShowBoxes
|
| ShowBoxes
|
||||||
| TrimMarks
|
| TrimMarks
|
||||||
|
| Prepend of string
|
||||||
|
| Postpend of string
|
||||||
|
|
||||||
let string_of_op = function
|
let string_of_op = function
|
||||||
| CopyFont _ -> "CopyFont"
|
| CopyFont _ -> "CopyFont"
|
||||||
|
@ -307,6 +309,8 @@ let string_of_op = function
|
||||||
| RemoveAllText -> "RemoveAllText"
|
| RemoveAllText -> "RemoveAllText"
|
||||||
| ShowBoxes -> "ShowBoxes"
|
| ShowBoxes -> "ShowBoxes"
|
||||||
| TrimMarks -> "TrimMarks"
|
| TrimMarks -> "TrimMarks"
|
||||||
|
| Prepend _ -> "Prepend"
|
||||||
|
| Postpend _ -> "Postpend"
|
||||||
|
|
||||||
(* Inputs: filename, pagespec. *)
|
(* Inputs: filename, pagespec. *)
|
||||||
type input_kind =
|
type input_kind =
|
||||||
|
@ -681,7 +685,8 @@ let banned banlist = function
|
||||||
RemoveAnnotations|RemoveFonts|Crop|RemoveCrop|Trim|RemoveTrim|Bleed|RemoveBleed|Art|RemoveArt|
|
RemoveAnnotations|RemoveFonts|Crop|RemoveCrop|Trim|RemoveTrim|Bleed|RemoveBleed|Art|RemoveArt|
|
||||||
CopyCropBoxToMediaBox|CopyBox|MediaBox|HardBox _|SetTrapped|SetUntrapped|Presentation|
|
CopyCropBoxToMediaBox|CopyBox|MediaBox|HardBox _|SetTrapped|SetUntrapped|Presentation|
|
||||||
BlackText|BlackLines|BlackFills|CopyFont _|CSP2 _|StampOn _|StampUnder _|
|
BlackText|BlackLines|BlackFills|CopyFont _|CSP2 _|StampOn _|StampUnder _|
|
||||||
AddText _|ScaleContents _|AttachFile _|CopyAnnotations _| ThinLines _ | RemoveClipping | RemoveAllText ->
|
AddText _|ScaleContents _|AttachFile _|CopyAnnotations _| ThinLines _ | RemoveClipping | RemoveAllText
|
||||||
|
| Prepend _ | Postpend _ ->
|
||||||
mem Pdfcrypt.NoEdit banlist
|
mem Pdfcrypt.NoEdit banlist
|
||||||
|
|
||||||
let operation_allowed pdf banlist op =
|
let operation_allowed pdf banlist op =
|
||||||
|
@ -1174,6 +1179,12 @@ let setcreator s =
|
||||||
let setproducer s =
|
let setproducer s =
|
||||||
args.producer <- Some s
|
args.producer <- Some s
|
||||||
|
|
||||||
|
let setprepend s =
|
||||||
|
args.op <- Some (Prepend s)
|
||||||
|
|
||||||
|
let setpostpend s =
|
||||||
|
args.op <- Some (Postpend s)
|
||||||
|
|
||||||
(* Parsing the control file *)
|
(* Parsing the control file *)
|
||||||
let rec getuntilendquote prev = function
|
let rec getuntilendquote prev = function
|
||||||
| [] -> implode (rev prev), []
|
| [] -> implode (rev prev), []
|
||||||
|
@ -2043,7 +2054,13 @@ and specs =
|
||||||
" Number of pages for new PDF");
|
" Number of pages for new PDF");
|
||||||
("-create-pdf-papersize",
|
("-create-pdf-papersize",
|
||||||
Arg.String setcreatepdfpapersize,
|
Arg.String setcreatepdfpapersize,
|
||||||
" Paper size for new PDF");
|
" Paper size for new PDF");
|
||||||
|
("-prepend-content",
|
||||||
|
Arg.String setprepend,
|
||||||
|
" Prepend content to page");
|
||||||
|
("-postpend-content",
|
||||||
|
Arg.String setpostpend,
|
||||||
|
" Postpend content to page");
|
||||||
("-gs", Arg.String setgspath, " Path to gs executable");
|
("-gs", Arg.String setgspath, " Path to gs executable");
|
||||||
("-gs-malformed", Arg.Unit setgsmalformed, " Also try to reconstruct malformed files with gs");
|
("-gs-malformed", Arg.Unit setgsmalformed, " Also try to reconstruct malformed files with gs");
|
||||||
("-gs-quiet", Arg.Unit setgsquiet, " Make gs go into quiet mode");
|
("-gs-quiet", Arg.Unit setgsquiet, " Make gs go into quiet mode");
|
||||||
|
@ -3507,6 +3524,18 @@ let trim_marks_page pdf n page =
|
||||||
let trim_marks range pdf =
|
let trim_marks range pdf =
|
||||||
Cpdf.process_pages (trim_marks_page pdf) pdf range
|
Cpdf.process_pages (trim_marks_page pdf) pdf range
|
||||||
|
|
||||||
|
(* Parse the new content to make sure syntactically ok, append
|
||||||
|
* as required. Rewrite the content *)
|
||||||
|
let append_page_content_page s before pdf n page =
|
||||||
|
let ops =
|
||||||
|
Pdfops.parse_stream pdf page.Pdfpage.resources [bytes_of_string s]
|
||||||
|
in
|
||||||
|
(if before then Pdfpage.prepend_operators else Pdfpage.postpend_operators)
|
||||||
|
pdf ops ~fast:args.fast page
|
||||||
|
|
||||||
|
let append_page_content s before range pdf =
|
||||||
|
Cpdf.process_pages (append_page_content_page s before pdf) pdf range
|
||||||
|
|
||||||
(* Main function *)
|
(* Main function *)
|
||||||
let go () =
|
let go () =
|
||||||
match args.op with
|
match args.op with
|
||||||
|
@ -4385,6 +4414,11 @@ let go () =
|
||||||
let pdf = get_single_pdf args.op false in
|
let pdf = get_single_pdf args.op false in
|
||||||
let range = parse_pagespec pdf (get_pagespec ()) in
|
let range = parse_pagespec pdf (get_pagespec ()) in
|
||||||
write_pdf false (trim_marks range pdf)
|
write_pdf false (trim_marks range pdf)
|
||||||
|
| Some (Postpend s | Prepend s as x) ->
|
||||||
|
let pdf = get_single_pdf args.op false in
|
||||||
|
let range = parse_pagespec pdf (get_pagespec ()) in
|
||||||
|
let before = match x with Prepend _ -> true | _ -> false in
|
||||||
|
write_pdf false (append_page_content s before range pdf)
|
||||||
|
|
||||||
let parse_argv () =
|
let parse_argv () =
|
||||||
if args.debug then
|
if args.debug then
|
||||||
|
|
Loading…
Reference in New Issue