From 188ecd20f2dd85e01fee4fc09f4705c6d529f997 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Mon, 9 Sep 2024 18:43:24 +0100 Subject: [PATCH] First structure tree showing in WNI --- cpdfdraw.ml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/cpdfdraw.ml b/cpdfdraw.ml index 1026548..630dddc 100644 --- a/cpdfdraw.ml +++ b/cpdfdraw.ml @@ -477,14 +477,18 @@ let write_structure_tree pdf st = let items = map (function StItem {kind; pageobjnum; children} -> - Pdf.Dictionary [("/S", Pdf.Name kind); - ("/Pg", Pdf.Indirect pageobjnum); - ("/P", Pdf.Indirect struct_tree_root); - ("/K", Pdf.Array (map (function StMCID x -> - let n = Pdf.addobj pdf (Pdf.Integer x) in - parentmap =| (string_of_int x, Pdf.Indirect n); - Pdf.Indirect (Pdf.addobj pdf (Pdf.Integer x)) - | _ -> assert false) children))] + let this_objnum = Pdf.addobj pdf Pdf.Null in + let this_obj = + Pdf.Dictionary [("/S", Pdf.Name kind); + ("/Pg", Pdf.Indirect pageobjnum); + ("/P", Pdf.Indirect struct_tree_root); + ("/K", Pdf.Array (map (function StMCID x -> + parentmap =| (string_of_int x, Pdf.Array [Pdf.Indirect this_objnum]); + Pdf.Integer x + | _ -> assert false) children))] + in + Pdf.addobj_given_num pdf (this_objnum, this_obj); + Pdf.Indirect this_objnum | _ -> assert false ) st