40

I had to print a couple of PDFs recently to send to someone, but I wanted to redact (black out) a couple small bits of text.

A quick google search didn't turn up any tools for this specific purpose, so I fell back to imagemagick & gimp:

  • convert document.pdf document.png
  • gimp document-0.png
  • (use paintbrush to black out text)
  • print redacted page from gimp
  • print remaining pages from xpdf

The problem with this strategy is that the conversion process (from PDF to PNG or whatever other format) loses quality. I tried editing the PDF in gimp but it didn't work right away.

Is there a specific tool that permits redaction in this way? (It doesn't even need to be "real" redaction -- I'm not sending a softcopy so "fake" redaction will work because the hardcopy can't be hacked to reveal the underlying text.)

Or, is there a trick to being able to edit PDFs in gimp?

2
  • 2
    PDF is scalable, PNG is raster graphics, which is probably why there is quality loss in the conversion process. Convert to a scalable format instead, such as SVG.
    – Anonymous
    Oct 27, 2011 at 19:28
  • @Anonymous: Nice idea, but not usable. The resulting SVG file is massive; I had to -KILL the viewer after 30 minutes and a GiB or so of memory consumption.
    – bstpierre
    Oct 27, 2011 at 20:35

17 Answers 17

26

You can use Okular.

sudo apt-get install okular
  1. Open the pdf with Okular.
  2. Press F6.
  3. Press 8.
  4. Highlight the text you wish to redact.
  5. Right click the text, select properties, select the "Type" as "Highlight", press Ok.
  6. Print the file to a pdf (check "Force rasterization" to make sure the redacted text is removed from the resulting file).
12
  • 6
    Perhaps mention how to make the highlight black.
    – equaeghe
    Oct 25, 2016 at 8:52
  • 6
    Okular can redact with any color (black) of these functions: text highlight, free hand line, and polygon links with inner fill. You can save the setting as your own custom annotation tool. Easily using it over and over. Then when you print the file to pdf you should "force rasterization" to ensure the redaction is not reversible. Okular Version 1.1.3
    – shadowbq
    Mar 23, 2018 at 2:09
  • 3
    The comment about forcing the rasterization should be added to the answer.
    – JSycamore
    May 1, 2020 at 18:31
  • 6
    it seems important to mention that this does not actually black-out the document... opening the pdf in inkscape easily allows to see the underlying text. For legal documents this is a big issue.
    – Alain
    Jan 29, 2021 at 20:57
  • 2
    @crobar unfortunately, even if you print (print to file) the pdf after editing it with Okular, the resulting pdf file can still be modified with Inkscape to retrieve the original file.
    – Alain
    Mar 25, 2021 at 17:00
20

(originally I recommened Okular but it didn't work as I expected)

1. Edit the document in a vector editor

I was able to open a PDF file in Inkscape, draw a rectangle over a piece of text and print it out. Inkscape is a vector editor so no rasterization involved. Some fonts looked wrong though - probably because the document was created on Windows machine with fonts which are absent on mine.

Note that any method that does not involve rasterization is only acceptable if you're going to print the redacted document on paper and not distribute it electronically, as the text still can be retrieved from under blackouts.

2. Increase the rasterization resolution when opening in a bitmap editor

Regarding "quality loss" when opening the page in Gimp: you can directly open a PDF file in Gimp. It will be rasterized in the process. The amount of quality loss in the process is a matter of resolution you choose when importing - 300 dpi should give you a very decent quality (the default is 100).

You can also get good results with ImageMagick's convert command if you tell it to increase resolution:

convert -density 300x300 ...
7
  • 1
    +1 and accepted! Thanks for suggesting inkscape, it did a reasonable job (not perfect -- it lost a couple of (unimportant to me) graphic objects) -- but very reasonable). And the tip on convert was good too: the incantation I used was convert -density 300x300 and there's no loss of quality.
    – bstpierre
    Oct 27, 2011 at 23:37
  • 1
    +1 for mentioning GIMP can handle pdfs quite well
    – don.joey
    Dec 20, 2012 at 12:09
  • 12
    Warning to the general populace: the redaction methods here that involve retaining text suggested here (e.g. all the ones that avoid rasterisation) are not secure. Text can still be selected from under blackouts, or read from the source of the file. See for example freerepublic.com/focus/f-news/2706743/posts and hackaday.com/2008/08/01/exposing-poorly-redacted-pdfs
    – naught101
    Jun 12, 2013 at 2:43
  • Although the original question asked about sending hardcopy only, for which nonrasterizing methods are acceptable, downvoting since this answer does not clearly enough warn about the security risk when distributing the result electronically. Feb 3, 2014 at 16:45
  • 5
    @JesseGlick: instead of "punishing" me for not addressing a use case not even mentioned in the original question, you could've just edited the answer. That would be more beneficial for the future visitors.
    – Sergey
    Feb 3, 2014 at 20:29
12

Basically what you are trying to do is highlight/annotate a PDF, but with some flexibility towards marker opacity and colour (you mentioned you don't need to censor/remove something, merely redact). Have you taken a look at answers here: How can I highlight or annotate PDFs?

One of the highest rated answers recommends Xournal, which has not been mentioned here and would be my weapon of choice. It is a tool that allows you to make handwritten notes but has extra features allowing you to annotate a PDF. By default it'll save your annotations as a separate file but also allows you to export the annotated PDF as a new PDF. This should maintain the layout, fonts, etc.

With Xournal you'd choose "Annotate PDF", then use a solid black marker to mask the parts you want to redact, and "Export to PDF".

There are some stories on the internet suggesting that Xournal rasterises the text in the exported PDF (thanks for pointing this out, MHC). This does not seem to be true: with simple annotations, the text remains selectable and searchable and the file size does not increase by much (it increased from 205 kb to 220 kb in the example below).

To install, run in a terminal: sudo apt-get install xournal or just select it from the Software Centre

Xournal interface Resulting exported PDF

5
  • Xournal is good but you have to know that it can only export raster PDFs meaning that all text and vector information is lost in the process. If you can deal with that then Xournal is the application of your choice. Apr 20, 2013 at 3:45
  • 1
    Thanks for the feedback, @MHC. Xournal does not rasterise, see revised answer for more information.
    – Tomas
    Apr 21, 2013 at 3:02
  • 3
    I just tried it for myself and you're absolutely right. Sorry for the confusion. It had been a while since I had used Xournal and somehow I was left with the impression that the exported documents weren't true PDFs. Thanks for setting that straight! Apr 21, 2013 at 16:13
  • 2
    This works well, but I couldn't find a clean way to redact information. I had to use the draw tool to scribble which looks very messy and lacks the professionalism I'd like. Otherwise, spot on with the export rasterizing the content so it can't be selected and discovered.
    – flickerfly
    Jun 27, 2016 at 15:50
  • For real redaction, that replaces textual data with images, combine this answer with @balu's that uses ImageMajick's convert command.
    – colan
    Dec 1, 2018 at 0:26
5

I am redact a lot of PDF files everyday, so I spend a lot of time thinking how to do it the best way.

For me the best way is split PDF in 1-page PDF file, next to edit with GIMP, next to combine it. I don't use imagemagick on all files (I do not use at all), so I don't loss text-layer on all pages, but only on redacted. Do not load the whole PDF file at once, because it causes memory exhaustion.

Split PDF in 1-page files

Easily split PDF files to 1-page PDF you can by this bash function (put it in ~/.bashrc):

function pdf_split(){
    for file in "$@"; do
        if [ "${file##*.}" != "pdf" ]; then
            echo "Skip $file because it's not PDF file";
            continue
        fi; 
        pages=$(pdfinfo "$file" | grep "Pages" | awk '{print $2}') 
        echo "Detect $pages in $file";
        filename="${file%.*}";
        unset Outfile;
        for i in $(seq 1 "$pages"); do
            pdftk "$file" cat "$i" output "$filename-$i.pdf";
            Outfile[$i]="$filename-$i.pdf";
        done;
    done;
};

You can now enter split_pdf file.pdf to get a lot of PDF files.

Redact files

But, now you need edit all this files. You can do it with gimp original-filename-*.pdf. I suggest configure shortcut in GIMP (Main window->Edit-> Shortcut) to replace file (I use CTRL+R), blur filter (eg. CTRL+D), close file (eg. CTRL+W) and exit GIMP (eg.CTRL+Q). Remember to don't load in GIMP to many files at once, but GIMP as you about load after open, so you can use gimp original-filename-*.pdf on thousand files safe.

Combine files

You can combine files easily with: pdftk originam-filename-*.pdf cat output "new-file-anon.pdf";

Connect it all together

These operations are very repetitive and boring, so I connect it all in 1 script:

function pdf_redact(){
    for file in "$@"; do
        if [ "${file##*.}" != "pdf" ]; then
            echo "Skip $file because it's not PDF file";
            continue
        fi; 
        pages=$(pdfinfo "$file" | grep "Pages" | awk '{print $2}') 
        echo "Detect $pages in $file";
        filename="${file%.*}";
        unset Outfile;
        for i in $(seq 1 "$pages"); do
            pdftk "$file" cat "$i" output "$filename-$i.pdf";
            Outfile[$i]="$filename-$i.pdf";
        done;
        gimp "${Outfile[@]}";
        pdftk "${Outfile[@]}" cat output "$filename-anon.pdf";
        rm "${Outfile[@]}";

    read -p "Do you want open output file? " -n 1 -r
    echo    
    if [[ $REPLY =~ ^[Yy]$ ]]
    then
            evince "$filename-anon.pdf";
    fi

    read -p "Do you want upload output file to Scribd.com? " -n 1 -r
    echo 
    if [[ $REPLY =~ ^[Yy]$ ]]
    then
        scribd_up "$filename-anon.pdf";
    fi
    done;
};

The newest version of this script is always accessible at: http://dostep.jawne.info.pl/it/bashrc

Remember to close GIMP (CTRL+Q) after all redaction to continue script.

In addiction it as me to open redacted files (I like read to check whether all) and as to upload to Scribd with my other script - scribd_up, so now I can redact a lot of PDF files very efficiently.

3

As a lot of solutions here recommend redacting / blacking out through annotations (which leave the original content in the pdf), I recommend rasterizing the pdf afterwards to truly remove the original content. (Don't be this guy.)

Here's one way to do that which, at the same time, keeps the quality up and the file size low (at least in my case of a bunch of black/white pages):

$  convert -quality 100 -density 180 -compress zip notreallyredacted.pdf trulyredacted.pdf

Note: convert needs ImageMagick.

Note 2: convert does not preserve the contents of forms you might have filled out. In order for it to not get lost you might want to print the document "to a file" in something like evince first (or in whatever application you filled out the form) and then rasterize it.

4
  • Just added the permissions fix. This answer should be combined with the Xournal one.
    – colan
    Dec 1, 2018 at 0:24
  • Rasterizing makes the document unsearcheable, and probably 10x its original size.
    – jesjimher
    Nov 3, 2021 at 13:06
  • Sure but a cynic would say that's usually not your issue but someone else's. At least, you're redacting things properly and people won't be able to undo your redactions.
    – balu
    Nov 3, 2021 at 13:33
  • An easy way to test if you have rasterized correctly is to just run pdtotext and verify there is no text output. Jan 26 at 15:44
2

Open the PDF with the free tool PDF-Xchange PDF Viewer. Black out the text to be redacted using black rectangles. Print. That will get you easy, high-quality "fake" redaction.

3
  • That appears to be a win32 tool. Let me know if I missed the link for the linux port...
    – bstpierre
    Oct 27, 2011 at 20:47
  • 3
    The free portable PDF-Xchange viewer will work with wine.
    – Sabacon
    Oct 27, 2011 at 23:27
  • Thanks, this worked perfectly for me with wine. The inkscape and gimp solutions are only really useful for single page redactions. Nov 10, 2012 at 15:52
2

Use LibreOffice Draw for that quick editing that you are looking for. After you are done you can save it as LibreOffice Draw format or export it again to PDF format (File>Export as PDF)

enter image description here

To be able to import PDF files in to LibreOffice Draw you must first install the package libreoffice-pdfimport.

Install it via the Ubuntu Software Center (libreoffice-pdfimport Install libreoffice-pdfimport) or via a terminal with sudo apt-get install libreoffice-pdfimport.

1
  • Just drawing boxes over original PDF doesn't remove original contents. Any vector editing software allows removing boxes and accessing hidden content.
    – jesjimher
    Nov 3, 2021 at 13:10
2

I remember one time me and a colleague had to find a way to edit a couple of pdf, We ended up using Gimp. I will comment you the details ... we open the pdf directly with gimp (in a terminal)

gimp the_file.pdf

Once you are finished editing, we did not save the changes, instead of that we print in to pdf file ... That seemed to work ok.

3
  • For whatever reason, gimp refuses to allow me to make any edits to the file. I had to convert with imagemagick's convert first, then edit the converted file. (See accepted answer.)
    – bstpierre
    Oct 27, 2011 at 23:38
  • ok, the solution of inkscape is valid. But I repeat to you The Gimp can edit pdf files directly. =D
    – maniat1k
    Oct 28, 2011 at 11:55
  • Gimp seems to work with most PDF files, but the file I was using last night didn't work correctly. Inkscape handled that file properly.
    – bstpierre
    Oct 28, 2011 at 13:18
2

PDF Studio is a non-opensource and is software that requires purchasing.

In terms of this question, from version 8 onwards it has a manual redaction feature. Users can select a text object and redact it. The content is removed from the PDF and replaced with a black rectangle.

In version 9 coming third quarter 2013, redaction annotations and burning will be also available for images and shapes.

2
  • 4
    Per the faq, you should disclose your affiliation with the product you are promoting.
    – bstpierre
    Apr 20, 2013 at 2:14
  • Even though this is likely more of a promotional ad than an answer I have to say that PDFstudio really is a great piece of software. It might be a tad bit overpriced but it's certainly the best PDF editing suite for Linux out there. Make sure to at least try their trial version out. Apr 20, 2013 at 3:57
2

If you don't want to remember the correct incantation for convert you can use pdf-redact-tools, a shell script automating the process of exploding a PDF into PNG images and merging them back together after redaction (using a tool of your choice e.g. gimp). It's conventiently apt-get installable.

3
  • +1 It’s the product of Micah Lee and others from First Look Media (publisher of The Intercept). Its man page is here (for example) and some background information from the time around its release in 2015 is available here.
    – caw
    Dec 10, 2019 at 16:24
  • Converting all pages to PNG seems a little bit overkill. I just tried with a 40 page, 300 KB document, and just a tiny annotation in one of the pages became a 10 MB, unsearcheable file.
    – jesjimher
    Nov 3, 2021 at 13:09
  • If you want to redact safely, you unfortunately can't get around converting to an image. If you just overlay a black rectangle, the text will still be available in the PDF.
    – kynan
    Nov 5, 2021 at 18:18
2

Xournalpp is a popular variant of Xournal which has what you need. It is not available via the package manager (on Ubuntu 20.10), but a Github release can be built using CMake.

The build instructions here suggest the following dependencies:

sudo apt-get install cmake libgtk-3-dev libpoppler-glib-dev portaudio19-dev libsndfile-dev libcppunit-dev dvipng texlive libxml2-dev liblua5.3-dev libzip-dev librsvg2-dev gettext lua-lgi

In Xournalpp you should then select the rectangle icon and, next to the pen colours, the paint bucket icon. You can then create filled rectangles - but they will be transparent. To make them fully opaque, select Tools > Pen Options > Fill Transparency and change the pop-up to 100%. (This is explained on the Github issue here.)

2
2

Web Tools

Okay, if your document is really sensitive, you don't want it going anywhere before redaction. Here are some web tools that may have good policy. The thing with these, is they have businesses aimed at corporate clients and offer these services to showcase their SDKs. Make sure to read their terms of service.

Never leave the browser

https://pdf.online/redact-pdf

Leave the browser but they get deleted afterwards

https://freepdfredactor.com/

https://avepdf.com/redact-pdf

Other suggestions

If you find better tools out there, feel free to comment. We'd like to have a good list of what's available to us.

1

You could also try this tool: https://launchpad.net/updf

Here it is (but anyway, the text is selectable):

enter image description here

3
  • 1
    uPDF is great in that it preserves the original PDF and its text and svg content. However, it appears to have some problems with compression levels. Edited PDFs are about 3-4x larger in size than the original. Thank you for posting this, though. I wasn't aware of uPDF. Apr 20, 2013 at 4:39
  • Yes I know it has some problems, it's a bit rough. Hopefully newer releases will correct these issues... :) Apr 21, 2013 at 16:37
  • As mentioned, uPDF does have a lot of bugs (and not even undo/redo) but everything still went well in my case, so thank you!
    – balu
    Jan 28, 2016 at 7:47
1

The best way I have found to do this is to use http://www.pdfescape.com. You can annotate, add text and images, draw a "whiteout" rectangle around stuff you want to redact, and you can quickly download and save it. It also works really well with multi-page documents, which is something that lots of other solutions don't work well with. For example, if you open a multi-page document in Gimp or Inkscape, you will only be able to open one page at a time. The process is much faster in PDFescape. The whole process for me to redact a 2-page document takes less than a minute.

1
  • 1
    Does not truly wipe the data you painted over. (I can still search for it and it will "highlight" below).
    – Frank N
    Oct 25, 2019 at 10:42
0

There are multiple editors for editing PDF documents directly, such as pdfedit, or converter it to other vector formats that might be better supported, such as pstoedit. However I wouldn't recommend the use of any of them as the risk of doing something stupid, like just painting over the text with black while leaving the vectors in place is to easy, thus making the redaction trivial to undo.

Going the vector to bitmap route is the safest way, preferably the 1bit bitmap route, to avoid any potential issues with alpha channels or color differences that could leave the text readable.

If possible you should always redact the original document and just flat out remove the info, not the paint on the PDF, as even the kerning and spacing of text around the redacted text can give it away.

2
  • I understand the issues with redacting properly, but thank you for taking the care to point them out for anyone who comes along after. In my case, the PDF itself is disposable -- all I'm looking for is a hardcopy. (The PDF will be deleted as soon as I'm have hardcopy.) FWIW, pdfedit did not work: when I drew a black rectangle over the text in question, it nuked the rest of the page, leaving me with a document consisting of a single black rectangle.
    – bstpierre
    Oct 27, 2011 at 23:24
  • Going vector to bitmap, while safe, it's pretty overkill. All text information is lost, searches are impossible, and a 100 KB file may become a multi MB file easily. A proper redaction tool, that actually removes sensitive info while leaving the rest of the document untouched, is the best way to proceed. Problem is it seems there's no free tool to do that.
    – jesjimher
    Nov 3, 2021 at 13:14
0

I add to the list: Krita. Had no quality loss, because when importing PDF you can define dpi (set it to 300, as @Sergey said). After editing hit "Export as PDF". Lastly, I find Krita more intuitive than Gimp, after having been a long time user of Photoshop.

-2

If using LibreOffice to create PDF file, open doc in LibreOffice , highlight text to be redacted, right click and select character, select Background and click on black. Export to PDF.

1
  • This doesn't remove sensitive information, it's still there and can be selected and copy-pasted anywhere. From version 6.3, LibreOffice comes with an actual redaction option, even if it's a little bit clunky (it rasterizes the whole document, involves sending it to Draw).
    – jesjimher
    Nov 3, 2021 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.