Ask HN: It seems to be impossible to find-replace text in a PDF at scale?
I have a bunch of generated PDF invoices, which all have the same typo, that I'd like to fix.
So far I have tried:
* pdftk via bash script
* qpdf via bash script
* PyPDF2
* pdf-lib via node
In all cases, it appears the PDF content is not in plain text, so the text replacement fails.
Often I'm getting:
> Unsupported contents type: <class 'PyPDF2.generic.TextStringObject'>
I'm surprised it's this hard to do a find-replace inside a PDF. Isn't there a Homebrew util for this?
GPT4 has been having me write a hundred variations of scripts, but not a single one addresses the "this isn't plain text" problem.
How would you go about doing find-replace of a text string in a PDF at scale (on Mac)?
1 comment
[ 4.1 ms ] story [ 17.0 ms ] threadUnless you restrict your ambitions to a clearly defined type of PDF this mission is supposedly impossible. Have a look at https://en.wikipedia.org/wiki/PDF to get an idea what kind of input data you are actually dealing with.
PDF is a wonderful display output container at the end of the publishing chain, but nothing you'd ever desire as input for further textual manipulation.