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

Is there any way to use pdf-redactor purely from .py instead of from terminal? #25

Closed rareguy closed 4 years ago

rareguy commented 4 years ago

So, instead of setting options in pdf-redactor.py and running it through terminal with

python3 pdf-redactor.py < doc-to-redact.pdf > doc-after-redact.pdf,

we can use:

...
some options
....
dataout = b""
with open("doc-to-redact.pdf", "rb") as f:
    data = f.read()
    dataout = pdf_redactor.redactor(data, options)
with open("doc-after-redact.pdf", "wb") as f:
    f.write(dataout)

or maybe show the workaround on this? Thank you!

JoshData commented 4 years ago

Yes... example.py shows how to call the redactor from a script.

rareguy commented 4 years ago

Oh right, I misunderstood. I thought it should be a standalone .py file, which totally isn't. Already running a workaround solution by using subprocess which is really unnecessary and unsafe. Will change it to script style. Thank you!