Finished off -dump-attachments
This commit is contained in:
parent
7a00d45b3e
commit
293af1ed9f
12
cpdf.ml
12
cpdf.ml
|
@ -2192,7 +2192,7 @@ let change_boxes f pdf page =
|
||||||
alter any /Matrix entries in pattern dictionaries for tiled and shading
|
alter any /Matrix entries in pattern dictionaries for tiled and shading
|
||||||
patterns. In addition, shadings used by Op_sh in the main page content and in
|
patterns. In addition, shadings used by Op_sh in the main page content and in
|
||||||
xobjects must be altered. *)
|
xobjects must be altered. *)
|
||||||
(*let rec change_shadings pdf tr resources =
|
let rec change_shadings pdf tr resources =
|
||||||
let transform_shading s =
|
let transform_shading s =
|
||||||
s
|
s
|
||||||
in
|
in
|
||||||
|
@ -2235,11 +2235,13 @@ xobjects must be altered. *)
|
||||||
| _ -> resources
|
| _ -> resources
|
||||||
end
|
end
|
||||||
with
|
with
|
||||||
_ -> resources*)
|
_ ->
|
||||||
|
Printf.eprintf "Error in change_shadings: returning default resources\n";
|
||||||
|
resources
|
||||||
|
|
||||||
let change_pattern_matrices pdf tr resources =
|
let change_pattern_matrices pdf tr resources =
|
||||||
try
|
try
|
||||||
(*let resources = change_shadings pdf tr resources in*)
|
let resources = change_shadings pdf tr resources in
|
||||||
begin match Pdf.lookup_direct pdf "/Pattern" resources with
|
begin match Pdf.lookup_direct pdf "/Pattern" resources with
|
||||||
| Some (Pdf.Dictionary patterns) ->
|
| Some (Pdf.Dictionary patterns) ->
|
||||||
let names, nums =
|
let names, nums =
|
||||||
|
@ -2262,7 +2264,9 @@ let change_pattern_matrices pdf tr resources =
|
||||||
| _ -> resources
|
| _ -> resources
|
||||||
end
|
end
|
||||||
with
|
with
|
||||||
Pdftransform.NonInvertable -> resources
|
Pdftransform.NonInvertable ->
|
||||||
|
Printf.eprintf "Warning: noninvertible matrix";
|
||||||
|
resources
|
||||||
|
|
||||||
(* Apply transformations to any annotations in /Annots (i.e their /Rect entries) *)
|
(* Apply transformations to any annotations in /Annots (i.e their /Rect entries) *)
|
||||||
let transform_annotations pdf transform rest =
|
let transform_annotations pdf transform rest =
|
||||||
|
|
|
@ -1513,10 +1513,10 @@ let setimageresolution f =
|
||||||
let setgspath p =
|
let setgspath p =
|
||||||
args.path_to_ghostscript <- p
|
args.path_to_ghostscript <- p
|
||||||
|
|
||||||
let setvertical () =
|
let settextvertical () =
|
||||||
args.orientation <- Cpdf.Vertical
|
args.orientation <- Cpdf.Vertical
|
||||||
|
|
||||||
let setverticaldown () =
|
let settextverticaldown () =
|
||||||
args.orientation <- Cpdf.VerticalDown
|
args.orientation <- Cpdf.VerticalDown
|
||||||
|
|
||||||
let setfrombox s =
|
let setfrombox s =
|
||||||
|
@ -2164,7 +2164,7 @@ and specs =
|
||||||
" List attached files");
|
" List attached files");
|
||||||
("-dump-attachments",
|
("-dump-attachments",
|
||||||
Arg.Unit (setop DumpAttachedFiles),
|
Arg.Unit (setop DumpAttachedFiles),
|
||||||
"");
|
" Dump attachments to disk");
|
||||||
("-attach-file",
|
("-attach-file",
|
||||||
Arg.String setattachfile,
|
Arg.String setattachfile,
|
||||||
" Attach a file");
|
" Attach a file");
|
||||||
|
@ -2282,8 +2282,8 @@ and specs =
|
||||||
("-csp1", Arg.Unit (setop CSP1), "");
|
("-csp1", Arg.Unit (setop CSP1), "");
|
||||||
("-csp2", Arg.Float setcsp2, "");
|
("-csp2", Arg.Float setcsp2, "");
|
||||||
("-csp3", Arg.Unit (setop CSP3), "");
|
("-csp3", Arg.Unit (setop CSP3), "");
|
||||||
("-text-vertical", Arg.Unit setvertical, "");
|
("-text-vertical", Arg.Unit settextvertical, "");
|
||||||
("-text-vertical-down", Arg.Unit setverticaldown, "");
|
("-text-vertical-down", Arg.Unit settextverticaldown, "");
|
||||||
("-flat-kids", Arg.Unit setflatkids, "");
|
("-flat-kids", Arg.Unit setflatkids, "");
|
||||||
("-debug", Arg.Unit setdebug, "");
|
("-debug", Arg.Unit setdebug, "");
|
||||||
("-debug-crypt", Arg.Unit setdebugcrypt, "");
|
("-debug-crypt", Arg.Unit setdebugcrypt, "");
|
||||||
|
@ -2673,8 +2673,7 @@ let write_pdf ?(encryption = None) ?(is_decompress=false) mk_id pdf =
|
||||||
end;
|
end;
|
||||||
flush stdout (*r For Windows *)
|
flush stdout (*r For Windows *)
|
||||||
|
|
||||||
(* Returns empty string on failure. Should only be used in conjunction with
|
(* Remove characters which might not make good filenames. *)
|
||||||
split at bookmarks code, so should never fail, by definiton. *)
|
|
||||||
let remove_unsafe_characters s =
|
let remove_unsafe_characters s =
|
||||||
if args.encoding = Cpdf.Raw then s else
|
if args.encoding = Cpdf.Raw then s else
|
||||||
let chars =
|
let chars =
|
||||||
|
@ -3342,11 +3341,15 @@ let dump_attachment out pdf (_, embeddedfile) =
|
||||||
| _ -> error "Bad embedded file stream"
|
| _ -> error "Bad embedded file stream"
|
||||||
end
|
end
|
||||||
in
|
in
|
||||||
let filename = if out = "" then s else out ^ "/" ^ s in (* FIXME dirsep! *)
|
let s = remove_unsafe_characters s in
|
||||||
(*i Printf.printf "writing to %s\n" filename; i*)
|
let filename = if out = "" then s else out ^ Filename.dir_sep ^ s in
|
||||||
|
begin try
|
||||||
let fh = open_out_bin filename in
|
let fh = open_out_bin filename in
|
||||||
for x = 0 to bytes_size efdata - 1 do output_byte fh (bget efdata x) done;
|
for x = 0 to bytes_size efdata - 1 do output_byte fh (bget efdata x) done;
|
||||||
close_out fh
|
close_out fh
|
||||||
|
with
|
||||||
|
e -> Printf.eprintf "Failed to write attachment to %s\n" filename;
|
||||||
|
end
|
||||||
| _ -> ()
|
| _ -> ()
|
||||||
|
|
||||||
let dump_attached_document pdf out =
|
let dump_attached_document pdf out =
|
||||||
|
@ -3382,7 +3385,7 @@ let dump_attached_files pdf out =
|
||||||
dump_attached_document pdf out;
|
dump_attached_document pdf out;
|
||||||
iter (dump_attached_page pdf out) (Pdfpage.pages_of_pagetree pdf)
|
iter (dump_attached_page pdf out) (Pdfpage.pages_of_pagetree pdf)
|
||||||
with
|
with
|
||||||
_ -> error "Couldn't dump attached files"
|
e -> error (Printf.sprintf "Couldn't dump attached files: %s\n" (Printexc.to_string e))
|
||||||
|
|
||||||
(* If pages in stamp < pages in main, extend stamp by repeating its last page. If pages in stamp more, chop stamp *)
|
(* If pages in stamp < pages in main, extend stamp by repeating its last page. If pages in stamp more, chop stamp *)
|
||||||
let equalize_pages_extend main stamp =
|
let equalize_pages_extend main stamp =
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
%FIXME: Distinguish properly between options and operations throughout manual.
|
%FIXME: Distinguish properly between options and operations throughout manual.
|
||||||
%FIXME: Finish and document -dump-attachments.
|
%FIXME: Document -dump-attachments.
|
||||||
%FIXME: Mention that OpenAction supersedes PageLayout so use -remove-dict-option to get rid of it
|
%FIXME: Mention that OpenAction supersedes PageLayout so use -remove-dict-option to get rid of it
|
||||||
%FIXME: Document new -hard-box option
|
%FIXME: Document new -hard-box option
|
||||||
%FIXME: Document that -upright also shifts the page to 0,0
|
%FIXME: Document that -upright also shifts the page to 0,0
|
||||||
|
|
Loading…
Reference in New Issue