Allow typesetting of the empty document

This commit is contained in:
John Whitington 2024-05-06 15:37:58 +08:00
parent 7e8a41fa6a
commit 65fec4d275
2 changed files with 13 additions and 11 deletions

View File

@ -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 instrs =
if instrs = [] then [] else
let firstfont = hd (keep (function Cpdftype.Font _ -> true | _ -> false) instrs) in
let instrs = [firstfont; Cpdftype.BeginDocument] @ 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

View File

@ -208,9 +208,8 @@ 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.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;