Extending attachment functions

This commit is contained in:
John Whitington 2015-09-26 19:51:22 +01:00
parent 82cb349e92
commit a68136c6c2
2 changed files with 79 additions and 77 deletions

10
cpdf.ml
View File

@ -673,8 +673,11 @@ let presentation range t d h i dir effect_dur pdf =
Pdfpage.change_pages true pdf pages' Pdfpage.change_pages true pdf pages'
(* Attaching files *) (* Attaching files *)
let make_filestream file = let attach_file ?memory keepversion topage pdf file =
let data = let data =
match memory with
Some data -> data
| None ->
let ch = open_in_bin file in let ch = open_in_bin file in
let len = in_channel_length ch in let len = in_channel_length ch in
let stream = mkbytes len in let stream = mkbytes len in
@ -683,14 +686,13 @@ let make_filestream file =
close_in ch; close_in ch;
stream stream
in in
let filestream =
Pdf.Stream Pdf.Stream
(ref (Pdf.Dictionary (ref (Pdf.Dictionary
[("/Length", Pdf.Integer (bytes_size data)); [("/Length", Pdf.Integer (bytes_size data));
("/Type", Pdf.Name "/EmbeddedFile")], ("/Type", Pdf.Name "/EmbeddedFile")],
Pdf.Got data)) Pdf.Got data))
in
let attach_file keepversion topage pdf file =
let filestream = make_filestream file in
let filestream_num = Pdf.addobj pdf filestream in let filestream_num = Pdf.addobj pdf filestream in
let filespec = let filespec =
Pdf.Dictionary Pdf.Dictionary

View File

@ -149,7 +149,7 @@ val presentation : int list -> string option ->
(** {2 File Attachments} *) (** {2 File Attachments} *)
(** [attach_file keepversion topage pdf filename] attaches the file in [filename] to the pdf, optionally to a page (rather than document-level). If keepversion is true, the PDF version number won't be altered. *) (** [attach_file keepversion topage pdf filename] attaches the file in [filename] to the pdf, optionally to a page (rather than document-level). If keepversion is true, the PDF version number won't be altered. *)
val attach_file : bool -> int option -> Pdf.t -> string -> Pdf.t val attach_file : ?memory:Pdfio.bytes -> bool -> int option -> Pdf.t -> string -> Pdf.t
(** Remove attached files. *) (** Remove attached files. *)
val remove_attached_files : Pdf.t -> Pdf.t val remove_attached_files : Pdf.t -> Pdf.t