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'
|
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
|
||||||
|
|
2
cpdf.mli
2
cpdf.mli
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue