Extending attachment functions
This commit is contained in:
parent
82cb349e92
commit
a68136c6c2
10
cpdf.ml
10
cpdf.ml
|
@ -673,8 +673,11 @@ let presentation range t d h i dir effect_dur pdf =
|
|||
Pdfpage.change_pages true pdf pages'
|
||||
|
||||
(* Attaching files *)
|
||||
let make_filestream file =
|
||||
let attach_file ?memory keepversion topage pdf file =
|
||||
let data =
|
||||
match memory with
|
||||
Some data -> data
|
||||
| None ->
|
||||
let ch = open_in_bin file in
|
||||
let len = in_channel_length ch in
|
||||
let stream = mkbytes len in
|
||||
|
@ -683,14 +686,13 @@ let make_filestream file =
|
|||
close_in ch;
|
||||
stream
|
||||
in
|
||||
let filestream =
|
||||
Pdf.Stream
|
||||
(ref (Pdf.Dictionary
|
||||
[("/Length", Pdf.Integer (bytes_size data));
|
||||
("/Type", Pdf.Name "/EmbeddedFile")],
|
||||
Pdf.Got data))
|
||||
|
||||
let attach_file keepversion topage pdf file =
|
||||
let filestream = make_filestream file in
|
||||
in
|
||||
let filestream_num = Pdf.addobj pdf filestream in
|
||||
let filespec =
|
||||
Pdf.Dictionary
|
||||
|
|
2
cpdf.mli
2
cpdf.mli
|
@ -149,7 +149,7 @@ val presentation : int list -> string option ->
|
|||
|
||||
(** {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. *)
|
||||
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. *)
|
||||
val remove_attached_files : Pdf.t -> Pdf.t
|
||||
|
|
Loading…
Reference in New Issue