From 1b9555bd231131dd8db1367d657bbd9f78d8e22b Mon Sep 17 00:00:00 2001 From: John Whitington Date: Mon, 17 Feb 2025 13:22:21 +0800 Subject: [PATCH] Add %Objnum to -extract-images to allow cross-referencing --- Changes | 1 + cpdfimage.ml | 14 +++++++++----- cpdfmanual.tex | 1 + 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Changes b/Changes index 0b0d3ec..906cac5 100644 --- a/Changes +++ b/Changes @@ -9,6 +9,7 @@ o -obj JSON output can follow a chain from each found dictionary entry * More of the PDF/UA Matterhorn verification suite implemented * Font lister now returns the font itself +o Allow %objnum in output name for -extract-images Fixes: diff --git a/cpdfimage.ml b/cpdfimage.ml index 3c78bf5..d751f65 100644 --- a/cpdfimage.ml +++ b/cpdfimage.ml @@ -128,11 +128,15 @@ let write_image ~raw ?path_to_p2p ?path_to_im pdf resources name image = let written = ref [] let extract_images_inner ~raw ?path_to_p2p ?path_to_im encoding serial pdf resources stem pnum images = - let names = map - (fun _ -> - Cpdfbookmarks.name_of_spec - encoding [] pdf 0 (stem ^ "-p" ^ string_of_int pnum) - (let r = !serial in serial := !serial + 1; r) "" 0 0) (indx images) + let names = + map + (fun image -> + (* Abuse @S *) + let stem = string_replace_all "%objnum" "@S" stem in + Cpdfbookmarks.name_of_spec + encoding [] pdf 0 (stem ^ "-p" ^ string_of_int pnum) + (let r = !serial in serial := !serial + 1; r) "" (match image with Pdf.Indirect i -> i | _ -> 0) 0) + images in iter2 (write_image ~raw ?path_to_p2p ?path_to_im pdf resources) names images diff --git a/cpdfmanual.tex b/cpdfmanual.tex index 96ff61a..c039c43 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -1,3 +1,4 @@ +%Document %objnum in -extract-images %\DocumentMetadata{lang=en, pdfversion=2.0, pdfstandard=ua-2, pdfstandard=a-4f, testphase={phase-III, title, table, math, firstaid}} \documentclass{book} % Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf,