I was wondering how to view and edit the code of a PDF file?
-
By viewing, I don't want to see the binary format, so I think
hexdump
may not be what I want. I triedgedit
,
but no encoding method can be used to decode the PDF content. -
By editing, I would like to search for
/Fit
and change them to
/XYZ
by for example sed. But my commandsed s/\/Fit/\/XYZ/ < 1.pdf > 2.pdf
seem not change the appearance of my PDF as I expected,
although it doesn't report any error. I was wondering ifsed
can
actually work on PDF files as if they were plain text?
The context of my questions can be found from this question. My OS is Ubuntu 10.10.
Best Answer
You can use
sed
with binary files (at least GNU sed; some implementations may have trouble with files containing null characters or not ending with a newline character). But the command you used only replaces the first occurrence of/Fit
on each line, and lines are pretty much meaningless in a PDF file. You need to replace all occurrences:It would be more robust only replace
/Fit
if it's not followed by a word constituent (e.g. not replacing/Fitness
; I don't know if your file contains occurrences of/Fit
that would cause trouble). Here's one way: