Reflecting internal Pdfmerge changes

This commit is contained in:
John Whitington 2014-11-23 20:05:03 +00:00
parent a68f225e90
commit b3ef9d16ff
2 changed files with 64 additions and 89 deletions

View File

@ -2123,7 +2123,6 @@ let stamp position fast scale_to_fit isover range over pdf =
in in
let merged = let merged =
Pdfmerge.merge_pdfs Pdfmerge.merge_pdfs
~rotations:[Pdfmerge.DNR; Pdfmerge.DNR]
false false ["a"; "b"] [pdf; over_firstpage_pdf] [pageseqs; [1]] false false ["a"; "b"] [pdf; over_firstpage_pdf] [pageseqs; [1]]
in in
let merged = let merged =
@ -2184,7 +2183,7 @@ let combine_pages (fast : bool) under over scaletofit swap equalize =
let pageseqs_under = ilist 1 (Pdfpage.endpage under) let pageseqs_under = ilist 1 (Pdfpage.endpage under)
in let pageseqs_over = ilist 1 (Pdfpage.endpage over) in in let pageseqs_over = ilist 1 (Pdfpage.endpage over) in
let merged = let merged =
Pdfmerge.merge_pdfs ~rotations: [Pdfmerge.DNR; Pdfmerge.DNR] false false ["a"; "b"] [under; over] [pageseqs_under; pageseqs_over] in Pdfmerge.merge_pdfs false false ["a"; "b"] [under; over] [pageseqs_under; pageseqs_over] in
let renamed_pdf = let renamed_pdf =
Pdfpage.change_pages true Pdfpage.change_pages true
merged (Pdfpage.renumber_pages merged (Pdfpage.pages_of_pagetree merged)) merged (Pdfpage.renumber_pages merged (Pdfpage.pages_of_pagetree merged))

View File

@ -267,8 +267,8 @@ let string_of_input_kind = function
| StdIn -> "Stdin" | StdIn -> "Stdin"
type input = type input =
input_kind * string * Pdfmerge.rotation * string * string * bool ref input_kind * string * string * string * bool ref
(* input kind, range, rotation, user_pw, owner_pw, was_decrypted_with_owner *) (* input kind, range, user_pw, owner_pw, was_decrypted_with_owner *)
type output_method = type output_method =
| NoOutputSpecified | NoOutputSpecified
@ -582,7 +582,7 @@ let operation_allowed pdf banlist op =
if args.debugcrypt then Printf.printf "Permissions: %s\n" (getpermissions pdf); if args.debugcrypt then Printf.printf "Permissions: %s\n" (getpermissions pdf);
not (banned banlist op) not (banned banlist op)
let rec decrypt_if_necessary (_, _, _, user_pw, owner_pw, was_dec_with_owner) op pdf = let rec decrypt_if_necessary (_, _, user_pw, owner_pw, was_dec_with_owner) op pdf =
if args.debugcrypt then if args.debugcrypt then
begin match op with begin match op with
None -> flprint "decrypt_if_necessary: op = None\n" None -> flprint "decrypt_if_necessary: op = None\n"
@ -675,14 +675,14 @@ let anon_fun s =
| "user" -> | "user" ->
begin match args.inputs with begin match args.inputs with
| [] -> () | [] -> ()
| (a, b, c, _, e, f)::more -> | (a, b, _, e, f)::more ->
args.inputs <- (a, b, c, implode (tl after), e, f)::more args.inputs <- (a, b, implode (tl after), e, f)::more
end end
| "owner" -> | "owner" ->
begin match args.inputs with begin match args.inputs with
| [] -> () | [] -> ()
| (a, b, c, d, _, f)::more -> | (a, b, d, _, f)::more ->
args.inputs <- (a, b, c, d, implode (tl after), f)::more args.inputs <- (a, b, d, implode (tl after), f)::more
end end
| _ -> raise Not_found | _ -> raise Not_found
end end
@ -691,39 +691,15 @@ let anon_fun s =
Not_found -> Not_found ->
try try
ignore (String.index s '.'); ignore (String.index s '.');
args.inputs <- (InFile s, "all", Pdfmerge.DNR, "", "", ref false)::args.inputs; args.inputs <- (InFile s, "all", "", "", ref false)::args.inputs;
args.original_filename <- s; args.original_filename <- s;
all_inputs := s::!all_inputs all_inputs := s::!all_inputs
with with
Not_found -> Not_found ->
match args.inputs with match args.inputs with
| [] -> () | [] -> ()
| (a, _, r, d, e, f)::t -> | (a, _, d, e, f)::t ->
match rev (explode s) with args.inputs <- (a, fixdashes s, d, e, f)::t
| 'N'::more ->
args.inputs <-
(a, fixdashes (implode (rev more)), Pdfmerge.N, d, e, f)::t
| 'S'::more ->
args.inputs <-
(a, fixdashes (implode (rev more)), Pdfmerge.S, d, e, f)::t
| 'E'::more ->
args.inputs <-
(a, fixdashes (implode (rev more)), Pdfmerge.E, d, e, f)::t
| 'W'::more ->
args.inputs <-
(a, fixdashes (implode (rev more)), Pdfmerge.W, d, e, f)::t
| 'L'::more ->
args.inputs <-
(a, fixdashes (implode (rev more)), Pdfmerge.L, d, e, f)::t
| 'R'::more ->
args.inputs <-
(a, fixdashes (implode (rev more)), Pdfmerge.R, d, e, f)::t
| 'D'::more ->
args.inputs <-
(a, fixdashes (implode (rev more)), Pdfmerge.D, d, e, f)::t
| _ ->
args.inputs <-
(a, fixdashes s, r, d, e, f)::t
(* Unit conversions to points. *) (* Unit conversions to points. *)
let mm x = ((x /. 10.) /. 2.54) *. 72. let mm x = ((x /. 10.) /. 2.54) *. 72.
@ -919,7 +895,7 @@ let displaydoctitle b =
let setsplitbookmarks i = setop (SplitOnBookmarks i) () let setsplitbookmarks i = setop (SplitOnBookmarks i) ()
let setstdout () = args.out <- Stdout let setstdout () = args.out <- Stdout
let setstdin () = args.inputs <- [StdIn, "all", Pdfmerge.DNR, "", "", ref false] let setstdin () = args.inputs <- [StdIn, "all", "", "", ref false]
let settrans s = args.transition <- Some s let settrans s = args.transition <- Some s
let setduration f = args.duration <- Some f let setduration f = args.duration <- Some f
let setvertical () = args.horizontal <- false let setvertical () = args.horizontal <- false
@ -1108,7 +1084,7 @@ let set_no_hq_print () =
let set_input s = let set_input s =
args.original_filename <- s; args.original_filename <- s;
args.inputs <- (InFile s, "all", Pdfmerge.DNR, "", "", ref false)::args.inputs; args.inputs <- (InFile s, "all", "", "", ref false)::args.inputs;
all_inputs := s::!all_inputs all_inputs := s::!all_inputs
let set_input_dir s = let set_input_dir s =
@ -1116,7 +1092,7 @@ let set_input_dir s =
args.inputs <- args.inputs <-
(rev (rev
(map (map
(fun n -> (InFile (s ^ Filename.dir_sep ^ n), "all", Pdfmerge.DNR, "", "", ref false)) names)) (fun n -> (InFile (s ^ Filename.dir_sep ^ n), "all", "", "", ref false)) names))
@ args.inputs @ args.inputs
let setdebug () = let setdebug () =
@ -1225,8 +1201,8 @@ let setextractimages () =
let setrange spec = let setrange spec =
args.dashrange <- spec; args.dashrange <- spec;
match args.inputs with match args.inputs with
(StdIn, a, b, c, d, e)::more -> (StdIn, a, c, d, e)::more ->
args.inputs <- (StdIn, spec, b, c, d, e) :: more args.inputs <- (StdIn, spec, c, d, e) :: more
| x -> () | x -> ()
let setoutline () = let setoutline () =
@ -1277,7 +1253,7 @@ let setscalestamptofit () =
let setkeepthisid () = let setkeepthisid () =
match args.inputs with match args.inputs with
| (InFile s, _, _, _, _, _)::_ -> args.keep_this_id <- Some s | (InFile s, _, _, _, _)::_ -> args.keep_this_id <- Some s
| _ -> () | _ -> ()
let setmakenewid () = let setmakenewid () =
@ -1303,12 +1279,12 @@ let setcreateobjstm () =
let setstdinuser u = let setstdinuser u =
match args.inputs with match args.inputs with
| (StdIn, x, y, _, o, f)::t -> args.inputs <- (StdIn, x, y, u, o, f)::t | (StdIn, x, _, o, f)::t -> args.inputs <- (StdIn, x, u, o, f)::t
| _ -> error "-stdin-user: must follow -stdin" | _ -> error "-stdin-user: must follow -stdin"
let setstdinowner o = let setstdinowner o =
match args.inputs with match args.inputs with
| (StdIn, x, y, u, _, f)::t -> args.inputs <- (StdIn, x, y, u, o, f)::t | (StdIn, x, u, _, f)::t -> args.inputs <- (StdIn, x, u, o, f)::t
| _ -> error "-stdin-owner: must follow -stdin" | _ -> error "-stdin-owner: must follow -stdin"
let setopenatpage n = let setopenatpage n =
@ -1890,7 +1866,7 @@ let filenames = null_hash ()
(* This now memoizes on the name of the file to make sure we only load each (* This now memoizes on the name of the file to make sure we only load each
file once *) file once *)
let get_pdf_from_input_kind ((_, _, _, u, o, _) as input) op = function let get_pdf_from_input_kind ((_, _, u, o, _) as input) op = function
| AlreadyInMemory pdf -> pdf | AlreadyInMemory pdf -> pdf
| InFile s -> | InFile s ->
if args.squeeze then if args.squeeze then
@ -1911,7 +1887,7 @@ let get_pdf_from_input_kind ((_, _, _, u, o, _) as input) op = function
let get_single_pdf op read_lazy = let get_single_pdf op read_lazy =
match args.inputs with match args.inputs with
| (InFile inname, _, _, u, o, _) as input::_ -> | (InFile inname, _, u, o, _) as input::_ ->
if args.squeeze then if args.squeeze then
Printf.printf "Initial file size is %i bytes\n" (filesize inname); Printf.printf "Initial file size is %i bytes\n" (filesize inname);
let pdf = let pdf =
@ -1922,23 +1898,23 @@ let get_single_pdf op read_lazy =
in in
args.was_encrypted <- Pdfcrypt.is_encrypted pdf; args.was_encrypted <- Pdfcrypt.is_encrypted pdf;
decrypt_if_necessary input op pdf decrypt_if_necessary input op pdf
| (StdIn, _, _, u, o, _) as input::_ -> | (StdIn, _, u, o, _) as input::_ ->
decrypt_if_necessary input op (pdf_of_stdin u o) decrypt_if_necessary input op (pdf_of_stdin u o)
| (AlreadyInMemory pdf, _, _, _, _, _)::_ -> pdf | (AlreadyInMemory pdf, _, _, _, _)::_ -> pdf
| _ -> | _ ->
raise (Arg.Bad "cpdf: No input specified.\n") raise (Arg.Bad "cpdf: No input specified.\n")
let get_single_pdf_nodecrypt read_lazy = let get_single_pdf_nodecrypt read_lazy =
match args.inputs with match args.inputs with
| (InFile inname, _, _, u, o, _)::_ -> | (InFile inname, _, u, o, _)::_ ->
if args.squeeze then if args.squeeze then
Printf.printf "Initial file size is %i bytes\n" (filesize inname); Printf.printf "Initial file size is %i bytes\n" (filesize inname);
if read_lazy then if read_lazy then
pdfread_pdf_of_channel_lazy (optstring u) (optstring o) (open_in_bin inname) pdfread_pdf_of_channel_lazy (optstring u) (optstring o) (open_in_bin inname)
else else
pdfread_pdf_of_file (optstring u) (optstring o) inname pdfread_pdf_of_file (optstring u) (optstring o) inname
| (StdIn, _, _, u, o, _)::_ -> pdf_of_stdin u o | (StdIn, _, u, o, _)::_ -> pdf_of_stdin u o
| (AlreadyInMemory pdf, _, _, _, _, _)::_ -> pdf | (AlreadyInMemory pdf, _, _, _, _)::_ -> pdf
| _ -> | _ ->
raise (Arg.Bad "cpdf: No input specified.\n") raise (Arg.Bad "cpdf: No input specified.\n")
@ -1957,7 +1933,7 @@ let really_write_pdf ?(encryption = None) ?(is_decompress=false) mk_id pdf outna
Printf.printf "Recrypting in really_write_pdf\n"; Printf.printf "Recrypting in really_write_pdf\n";
match args.inputs with match args.inputs with
[] -> raise (Pdf.PDFError "no input in recryption") [] -> raise (Pdf.PDFError "no input in recryption")
| (_, _, _, user_pw, owner_pw, _)::_ -> | (_, _, user_pw, owner_pw, _)::_ ->
let best_password = let best_password =
if owner_pw <> "" then owner_pw else user_pw if owner_pw <> "" then owner_pw else user_pw
in in
@ -1994,7 +1970,7 @@ let really_write_pdf ?(encryption = None) ?(is_decompress=false) mk_id pdf outna
in in
match args.inputs with match args.inputs with
[] -> raise (Pdf.PDFError "no input in recryption") [] -> raise (Pdf.PDFError "no input in recryption")
| (_, _, _, user_pw, owner_pw, _)::_ -> | (_, _, user_pw, owner_pw, _)::_ ->
let best_password = let best_password =
if owner_pw <> "" then owner_pw else user_pw if owner_pw <> "" then owner_pw else user_pw
in in
@ -2178,7 +2154,7 @@ let split_pdf
let get_pagespec () = let get_pagespec () =
match args.inputs with match args.inputs with
| (_, ps, _, _, _, _)::_ -> ps | (_, ps, _, _, _)::_ -> ps
| _ -> error "get_pagespec" | _ -> error "get_pagespec"
(* Copy a font from [frompdf] with name [fontname] on page [fontpage] to [pdf] on all pages in [range] *) (* Copy a font from [frompdf] with name [fontname] on page [fontpage] to [pdf] on all pages in [range] *)
@ -2884,15 +2860,15 @@ let go () =
| Some s -> | Some s ->
(* get the ID from the file with name 's', and copy to pdf *) (* get the ID from the file with name 's', and copy to pdf *)
let namewiths = let namewiths =
keep (function (InFile s', _, _, _, _, _) when s' = s -> true | _ -> false) inputs keep (function (InFile s', _, _, _, _) when s' = s -> true | _ -> false) inputs
in in
match namewiths with match namewiths with
| (namewiths, _, _, _, _, _) as input::t -> | (namewiths, _, _, _, _) as input::t ->
let spdf = get_pdf_from_input_kind input op namewiths in let spdf = get_pdf_from_input_kind input op namewiths in
write_pdf x (Cpdf.copy_id true spdf pdf) write_pdf x (Cpdf.copy_id true spdf pdf)
| _ -> write_pdf x pdf | _ -> write_pdf x pdf
in in
let names, ranges, rotations, _, _, _ = split6 inputs in let names, ranges, rotations, _, _ = split5 inputs in
let pdfs = map2 (fun i -> get_pdf_from_input_kind i op) inputs names in let pdfs = map2 (fun i -> get_pdf_from_input_kind i op) inputs names in
(* If at least one file had object streams and args.preserve_objstm is true, set -objstm-create *) (* If at least one file had object streams and args.preserve_objstm is true, set -objstm-create *)
if args.preserve_objstm then if args.preserve_objstm then
@ -2906,7 +2882,7 @@ let go () =
(* FIXME Here, if the output file is different from the (* FIXME Here, if the output file is different from the
input file, and we're just extracting pages, might we use a input file, and we're just extracting pages, might we use a
lazy read? *) lazy read? *)
if hd ranges <> "all" || hd rotations <> Pdfmerge.DNR || !Pdfpage.flat_pagetrees then if hd ranges <> "all" || !Pdfpage.flat_pagetrees then
let range = parse_pagespec pdf (hd ranges) in let range = parse_pagespec pdf (hd ranges) in
let newpdf = Pdfpage.pdf_of_pages ~retain_numbering:args.retain_numbering pdf range in let newpdf = Pdfpage.pdf_of_pages ~retain_numbering:args.retain_numbering pdf range in
write_pdf false newpdf write_pdf false newpdf
@ -2921,7 +2897,7 @@ let go () =
not not
(fold_left ( && ) true (fold_left ( && ) true
(map2 (map2
(fun (_, _, _, _, _, was_dec_with_owner) pdf -> (fun (_, _, _, _, was_dec_with_owner) pdf ->
!was_dec_with_owner || pdf.Pdf.saved_encryption = None) !was_dec_with_owner || pdf.Pdf.saved_encryption = None)
inputs inputs
pdfs)) pdfs))
@ -2931,7 +2907,7 @@ let go () =
(* If args.keep_this_id is set, change the ID to the one from the kept one *) (* If args.keep_this_id is set, change the ID to the one from the kept one *)
let rangenums = map2 parse_pagespec pdfs ranges in let rangenums = map2 parse_pagespec pdfs ranges in
let outpdf = let outpdf =
Pdfmerge.merge_pdfs ~rotations args.retain_numbering args.remove_duplicate_fonts Pdfmerge.merge_pdfs args.retain_numbering args.remove_duplicate_fonts
(map string_of_input_kind names) pdfs rangenums (map string_of_input_kind names) pdfs rangenums
in in
write_pdf false outpdf write_pdf false outpdf
@ -2954,7 +2930,7 @@ let go () =
end end
| Some (CopyFont fromfile) -> | Some (CopyFont fromfile) ->
begin match args.inputs, args.out with begin match args.inputs, args.out with
| (_, pagespec, _, u, o, _)::_, _ -> | (_, pagespec, u, o, _)::_, _ ->
let pdf = get_single_pdf (Some (CopyFont fromfile)) false let pdf = get_single_pdf (Some (CopyFont fromfile)) false
and frompdf = pdfread_pdf_of_file (optstring u) (optstring o) fromfile in and frompdf = pdfread_pdf_of_file (optstring u) (optstring o) fromfile in
let range = parse_pagespec pdf pagespec in let range = parse_pagespec pdf pagespec in
@ -2969,7 +2945,7 @@ let go () =
end end
| Some RemoveFonts -> | Some RemoveFonts ->
begin match args.inputs, args.out with begin match args.inputs, args.out with
| (_, pagespec, _, _, _, _)::_, _ -> | (_, pagespec, _, _, _)::_, _ ->
let pdf = get_single_pdf (Some RemoveFonts) false in let pdf = get_single_pdf (Some RemoveFonts) false in
write_pdf true (remove_fonts pdf) write_pdf true (remove_fonts pdf)
| _ -> error "remove fonts: bad command line" | _ -> error "remove fonts: bad command line"
@ -2977,7 +2953,7 @@ let go () =
| Some ExtractFontFile -> | Some ExtractFontFile ->
(*Graphics.open_graph " 1600x1050";*) (*Graphics.open_graph " 1600x1050";*)
begin match args.inputs, args.out with begin match args.inputs, args.out with
| (_, pagespec, _, u, o, _)::_, _ -> | (_, pagespec, u, o, _)::_, _ ->
let pdf = get_single_pdf (Some ExtractFontFile) false in let pdf = get_single_pdf (Some ExtractFontFile) false in
let page = args.copyfontpage let page = args.copyfontpage
and name = and name =
@ -2991,9 +2967,9 @@ let go () =
| Some CountPages -> | Some CountPages ->
let pdf, inname, input = let pdf, inname, input =
match args.inputs with match args.inputs with
| (InFile inname, _, _, u, o, _) as input::_ -> pdfread_pdf_of_channel_lazy (optstring u) (optstring o) (open_in_bin inname), inname, input | (InFile inname, _, u, o, _) as input::_ -> pdfread_pdf_of_channel_lazy (optstring u) (optstring o) (open_in_bin inname), inname, input
| (StdIn, _, _, u, o, _) as input::_ -> pdf_of_stdin u o, "", input | (StdIn, _, u, o, _) as input::_ -> pdf_of_stdin u o, "", input
| (AlreadyInMemory pdf, _, _, _, _, _) as input::_ -> pdf, "", input | (AlreadyInMemory pdf, _, _, _, _) as input::_ -> pdf, "", input
| _ -> raise (Arg.Bad "cpdf: No input specified.\n") | _ -> raise (Arg.Bad "cpdf: No input specified.\n")
in in
let pdf = decrypt_if_necessary input (Some CountPages) pdf in let pdf = decrypt_if_necessary input (Some CountPages) pdf in
@ -3008,10 +2984,10 @@ let go () =
| Some Info -> | Some Info ->
let pdf, inname, input = let pdf, inname, input =
match args.inputs with match args.inputs with
| (InFile inname, _, _, u, o, _) as input::_ -> | (InFile inname, _, u, o, _) as input::_ ->
pdfread_pdf_of_channel_lazy (optstring u) (optstring o) (open_in_bin inname), inname, input pdfread_pdf_of_channel_lazy (optstring u) (optstring o) (open_in_bin inname), inname, input
| (StdIn, _, _, u, o, _) as input::_ -> pdf_of_stdin u o, "", input | (StdIn, _, u, o, _) as input::_ -> pdf_of_stdin u o, "", input
| (AlreadyInMemory pdf, _, _, _, _, _) as input::_ -> pdf, "", input | (AlreadyInMemory pdf, _, _, _, _) as input::_ -> pdf, "", input
| _ -> raise (Arg.Bad "cpdf: No input specified.\n") | _ -> raise (Arg.Bad "cpdf: No input specified.\n")
in in
Printf.printf "Encryption: %s\n" (getencryption pdf); Printf.printf "Encryption: %s\n" (getencryption pdf);
@ -3023,7 +2999,7 @@ let go () =
Cpdf.output_xmp_info args.encoding pdf Cpdf.output_xmp_info args.encoding pdf
| Some PageInfo -> | Some PageInfo ->
begin match args.inputs, args.out with begin match args.inputs, args.out with
| (_, pagespec, _, _, _, _)::_, _ -> | (_, pagespec, _, _, _)::_, _ ->
let pdf = get_single_pdf args.op true in let pdf = get_single_pdf args.op true in
let range = parse_pagespec pdf pagespec in let range = parse_pagespec pdf pagespec in
Cpdf.output_page_info (get_single_pdf (Some PageInfo) true) range Cpdf.output_page_info (get_single_pdf (Some PageInfo) true) range
@ -3035,7 +3011,7 @@ let go () =
Cpdf.print_fonts (get_single_pdf (Some Fonts) true) Cpdf.print_fonts (get_single_pdf (Some Fonts) true)
| Some ListBookmarks -> | Some ListBookmarks ->
begin match args.inputs, args.out with begin match args.inputs, args.out with
| (_, pagespec, _, _, _, _)::_, _ -> | (_, pagespec, _, _, _)::_, _ ->
let pdf = get_single_pdf args.op true in let pdf = get_single_pdf args.op true in
let range = parse_pagespec pdf pagespec in let range = parse_pagespec pdf pagespec in
Cpdf.list_bookmarks args.encoding range pdf (Pdfio.output_of_channel stdout); Cpdf.list_bookmarks args.encoding range pdf (Pdfio.output_of_channel stdout);
@ -3044,7 +3020,7 @@ let go () =
end end
| Some Crop -> | Some Crop ->
begin match args.inputs, args.out with begin match args.inputs, args.out with
| (_, pagespec, _, _, _, _)::_, _ -> | (_, pagespec, _, _, _)::_, _ ->
let x, y, w, h = args.rectangle in let x, y, w, h = args.rectangle in
let pdf = get_single_pdf (Some Crop) false in let pdf = get_single_pdf (Some Crop) false in
let range = parse_pagespec pdf pagespec in let range = parse_pagespec pdf pagespec in
@ -3055,7 +3031,7 @@ let go () =
| Some MediaBox -> | Some MediaBox ->
begin match args.inputs, args.out with begin match args.inputs, args.out with
| (_, pagespec, _, _, _, _)::_, _ -> | (_, pagespec, _, _, _)::_, _ ->
let x, y, w, h = args.rectangle in let x, y, w, h = args.rectangle in
let pdf = get_single_pdf (Some MediaBox) false in let pdf = get_single_pdf (Some MediaBox) false in
let range = parse_pagespec pdf pagespec in let range = parse_pagespec pdf pagespec in
@ -3065,7 +3041,7 @@ let go () =
end end
| Some CopyBox -> | Some CopyBox ->
begin match args.inputs, args.out with begin match args.inputs, args.out with
| (_, pagespec, _, _, _, _)::_, _ -> | (_, pagespec, _, _, _)::_, _ ->
let pdf = get_single_pdf (Some CopyBox) false in let pdf = get_single_pdf (Some CopyBox) false in
let range = parse_pagespec pdf pagespec in let range = parse_pagespec pdf pagespec in
let f, t = let f, t =
@ -3093,7 +3069,7 @@ let go () =
write_pdf false (Cpdf.recompress_pdf pdf) write_pdf false (Cpdf.recompress_pdf pdf)
| Some RemoveCrop -> | Some RemoveCrop ->
begin match args.inputs, args.out with begin match args.inputs, args.out with
| (_, pagespec, _, _, _, _)::_, _ -> | (_, pagespec, _, _, _)::_, _ ->
let pdf = get_single_pdf (Some RemoveCrop) false in let pdf = get_single_pdf (Some RemoveCrop) false in
let range = parse_pagespec pdf pagespec in let range = parse_pagespec pdf pagespec in
let pdf = Cpdf.remove_cropping_pdf pdf range in let pdf = Cpdf.remove_cropping_pdf pdf range in
@ -3102,7 +3078,7 @@ let go () =
end end
| Some CopyCropBoxToMediaBox -> | Some CopyCropBoxToMediaBox ->
begin match args.inputs, args.out with begin match args.inputs, args.out with
| (_, pagespec, _, _, _, _)::_, _ -> | (_, pagespec, _, _, _)::_, _ ->
let pdf = get_single_pdf (Some CopyCropBoxToMediaBox) false in let pdf = get_single_pdf (Some CopyCropBoxToMediaBox) false in
let range = parse_pagespec pdf pagespec in let range = parse_pagespec pdf pagespec in
let pdf = copy_cropbox_to_mediabox pdf range in let pdf = copy_cropbox_to_mediabox pdf range in
@ -3111,7 +3087,7 @@ let go () =
end end
| Some (Rotate _) | Some (Rotateby _) -> | Some (Rotate _) | Some (Rotateby _) ->
begin match args.inputs, args.out with begin match args.inputs, args.out with
| (_, pagespec, _, _, _, _)::_, _ -> | (_, pagespec, _, _, _)::_, _ ->
let pdf = get_single_pdf args.op false in let pdf = get_single_pdf args.op false in
let range = parse_pagespec pdf pagespec in let range = parse_pagespec pdf pagespec in
let rotate = let rotate =
@ -3126,7 +3102,7 @@ let go () =
end end
| Some (RotateContents a) -> | Some (RotateContents a) ->
begin match args.inputs, args.out with begin match args.inputs, args.out with
| (_, pagespec, _, _, _, _)::_, _ -> | (_, pagespec, _, _, _)::_, _ ->
let pdf = get_single_pdf args.op false in let pdf = get_single_pdf args.op false in
let range = parse_pagespec pdf pagespec in let range = parse_pagespec pdf pagespec in
let pdf = Cpdf.rotate_contents ~fast:args.fast a pdf range in let pdf = Cpdf.rotate_contents ~fast:args.fast a pdf range in
@ -3135,7 +3111,7 @@ let go () =
end end
| Some Upright -> | Some Upright ->
begin match args.inputs, args.out with begin match args.inputs, args.out with
| (_, pagespec, _, _, _, _)::_, _ -> | (_, pagespec, _, _, _)::_, _ ->
let pdf = get_single_pdf args.op false in let pdf = get_single_pdf args.op false in
let range = parse_pagespec pdf pagespec in let range = parse_pagespec pdf pagespec in
let pdf = Cpdf.upright ~fast:args.fast range pdf in let pdf = Cpdf.upright ~fast:args.fast range pdf in
@ -3144,7 +3120,7 @@ let go () =
end end
| Some ((VFlip | HFlip) as flip) -> | Some ((VFlip | HFlip) as flip) ->
begin match args.inputs, args.out with begin match args.inputs, args.out with
| (_, pagespec, _, _, _, _)::_, _ -> | (_, pagespec, _, _, _)::_, _ ->
let pdf = get_single_pdf args.op false in let pdf = get_single_pdf args.op false in
let range = parse_pagespec pdf pagespec in let range = parse_pagespec pdf pagespec in
let pdf = let pdf =
@ -3209,7 +3185,7 @@ let go () =
write_pdf false (Cpdf.set_page_mode (get_single_pdf args.op false) s) write_pdf false (Cpdf.set_page_mode (get_single_pdf args.op false) s)
| Some Split -> | Some Split ->
begin match args.inputs, args.out with begin match args.inputs, args.out with
| [(f, ranges, _, _, _, _)], File output_spec -> | [(f, ranges, _, _, _)], File output_spec ->
let pdf = get_single_pdf args.op true in let pdf = get_single_pdf args.op true in
let enc = let enc =
match args.crypt_method with match args.crypt_method with
@ -3279,10 +3255,10 @@ let go () =
if args.recrypt then if args.recrypt then
soft_error "Cannot recrypt with change id: an id is part of encryption information"; soft_error "Cannot recrypt with change id: an id is part of encryption information";
begin match args.inputs, args.out with begin match args.inputs, args.out with
| [(k, _, _, _, _, _) as input], File s -> | [(k, _, _, _, _) as input], File s ->
let pdf = get_pdf_from_input_kind input args.op k in let pdf = get_pdf_from_input_kind input args.op k in
write_pdf true pdf write_pdf true pdf
| [(k, _, _, _, _, _) as input], Stdout -> | [(k, _, _, _, _) as input], Stdout ->
let pdf = get_pdf_from_input_kind input args.op k in let pdf = get_pdf_from_input_kind input args.op k in
write_pdf true pdf write_pdf true pdf
| _ -> error "ChangeId: exactly one input file and output file required." | _ -> error "ChangeId: exactly one input file and output file required."
@ -3297,7 +3273,7 @@ let go () =
if args.recrypt then if args.recrypt then
soft_error "Cannot recrypt with copy id: an id is part of encryption information"; soft_error "Cannot recrypt with copy id: an id is part of encryption information";
begin match args.inputs with begin match args.inputs with
| [(k, _, _, u, o, _) as input] -> | [(k, _, u, o, _) as input] ->
let pdf = let pdf =
Cpdf.copy_id Cpdf.copy_id
args.keepversion args.keepversion
@ -3329,7 +3305,7 @@ let go () =
write_pdf false (Cpdf.remove_annotations range pdf) write_pdf false (Cpdf.remove_annotations range pdf)
| Some (CopyAnnotations getfrom) -> | Some (CopyAnnotations getfrom) ->
begin match args.inputs with begin match args.inputs with
| [(k, _, _, u, o, _) as input] -> | [(k, _, u, o, _) as input] ->
let input_pdf = get_pdf_from_input_kind input args.op k in let input_pdf = get_pdf_from_input_kind input args.op k in
let range = parse_pagespec input_pdf (get_pagespec ()) in let range = parse_pagespec input_pdf (get_pagespec ()) in
let pdf = let pdf =
@ -3383,7 +3359,7 @@ let go () =
write_pdf false (Cpdf.remove_attached_files (get_single_pdf args.op false)) write_pdf false (Cpdf.remove_attached_files (get_single_pdf args.op false))
| Some (AttachFile files) -> | Some (AttachFile files) ->
begin match args.inputs with begin match args.inputs with
| [(k, _, _, _, _, _) as input] -> | [(k, _, _, _, _) as input] ->
let pdf = get_pdf_from_input_kind input args.op k in let pdf = get_pdf_from_input_kind input args.op k in
let topage = let topage =
try try
@ -3433,7 +3409,7 @@ let go () =
if args.prerotate then Cpdf.upright ~fast:args.fast range pdf else pdf if args.prerotate then Cpdf.upright ~fast:args.fast range pdf else pdf
and filename = and filename =
match args.inputs with match args.inputs with
| (InFile inname, _, _, _, _, _)::_ -> inname | (InFile inname, _, _, _, _)::_ -> inname
| _ -> "" | _ -> ""
in in
write_pdf false write_pdf false
@ -3545,7 +3521,7 @@ let go () =
write_pdf false (Cpdf.custom_csp2 f (get_single_pdf (Some (CSP2 f)) false)) write_pdf false (Cpdf.custom_csp2 f (get_single_pdf (Some (CSP2 f)) false))
| Some CSP3 -> | Some CSP3 ->
begin match args.inputs with begin match args.inputs with
| [InFile s, _, _, _, _, _] -> | [(InFile s, _, _, _, _)] ->
let pdf = get_single_pdf args.op true in let pdf = get_single_pdf args.op true in
let range = parse_pagespec pdf (get_pagespec ()) in let range = parse_pagespec pdf (get_pagespec ()) in
calculate_margins s pdf range calculate_margins s pdf range
@ -3629,7 +3605,7 @@ let go_withargv argv =
reset_arguments (); reset_arguments ();
parse_argv () s (align_specs specs) anon_fun usage_msg; parse_argv () s (align_specs specs) anon_fun usage_msg;
parse_argv () (Array.of_list ("cpdf"::!control_args)) (align_specs specs) anon_fun usage_msg; parse_argv () (Array.of_list ("cpdf"::!control_args)) (align_specs specs) anon_fun usage_msg;
let addrange pdf = AlreadyInMemory pdf, args.dashrange, Pdfmerge.DNR, "", "", ref false in let addrange pdf = AlreadyInMemory pdf, args.dashrange, "", "", ref false in
args.inputs <- rev (map addrange !output_pdfs) @ rev args.inputs; args.inputs <- rev (map addrange !output_pdfs) @ rev args.inputs;
output_pdfs := []; output_pdfs := [];
go ()) go ())