diff --git a/Makefile b/Makefile index 17577c9..6a1e13c 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,8 @@ DOC = cpdfunicodedata cpdferror cpdfdebug cpdfjson cpdfstrftime cpdfcoord \ cpdfembed cpdffont cpdftype cpdfaddtext cpdfpad cpdfocg \ cpdfsqueeze cpdfdraft cpdfspot cpdfpagelabels cpdfcreate cpdfannot \ cpdfxobject cpdfimpose cpdfchop cpdftweak cpdftexttopdf cpdftoc \ - cpdfjpeg cpdfjpeg2000 cpdfpng cpdfimage cpdfdraw cpdfcomposition \ - cpdfshape cpdfcolours cpdfdrawcontrol cpdfprinttree cpdfua \ + cpdfjpeg cpdfjpeg2000 cpdfpng cpdfprinttree cpdfua cpdfimage cpdfdraw \ + cpdfcomposition cpdfshape cpdfcolours cpdfdrawcontrol \ cpdfcommand MODS = $(NONDOC) $(DOC) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 49dd1fa..50a5e5e 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -1025,7 +1025,7 @@ let fixdashes s = let set_input_image f s = try let fh = open_in_bin s in - let pdf = Cpdfimage.image_of_input ~subformat:args.subformat ~title:args.title f (Pdfio.input_of_channel fh) in + let pdf = Cpdfimage.image_of_input ?subformat:args.subformat ?title:args.title f (Pdfio.input_of_channel fh) in begin try close_in fh with _ -> () end; args.original_filename <- s; args.create_objstm <- true; @@ -4476,11 +4476,11 @@ let go () = begin match args.subformat with | Some Cpdfua.PDFUA1 -> begin match args.title with None -> error "Provide -title" | _ -> () end; - let pdf = Cpdfua.create_cpdfua1 (unopt args.title) args.createpdf_pagesize args.createpdf_pages in + let pdf = Cpdfua.create_pdfua1 (unopt args.title) args.createpdf_pagesize args.createpdf_pages in write_pdf false pdf | Some Cpdfua.PDFUA2 -> begin match args.title with None -> error "Provide -title" | _ -> () end; - let pdf = Cpdfua.create_cpdfua2 (unopt args.title) args.createpdf_pagesize args.createpdf_pages in + let pdf = Cpdfua.create_pdfua2 (unopt args.title) args.createpdf_pagesize args.createpdf_pages in write_pdf false pdf | None -> let pdf = Cpdfcreate.blank_document_paper args.createpdf_pagesize args.createpdf_pages in diff --git a/cpdfimage.ml b/cpdfimage.ml index e2429fa..b239c2c 100644 --- a/cpdfimage.ml +++ b/cpdfimage.ml @@ -494,7 +494,20 @@ let obj_of_jbig2_data ?global data = Pdf.Stream {contents = (Pdf.Dictionary d, Pdf.Got data)}, extra let image_of_input ?subformat ?title fobj i = - let pdf = Pdf.empty () in + let pdf = + match subformat with + | None -> Pdf.empty () + | Some Cpdfua.PDFUA1 -> + begin match title with + | None -> error "no -title given" + | Some title -> Cpdfua.create_pdfua1 title Pdfpaper.a4 1 + end + | Some Cpdfua.PDFUA2 -> + begin match title with + | None -> error "no -title given" + | Some title -> Cpdfua.create_pdfua2 title Pdfpaper.a4 1 + end + in let data = Pdfio.bytes_of_input i 0 i.Pdfio.in_channel_length in let obj, extras = fobj () data in iter (Pdf.addobj_given_num pdf) extras; diff --git a/cpdfimage.mli b/cpdfimage.mli index 040bb58..fb50ca1 100644 --- a/cpdfimage.mli +++ b/cpdfimage.mli @@ -25,7 +25,7 @@ val process : path_to_jbig2enc:string -> path_to_convert:string -> int list -> Pdf.t -> unit (**/**) -val image_of_input : ?subformat:Cpdfua.subformat option -> ?title:string option -> (unit -> Pdfio.bytes -> Pdf.pdfobject * (int * Pdf.pdfobject) list) -> Pdfio.input -> Pdf.t +val image_of_input : ?subformat:Cpdfua.subformat -> ?title:string -> (unit -> Pdfio.bytes -> Pdf.pdfobject * (int * Pdf.pdfobject) list) -> Pdfio.input -> Pdf.t val obj_of_jpeg_data : Pdfio.bytes -> Pdf.pdfobject * (int * Pdf.pdfobject) list val obj_of_png_data : Pdfio.bytes -> Pdf.pdfobject * (int * Pdf.pdfobject) list val obj_of_jbig2_data : ?global:Pdfio.bytes -> Pdfio.bytes -> Pdf.pdfobject * (int * Pdf.pdfobject) list diff --git a/cpdfua.ml b/cpdfua.ml index 9a7c40a..11d108e 100644 --- a/cpdfua.ml +++ b/cpdfua.ml @@ -1604,7 +1604,7 @@ let print_struct_tree pdf = ~get_children:(fun (E2 (_, _, cs)) -> cs) (remove_empty (remove_slashes st))) -let create_cpdfua1 title pagesize pages = +let create_pdfua1 title pagesize pages = let pdf = Cpdfcreate.blank_document_paper pagesize pages in let pdf = Cpdfmetadata.set_pdf_info ~xmp_also:false ~xmp_just_set:false ("/Title", Pdf.String title, 0) pdf in let pdf = Cpdfmetadata.create_metadata pdf in @@ -1616,7 +1616,7 @@ let create_cpdfua1 title pagesize pages = mark pdf; pdf -let create_cpdfua2 title pagesize pages = +let create_pdfua2 title pagesize pages = let pdf = Cpdfcreate.blank_document_paper pagesize pages in let pdf = Cpdfmetadata.set_pdf_info ~xmp_also:false ~xmp_just_set:false ("/Title", Pdf.String title, 0) pdf in let pdf = Cpdfmetadata.create_metadata pdf in diff --git a/cpdfua.mli b/cpdfua.mli index 3a4c758..a84126b 100644 --- a/cpdfua.mli +++ b/cpdfua.mli @@ -30,6 +30,6 @@ val extract_struct_tree : Pdf.t -> Cpdfyojson.Safe.t (** Reapply an edited JSON structure tree to its PDF. *) val replace_struct_tree : Pdf.t -> Cpdfyojson.Safe.t -> unit -val create_cpdfua1 : string -> Pdfpaper.t -> int -> Pdf.t +val create_pdfua1 : string -> Pdfpaper.t -> int -> Pdf.t -val create_cpdfua2 : string -> Pdfpaper.t -> int -> Pdf.t +val create_pdfua2 : string -> Pdfpaper.t -> int -> Pdf.t