This commit is contained in:
John Whitington 2022-09-21 15:30:28 +01:00
parent d030bc7e74
commit c08b0351ca
3 changed files with 6 additions and 5 deletions

View File

@ -3998,15 +3998,16 @@ let go () =
write_pdf false pdf write_pdf false pdf
| Some (Typeset filename) -> | Some (Typeset filename) ->
let text = Pdfio.bytes_of_input_channel (open_in filename) in let text = Pdfio.bytes_of_input_channel (open_in filename) in
let pdf = Pdf.empty () in
let font = let font =
match args.font with match args.font with
| StandardFont f -> Pdftext.StandardFont (f, Pdftext.WinAnsiEncoding) | StandardFont f -> Pdftext.StandardFont (f, Pdftext.WinAnsiEncoding)
| FontToEmbed (fontfile, encoding) -> | FontToEmbed (fontfile, encoding) ->
Cpdfembed.embed_truetype (Pdf.empty ()) ~fontfile ~fontname:args.fontname ~codepoints:[] ~encoding Cpdfembed.embed_truetype pdf ~fontfile ~fontname:args.fontname ~codepoints:[] ~encoding
| _ -> error "text to PDF: not a standard or embedded font" | _ -> error "text to PDF: not a standard or embedded font"
in in
let pdf = let pdf =
Cpdftexttopdf.typeset ~papersize:args.createpdf_pagesize ~font ~fontsize:args.fontsize text Cpdftexttopdf.typeset ~pdf:pdf ~papersize:args.createpdf_pagesize ~font ~fontsize:args.fontsize text
in in
write_pdf false pdf write_pdf false pdf

View File

@ -28,9 +28,9 @@ let rec of_utf8_with_newlines charcode_extractor t =
if c <> [] then items := Text (charcodes_of_codepoints c)::!items; if c <> [] then items := Text (charcodes_of_codepoints c)::!items;
rev !items rev !items
let typeset ~papersize ~font ~fontsize text = let typeset ?pdf ~papersize ~font ~fontsize text =
let charcode_extractor = Pdftext.charcode_extractor_of_font_real font in let charcode_extractor = Pdftext.charcode_extractor_of_font_real font in
let pdf = Pdf.empty () in let pdf = match pdf with None -> Pdf.empty () | Some pdf -> pdf in
let margin = let margin =
Pdfunits.convert Pdfunits.convert
72. (Pdfpaper.unit papersize) (Pdfunits.PdfPoint) (Pdfpaper.width papersize) /. 15. 72. (Pdfpaper.unit papersize) (Pdfunits.PdfPoint) (Pdfpaper.width papersize) /. 15.

View File

@ -1,4 +1,4 @@
(** Text to PDF *) (** Text to PDF *)
(** Typeset a text file as a PDF. *) (** Typeset a text file as a PDF. *)
val typeset : papersize:Pdfpaper.t -> font:Pdftext.font -> fontsize:float -> Pdfio.bytes -> Pdf.t val typeset : ?pdf:Pdf.t -> papersize:Pdfpaper.t -> font:Pdftext.font -> fontsize:float -> Pdfio.bytes -> Pdf.t