Allow typesetting of the empty document
This commit is contained in:
parent
7e8a41fa6a
commit
65fec4d275
|
@ -56,8 +56,11 @@ let typeset ~papersize ~font ~fontsize text =
|
|||
in
|
||||
let instrs = of_utf8_with_newlines fontpack fontsize (Pdfio.string_of_bytes text) in
|
||||
let margin = Pdfunits.points (Pdfpaper.width papersize) (Pdfpaper.unit papersize) /. 15. in
|
||||
let firstfont = hd (keep (function Cpdftype.Font _ -> true | _ -> false) instrs) in
|
||||
let instrs = [firstfont; Cpdftype.BeginDocument] @ instrs in
|
||||
let instrs =
|
||||
if instrs = [] then [] else
|
||||
let firstfont = hd (keep (function Cpdftype.Font _ -> true | _ -> false) instrs) in
|
||||
[firstfont; Cpdftype.BeginDocument] @ instrs
|
||||
in
|
||||
let pages = Cpdftype.typeset margin margin margin margin papersize pdf instrs in
|
||||
let pdf, pageroot = Pdfpage.add_pagetree pages pdf in
|
||||
Pdfpage.add_root pageroot [] pdf
|
||||
|
|
17
cpdftype.ml
17
cpdftype.ml
|
@ -208,15 +208,14 @@ let typeset lmargin rmargin tmargin bmargin papersize pdf i =
|
|||
let thisdestrectangles = ref [] in
|
||||
let pages = ref [] in
|
||||
let write_page () =
|
||||
if !ops <> [] then
|
||||
let page =
|
||||
{Pdfpage.content = [Pdfops.stream_of_ops (rev !ops)];
|
||||
Pdfpage.mediabox = Pdfpage.rectangle_of_paper papersize;
|
||||
Pdfpage.resources = make_resources !thispagefontnums;
|
||||
Pdfpage.rotate = Pdfpage.Rotate0;
|
||||
Pdfpage.rest = make_annotations pdf !thispageannotations}
|
||||
in
|
||||
pages := page :: !pages
|
||||
let page =
|
||||
{Pdfpage.content = if !ops = [] then [] else [Pdfops.stream_of_ops (rev !ops)];
|
||||
Pdfpage.mediabox = Pdfpage.rectangle_of_paper papersize;
|
||||
Pdfpage.resources = make_resources !thispagefontnums;
|
||||
Pdfpage.rotate = Pdfpage.Rotate0;
|
||||
Pdfpage.rest = make_annotations pdf !thispageannotations}
|
||||
in
|
||||
pages := page :: !pages
|
||||
in
|
||||
let rec typeset_element = function
|
||||
| Text cps ->
|
||||
|
|
Loading…
Reference in New Issue