UTF8 for filenames stored with attached files in a PDF

This commit is contained in:
John Whitington 2020-02-07 10:58:36 +00:00
parent b33864548a
commit b54e4c84c3
1 changed files with 7 additions and 6 deletions

13
cpdf.ml
View File

@ -750,13 +750,14 @@ let attach_file ?memory keepversion topage pdf file =
Pdf.Got data)) Pdf.Got data))
in in
let filestream_num = Pdf.addobj pdf filestream in let filestream_num = Pdf.addobj pdf filestream in
let basename = Pdftext.pdfdocstring_of_utf8 (Filename.basename file) in
let filespec = let filespec =
Pdf.Dictionary Pdf.Dictionary
[("/EF", Pdf.Dictionary ["/F", Pdf.Indirect filestream_num]); [("/EF", Pdf.Dictionary ["/F", Pdf.Indirect filestream_num]);
("/F", Pdf.String (Filename.basename file)); ("/F", Pdf.String basename);
("/Type", Pdf.Name "/Filespec"); ("/Type", Pdf.Name "/Filespec");
("/Desc", Pdf.String ""); ("/Desc", Pdf.String "");
("/UF", Pdf.String (Filename.basename file))] ("/UF", Pdf.String basename)]
in in
match topage with match topage with
| None -> | None ->
@ -778,7 +779,7 @@ let attach_file ?memory keepversion topage pdf file =
| _ -> [] | _ -> []
in in
let filespecobj = Pdf.addobj pdf filespec in let filespecobj = Pdf.addobj pdf filespec in
let names' = Pdf.Array (elts @ [Pdf.String (Filename.basename file); Pdf.Indirect filespecobj]) in let names' = Pdf.Array (elts @ [Pdf.String basename; Pdf.Indirect filespecobj]) in
let embeddednamedict' = Pdf.add_dict_entry embeddednamedict "/Names" names' in let embeddednamedict' = Pdf.add_dict_entry embeddednamedict "/Names" names' in
let namedict' = Pdf.add_dict_entry namedict "/EmbeddedFiles" embeddednamedict' in let namedict' = Pdf.add_dict_entry namedict "/EmbeddedFiles" embeddednamedict' in
let rootdict' = Pdf.add_dict_entry rootdict "/Names" namedict' in let rootdict' = Pdf.add_dict_entry rootdict "/Names" namedict' in
@ -807,7 +808,7 @@ let attach_file ?memory keepversion topage pdf file =
Pdf.Dictionary Pdf.Dictionary
[("/FS", Pdf.Indirect filespecobj); [("/FS", Pdf.Indirect filespecobj);
("/Subtype", Pdf.Name "/FileAttachment"); ("/Subtype", Pdf.Name "/FileAttachment");
("/Contents", Pdf.String (Filename.basename file)); ("/Contents", Pdf.String basename);
("/Rect", rect)] ("/Rect", rect)]
in in
let annots' = Pdf.Array (annot::annots) in let annots' = Pdf.Array (annot::annots) in
@ -1331,8 +1332,8 @@ let get_bookmark_name pdf marks splitlevel n _ =
| _ -> "" | _ -> ""
(* Find the stem of a filename *) (* Find the stem of a filename *)
let stem s = (*let stem s =
implode (rev (tail_no_fail (dropwhile (neq '.') (rev (explode (Filename.basename s)))))) implode (rev (tail_no_fail (dropwhile (neq '.') (rev (explode (Filename.basename s))))))*)
(* Return list, in order, a *set* of page numbers of bookmarks at a given level *) (* Return list, in order, a *set* of page numbers of bookmarks at a given level *)
let bookmark_pages level pdf = let bookmark_pages level pdf =