JoshData / pdf-redactor

A general purpose PDF text-layer redaction tool for Python 2/3.
Creative Commons Zero v1.0 Universal
180 stars 61 forks source link

pdf-redactor failing to perform string substitution #16

Open 0xCoto opened 5 years ago

0xCoto commented 5 years ago

So, I have a PDF file (the small text says aaa): https://cdn.discordapp.com/attachments/283280590860582912/521025782664003584/r.png

I want to replace aaa with "test123".

My code is this:

#;encoding=utf-8

import re
from datetime import datetime

import pdf_redactor

options = pdf_redactor.RedactorOptions()

options.content_filters = [
    # First convert all dash-like characters to dashes.
    (
        re.compile(r"aaa"),
        lambda m : "test123"
    ),
]

pdf_redactor.redactor(options)

(If https://github.com/JoshData/pdf-redactor/blob/master/example.py works, why doesn't my script work?)

(Using Python3.7)

hibellm commented 5 years ago

I am not an expert at this but it worked for my example when I added U in front

options.content_filters = [   
    (
        re.compile(u"LibreOffice"),
        lambda m: "(REDACTED)"
    ),
]