0

Assume a pdf document that contains text highlights on pages 1, 3 and 14. Is there a Linux command-line tool (or a set of tools whose output can be piped to each other) that can report the page numbers of those pages that contain highlighted text? Something like:

$ sought_tool --list-pages-with-highlights doc.pdf
1 3 14
3
  • There are a number of ways you can highlight in PDF files, so any tool that exists may not succeed in catching all types. I’m not aware of any tool that does this. I’m also aware of many tools that interfere or removed (incorrectly) other highlighting or annotations when editing a pdf. So your mileage may vary. Nov 14, 2022 at 22:20
  • @JamesRisner I understand that there is no one-size-fits-all solution for PDF highlights and would be happy to be recommended any tool that returns page numbers for highlighted pages, even if it works sub-optimally. Nov 14, 2022 at 23:35
  • I have used a ton of tools (mtools, cpdf, qpdf, pdktk, etc.) I don't recall any of them doing much with highlighted text. So I can't help unfortunately. Nov 15, 2022 at 0:43

1 Answer 1

1

The nifty little Python library pdfannots has exactly the desired capability.

$ pdfannots doc.pdf

If combined with grep and awk it can produce the desired result.

$ pdfannots doc.pdf | \
  grep "* Page #" | \
  awk -F':' '{print $1}' | \
  awk -F'#' '{print $2}' | \
  sort -u -n | \
  paste -s -d ' '
1 3 14
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .