Is there a way to blacken parts of a pdf file (i.e. personal data that I don't want to send with the pdf)?
Maybe from the command line where I can say make everything black on page 2 from pixel X455 to X470 and Y300 to Y320.
2 Answers
You can not edit the content of PDF using the command line. You have to manually download it and edit it using a GUI software regarding the same.
But there are few tools which can help you to manipulate PDF using Terminal.
On Linux, you can install qpdf and poppler-utils using your package manager (such as apt or dnf.)
For example, on Fedora:
$ sudo dnf install qpdf poppler-utils
qpdf
The qpdf command can do a lot, but I mostly use it for:
Splitting a PDF into separate pages Concatenating, or combining, PDFs into one file To split a PDF into separate pages:
qpdf --split-pages original.pdf split.pdf
This generates files like split-01.pdf, split-02.pdf, and so on. Each file is a single-page PDF file.
Concatenating files is a little subtler:
qpdf --empty concatenated.pdf --pages split-*.pdf --
This is what qpdf
does by default. The --empty
option tells qpdf to start with an empty file. The two dashes (--
) at the end signals that there are no more files to process. This is a case where the parameters reflect an internal model, rather than what people use it for, but at least it runs and produces valid PDFs!
poppler-utils
This package contains several utilities, but the one I use the most is pdftoppm
, which converts PDF files to portable pixmap (ppm) image files. I usually use it after I split pages with qpdf
and need to convert a specific page to an image that I can modify. The ppm format is not well known, but the important thing about it is that most image manipulation methods, including ImageMagick, Pillow, and many other options, work with it. Most of these tools can save files back to PDF, too.
In the end I managed to do it with GIMP
.
You can open .pdfs in Gimp
and edit them.
I took a black paintbrush to redact some text.
Then I clicked on export and used a .pdf ending and it was exported to PDF (with some quality loss).