Skip to content

Highlighting issue distorted on recent versions #4245

Closed
@sadaqabdo

Description

@sadaqabdo

Edited:

Description of the bug

When rendering the same content, I observed a noticeable difference in text highlighting appearance between a system using the Rocky Linux 9 base image and systems running on macOS or Linux Ubuntu.
The issue is not related to the platform but rather to changes in the PyMuPDF version. Specifically, the problem arises due to how recent MuPDF versions handle font override values in the PDF.

On Rocky Linux 9, the text appears slightly distorted, with misaligned or inconsistent lines.
On macOS/Ubuntu, the text renders correctly and appears as expected.

Image

macOS/Ubuntu

Image

Steps to Reproduce:

  • Use the following Python script to highlight text in a PDF.
  1. Run the script in pymupdf==1.24.x and pymupdf==1.25.x
  2. Compare the resulting PDFs to observe the difference
import fitz


def highlight_text_in_pdf(input_pdf, output_pdf, text_to_highlight):
    pdf_document = fitz.open(input_pdf)
    for page_number in range(len(pdf_document)):
        page = pdf_document[page_number]
        text_instances = page.search_for(text_to_highlight)
        for inst in text_instances:
            highlight = page.add_highlight_annot(inst)
            if highlight:
                highlight.update()

    pdf_document.save(output_pdf)
    pdf_document.close()


input_pdf_path = "Bart-Simpson.pdf"
output_pdf_path = "Bart-Simpson-highlighted.pdf"

text_to_search = "Bart Simpson"

highlight_text_in_pdf(input_pdf_path, output_pdf_path, text_to_search)

the file:
Bart-Simpson.pdf

Bart-Simpson.pdf

PyMuPDF version

1.25.2

Operating system

Other

Python version

3.12

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions