This forum has been archived. All content is frozen. Please use KDE Discuss instead.
Please use bugs.kde.org for bug reports or feature requests. Development related questions should be directed to the okular-devel mailing list.

Okular highlight words command line

Tags: None
(comma "," separated)
josephme
Registered Member
Posts
1
Karma
0

Okular highlight words command line

Thu Jul 21, 2022 6:28 pm
Hi All.

Newbie here. I like to highlight certain words in a PDF document via the command line in Ubuntu. I have a lot of words I like to highlight in a PDF document.

Better yet if available: I have a text file with words, one word per line. Is there a way to tell Okular to read the words in the text file and highlight all these words in the PDF document in yellow?

If not, I can do it one word at a time but I need to do it via the command line - one word at a time.

Or is this not possible with Okular?

Thank you!
User avatar
pvzh
Registered Member
Posts
24
Karma
1
OS
Hello! You can search and highlight any phrase from the command line:
Code: Select all
okular --find "some phrase" filename.pdf

Other available command line options can be viewed via
Code: Select all
okular --help
User avatar
pvzh
Registered Member
Posts
24
Karma
1
OS
Perhaps the annotation mechanism in PDF would be suitable for your task. It is not difficult to add annotations to a PDF file programmatically, for example with a Python script:
Code: Select all
import fitz

highlights = ["data", "load"]

doc = fitz.open("input.pdf")
for page in doc:
    for text in highlights:
        quads = page.search_for(text, quads=True)
        for quad in quads:
            annot = page.add_highlight_annot(quad)
            annot.update()

doc.save("output.pdf")

https://pymupdf.readthedocs.io/en/lates ... tions.html


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]