Retreiving data from attachments finished

This commit is contained in:
John Whitington 2015-09-28 16:40:19 +01:00
parent 36df106ec0
commit 330f78076e
1 changed files with 21 additions and 5 deletions

26
cpdf.ml
View File

@ -775,12 +775,28 @@ let list_attached_files pdf =
match Pdf.lookup_direct pdf "/EmbeddedFiles" namedict with match Pdf.lookup_direct pdf "/EmbeddedFiles" namedict with
| Some nametree -> | Some nametree ->
map map
(function x -> (function (x, ef) ->
{name = x; match Pdf.lookup_direct pdf "/EF" ef with
pagenumber = 0; | Some ((Pdf.Dictionary _) as d) ->
data = (fun () -> Pdfio.mkbytes 0)}) begin match Pdf.lookup_direct pdf "/F" d with
| Some stream ->
{name = x;
pagenumber = 0;
data =
(fun () ->
try
Pdf.getstream stream;
Pdfcodec.decode_pdfstream pdf stream;
match stream with
Pdf.Stream {contents = (_, Pdf.Got data)} -> data
| _ -> raise Not_found
with
_ -> raise (Pdf.PDFError "could not retreive attachment data"))}
| None -> raise (Pdf.PDFError "/F not found")
end
| _ -> raise (Pdf.PDFError "/EF not found"))
(option_map (option_map
(function (Pdf.String s, _) -> Some s | _ -> None) (function (Pdf.String s, ef) -> Some (s, ef) | _ -> None)
(Pdf.contents_of_nametree pdf nametree)) (Pdf.contents_of_nametree pdf nametree))
| _ -> [] | _ -> []
in let pagelevel = in let pagelevel =