From 60c191e60bd4cfb75f4c1e50d84ed7411d894cfc Mon Sep 17 00:00:00 2001 From: John Whitington Date: Sun, 7 May 2023 17:09:08 +0100 Subject: [PATCH] more --- cpdfdraw.ml | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/cpdfdraw.ml b/cpdfdraw.ml index 999899c..e557eff 100644 --- a/cpdfdraw.ml +++ b/cpdfdraw.ml @@ -268,13 +268,17 @@ let draw_single ~filename ~bates ~batespad fast range pdf drawops = let new_gss = update gss_resources (read_resource pdf "/ExtGState" p) in let new_xobjects = update (select_resources res.form_xobjects @ select_resources res.images) (read_resource pdf "/XObject" p) in let new_fonts = update (select_resources res.fonts) (read_resource pdf "/Font" p) in - Pdf.add_dict_entry - (Pdf.add_dict_entry - (Pdf.add_dict_entry p.Pdfpage.resources "/XObject" (Pdf.Dictionary new_xobjects)) - "/ExtGState" - (Pdf.Dictionary new_gss)) - "/Font" - (Pdf.Dictionary new_fonts) + let add_if_non_empty dict name newdict = + if newdict = Pdf.Dictionary [] then dict else + Pdf.add_dict_entry dict name newdict + in + add_if_non_empty + (add_if_non_empty + (add_if_non_empty p.Pdfpage.resources "/XObject" (Pdf.Dictionary new_xobjects)) + "/ExtGState" + (Pdf.Dictionary new_gss)) + "/Font" + (Pdf.Dictionary new_fonts) in {p with resources = new_resources}) (Pdfpage.pages_of_pagetree pdf)