From 3cb9e52ae3906c2457fa6da7fa8ba5c0960ba2ae Mon Sep 17 00:00:00 2001 From: John Whitington Date: Thu, 28 Oct 2021 18:44:01 +0100 Subject: [PATCH] Fixed proper recursion for remove_dict_entry --- cpdf.ml | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/cpdf.ml b/cpdf.ml index de03383..af64fdf 100644 --- a/cpdf.ml +++ b/cpdf.ml @@ -4237,14 +4237,19 @@ let remove_all_text range pdf = pagenums; Pdfpage.change_pages true !pdf (rev !pages') +(* 1. Extend remove_dict_entry with search term + 2. Implement replace_dict_entry by analogy to remove_dict_entry *) +let rec remove_dict_entry_single_object f pdf = function + | (Pdf.Dictionary d) -> f (Pdf.recurse_dict (remove_dict_entry_single_object f pdf) d) + | (Pdf.Stream {contents = (Pdf.Dictionary dict, data)}) -> + f (Pdf.Stream {contents = (Pdf.recurse_dict (remove_dict_entry_single_object f pdf) dict, data)}) + | Pdf.Array a -> Pdf.recurse_array (remove_dict_entry_single_object f pdf) a + | x -> x + let remove_dict_entry pdf key = - Pdf.objselfmap - (function - (Pdf.Dictionary _ as d) | (Pdf.Stream _ as d) -> - Pdf.remove_dict_entry d key - | x -> x) - pdf; - pdf.Pdf.trailerdict <- Pdf.remove_dict_entry pdf.Pdf.trailerdict key + let f d = Pdf.remove_dict_entry d key in + Pdf.objselfmap (remove_dict_entry_single_object f pdf) pdf; + pdf.Pdf.trailerdict <- remove_dict_entry_single_object f pdf pdf.Pdf.trailerdict let replace_dict_entry pdf key value search = ()