0

I want to replace text in PDF files

and found solutions

but doesn't work.

please help me...

i using pymupdf's xref stream and get this

BT
0 0 0 0  scn
/C0_0 1 Tf
13.72 0 0 14 14.0156 76.1611 Tm
<0D1804E10632>Tj
/C0_1 1 Tf
-0.01 Tc 0.01 Tw 7.84 0 0 8 25.5322 57.7412 Tm
<001100120011000F0011001100110011000F0011001100110011>Tj
0.287 0.176 0.138 0  scn
/C0_0 1 Tf
-1.469 0.001 Td
<002E001B>Tj
0 -1.456 TD
<0026001B>Tj
0 -1.506 TD
<0038001B>Tj
0 0 0 0  scn
/C0_1 1 Tf
1.469 -0.001 Td
[<004500460054004A0048004F00430042>41 <00540046000F0044>17 <0050000F004C0053>]TJ
-1.469 -2.183 Td
<048304DD0628000108BF056909260001081905FC04B300010A7F0A57063200010011001100110001001100110011>Tj
1.214 3.689 Td
[<004500460054004A0048004F00430042>41 <00540046004C>19 <00500053>30.1 <0046004200210048004E0042>13.1 <004A004D000F0044>17 <0050004E>]TJ
0.287 0.176 0.138 0  scn
/C0_0 1 Tf
8.82 0 0 9 55.3369 76.1611 Tm
<06630A570A490581>Tj
0 0 0 0  scn
/C0_1 1 Tf
6.86 0 0 7 165.2456 107.1807 Tm
<05BE04B30561000108DA09140471000106630A570A4B07EC0A49091D>Tj
ET

and using this code


def chunks(lst, n):
    """Yield successive n-sized chunks from lst."""
    for i in range(0, len(lst), n):
        yield lst[i:i + n]

s = '048304DD0628000108BF056909260001081905FC04B300010A7F0A57063200010011001100110001001100110011'
ns = [29 + int(c, 16) for c in chunks(s, 4)]

print(bytes(ns))

but return error


Traceback (most recent call last):
  File "convert.py", line 10, in <module>
    print(bytes(ns))
ValueError: bytes must be in range(0, 256)

How do I solve this problem, and how do I encode the reverse text

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 31 '23 at 08:56
  • 1
    Text replacement in PDFs in general is complicated. Only if the source PDF is built in very special ways, you can use simple solutions like the one you found. – mkl May 31 '23 at 09:10
  • Warm welcome to SO. Please try to use correct upper case letters, e.g. in the beginning of your title, sentences or the word "I". This would be gentle to your readers. Please read [How to ask](https://stackoverflow.com/help/how-to-ask) and [Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). Then update your question with code to show us what you have tried so far. – buhtz May 31 '23 at 10:42

0 Answers0