So you want to modify the text of a PDF by hand (2020)
gist.github.com
So you want to modify the text of a PDF by hand (2020)
1–10 of 103 posts
Re: So you want to modify the text of a PDF by hand (2020)
#2Re: So you want to modify the text of a PDF by hand (2020)
#3Although this is an interesting dive into the PDF format, just opening the PDF in Libreoffice or Inkscape usually works fine to modify its text.
Re: So you want to modify the text of a PDF by hand (2020)
#4Although this is an interesting dive into the PDF format, just opening the PDF in Libreoffice or Inkscape usually works fine to modify its text.
I’m interested in extracting the contents of a pdf form — many individual text boxes. You’re saying libre office would likely be able to parse that pdf into a usable format?
Re: So you want to modify the text of a PDF by hand (2020)
#5They are a graph of objects of different types. The types themselves are well described in the official spec (I’m a sadist, I read it for fun).
My advice is always to convert the pdf to a version without compressed data like the author here has. My tool of choice is mutool (mutool clean -d in.pdf out.pdf). Then just have a rummage. You’ll be surprised by how much you can follow.
In the article the author missed a step where you look at the page object to see the resources. That’s where the mapping from the font name use in the content stream to the underlying object is made.
There’s also another important bit missing - most fonts are subset into the pdf. Ie, only the glyphs that are needed are maintained in the font. I think that’s often where the re-encoding happens. ToUnicode is maintained to allow you to copy text (or search in a PDF). It’s a nice to have for users (in my experience it’s normally there and correct though).
Re: So you want to modify the text of a PDF by hand (2020)
#6Re: So you want to modify the text of a PDF by hand (2020)
#7Although this is an interesting dive into the PDF format, just opening the PDF in Libreoffice or Inkscape usually works fine to modify its text.
I’m interested in extracting the contents of a pdf form — many individual text boxes. You’re saying libre office would likely be able to parse that pdf into a usable format?
Re: So you want to modify the text of a PDF by hand (2020)
#8If you modify things within the file, typically these offsets will change and the file will be corrupt. It looks like in this article, maybe they were only interested in changing one number to another, so none of the positions change.
But, generally, adding/removing/modifying things in the middle of the file require recomputing the xref table and thus become much easier to use a library rather than direct text editing.
Re: So you want to modify the text of a PDF by hand (2020)
#9https://qpdf.readthedocs.io/en/stable/overview.html
It turns a PDF (typically everything in it is compressed binary blobs) into a mixed binary/ASCII file (which itself is a PDF) that can be edited with vim.
Re: So you want to modify the text of a PDF by hand (2020)
#10This topic comes up periodically as most people think PDFs are some impenetrable binary format, but they’re really not. They are a graph of objects of different types. The types themselves are well described in the official spec (I’m a sadist, I read it for fun). My advice is always to convert the pdf to a version without compressed data like the author here has. My tool of choice is mutool (mutool clean -d in.pdf ou…
Their design philosophy of creating a read-only format was flawed to begin with. What's the first feature people are going to ask for??