More attachment work
This commit is contained in:
parent
a68136c6c2
commit
20ba0b1031
10
cpdf.ml
10
cpdf.ml
|
@ -759,6 +759,11 @@ let attach_file ?memory keepversion topage pdf file =
|
|||
{pdf with
|
||||
Pdf.minor = if keepversion then pdf.Pdf.minor else max pdf.Pdf.minor 4}
|
||||
|
||||
type attachment =
|
||||
{name : string;
|
||||
pagenumber : int;
|
||||
data : int}
|
||||
|
||||
let list_attached_files pdf =
|
||||
let toplevel =
|
||||
match Pdf.lookup_direct pdf "/Root" pdf.Pdf.trailerdict with
|
||||
|
@ -770,7 +775,7 @@ let list_attached_files pdf =
|
|||
match Pdf.lookup_direct pdf "/EmbeddedFiles" namedict with
|
||||
| Some nametree ->
|
||||
map
|
||||
(function x -> x, 0)
|
||||
(function x -> {name = x; pagenumber = 0; data = 0})
|
||||
(option_map
|
||||
(function (Pdf.String s, _) -> Some s | _ -> None)
|
||||
(Pdf.contents_of_nametree pdf nametree))
|
||||
|
@ -785,7 +790,8 @@ let list_attached_files pdf =
|
|||
match Pdf.lookup_direct pdf "/Subtype" annot with
|
||||
| Some (Pdf.Name "/FileAttachment") ->
|
||||
(match Pdf.lookup_direct pdf "/Contents" annot with
|
||||
| Some (Pdf.String s) -> Some (s, pagenumber)
|
||||
| Some (Pdf.String s) ->
|
||||
Some {name = s; pagenumber; data = 0}
|
||||
| _ -> None)
|
||||
| _ -> None)
|
||||
(match Pdf.lookup_direct pdf "/Annots" page.Pdfpage.rest with
|
||||
|
|
7
cpdf.mli
7
cpdf.mli
|
@ -154,8 +154,13 @@ val attach_file : ?memory:Pdfio.bytes -> bool -> int option -> Pdf.t -> string -
|
|||
(** Remove attached files. *)
|
||||
val remove_attached_files : Pdf.t -> Pdf.t
|
||||
|
||||
type attachment =
|
||||
{name : string;
|
||||
pagenumber : int;
|
||||
data : int}
|
||||
|
||||
(** List attached files. Attachment name and page number. Page 0 is document level. *)
|
||||
val list_attached_files : Pdf.t -> (string * int) list
|
||||
val list_attached_files : Pdf.t -> attachment list
|
||||
|
||||
(** {2 Bookmarks} *)
|
||||
|
||||
|
|
|
@ -3463,8 +3463,10 @@ let go () =
|
|||
write_pdf false (Cpdf.scale_contents ~fast:args.fast args.position scale pdf range)
|
||||
| Some ListAttachedFiles ->
|
||||
let pdf = get_single_pdf args.op false in
|
||||
let names, numbers = split (Cpdf.list_attached_files pdf) in
|
||||
iter2 (Printf.printf "%i %s\n") numbers names;
|
||||
let attachments = Cpdf.list_attached_files pdf in
|
||||
iter
|
||||
(fun a -> Printf.printf "%i %s\n" a.Cpdf.pagenumber a.Cpdf.name)
|
||||
attachments;
|
||||
flprint ""
|
||||
| Some DumpAttachedFiles ->
|
||||
let pdf = get_single_pdf args.op false in
|
||||
|
|
Loading…
Reference in New Issue