want Change colour of hind vowel diacritic . #3175
Replies: 4 comments 18 replies
-
We have noticed this already and submitted a bug report to MuPDF, please see here. |
Beta Was this translation helpful? Give feedback.
-
Your problem does go back to the issue I think: |
Beta Was this translation helpful? Give feedback.
-
Here you are: |
Beta Was this translation helpful? Give feedback.
-
@JorjMcKie Hi sir, In our previous discussion, you mention you already report a bug https://bugs.ghostscript.com/show_bug.cgi?id=707560. So I have tracked this as a bug. now this bug is resolved, But still, I am not able to Redaction |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I want to change the colour of the hind vowel diacritic. I read the {#1532) Discussion and it kind of works for me only issue is they are unable to remove old diacritic. they just overlap it new over old.
my target vowel diacritic "ं". want to change colour only.
I tried both dict and rawdict methods both did not work.
I tried to search first and then change also did not work. when I tried to search they searched all diacritics on a page.
doc=fitz.open("test_pages/11022024_mtm_mp_03_1_col_r1.pdf")
page=doc[0]
search=page.search_for("ं")
print(search)
output:
[Rect(42.94731521606445, 127.79308319091797, 42.94731521606445, 141.1910858154297), Rect(501.72882080078125, 124.0313720703125, 501.72882080078125, 147.93136596679688), Rect(172.7761993408203, 306.5633544921875, 172.7761993408203, 371.8208312988281),....]
but after extraction text, it failed it gave an empty
for search in search:# loop because I have may tow many result
blocks=page.get_text("dict",clip=search)["blocks"]
print(blocks)
[]
[]
[]
Method 2:- Without search, they find and change colour but do not remove old
import fitz
import pandas as pd
from pathlib import Path
import numpy as np
doc=fitz.open("test_pages/11022024_mtm_mp_03_1_col_r1.pdf")
page=doc[0]
black = fitz.pdfcolor["black"]
blocks=page.get_text("rawdict",flags=11)["blocks"]
for block in blocks:
for lines in block["lines"]:
for span in lines["spans"]:
for char in span["chars"]:
if char["c"] == "ं" and span["color"]==15539236:
x0, y0, x1, y1 = span["bbox"] # Extract exact bounding box coordinates
rect = fitz.Rect(x0, y0, x1, y1)
print(char)
# Remove original text
# re-insert same text - different color
font = fitz.Font(fontname=span['font'],fontfile=f"{span['font']}.ttf") # this must be known somehow - or simply try some font else
page.add_redact_annot(rect,fontname=font,align=char["origin"])
tw = fitz.TextWriter(page.rect, color=black)
tw.append(char["origin"], text=char["c"], font=font,fontsize=span['size'])
tw.write_text(page)
Apply redactions after all text replacements
page.apply_redactions()
Saving Option
out_filename=Path('out') /"11022024_mtm_mp_03_2_col_r2.pdf"
save to a new PDF
doc.ez_save(out_filename)
original PDF
11022024_mtm_mp_01_1_col_r1.pdf
after PDF
11022024_mtm_mp_03_2_col_r2.pdf
Beta Was this translation helpful? Give feedback.
All reactions