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
|
in
|
||||||
let instrs = of_utf8_with_newlines fontpack fontsize (Pdfio.string_of_bytes 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 margin = Pdfunits.points (Pdfpaper.width papersize) (Pdfpaper.unit papersize) /. 15. in
|
||||||
let firstfont = hd (keep (function Cpdftype.Font _ -> true | _ -> false) instrs) in
|
let instrs =
|
||||||
let instrs = [firstfont; Cpdftype.BeginDocument] @ instrs in
|
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 pages = Cpdftype.typeset margin margin margin margin papersize pdf instrs in
|
||||||
let pdf, pageroot = Pdfpage.add_pagetree pages pdf in
|
let pdf, pageroot = Pdfpage.add_pagetree pages pdf in
|
||||||
Pdfpage.add_root pageroot [] pdf
|
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 thisdestrectangles = ref [] in
|
||||||
let pages = ref [] in
|
let pages = ref [] in
|
||||||
let write_page () =
|
let write_page () =
|
||||||
if !ops <> [] then
|
let page =
|
||||||
let page =
|
{Pdfpage.content = if !ops = [] then [] else [Pdfops.stream_of_ops (rev !ops)];
|
||||||
{Pdfpage.content = [Pdfops.stream_of_ops (rev !ops)];
|
Pdfpage.mediabox = Pdfpage.rectangle_of_paper papersize;
|
||||||
Pdfpage.mediabox = Pdfpage.rectangle_of_paper papersize;
|
Pdfpage.resources = make_resources !thispagefontnums;
|
||||||
Pdfpage.resources = make_resources !thispagefontnums;
|
Pdfpage.rotate = Pdfpage.Rotate0;
|
||||||
Pdfpage.rotate = Pdfpage.Rotate0;
|
Pdfpage.rest = make_annotations pdf !thispageannotations}
|
||||||
Pdfpage.rest = make_annotations pdf !thispageannotations}
|
in
|
||||||
in
|
pages := page :: !pages
|
||||||
pages := page :: !pages
|
|
||||||
in
|
in
|
||||||
let rec typeset_element = function
|
let rec typeset_element = function
|
||||||
| Text cps ->
|
| Text cps ->
|
||||||
|
|
Loading…
Reference in New Issue