Developing a Redaction Feature for LibreOffice - Phase 1
Tags: opensource, libreoffice, development, story
Published: 2020-10-27 23:28:29

---
title: "Developing a Redaction Feature for LibreOffice - Phase 1"
published: true
description: The development story of the new redaction feature of Libreoffice - Phase 1 - Manual Redaction
tags: opensource, libreoffice, development, story
canonical_url: https://muhammetkara.dev/post/2019-10-29-redaction-in-libreoffice-phase-1-manual-redaction
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/s00jwhflrtb2qpqurc11.png
---

Now it is possible to redact your documents with LibreOffice to remove/hide sensitive information, and I'll try to share some info about it via a 2-part series of blog posts. You can also check out the [Collabora's blog post](https://www.collaboraoffice.com/company-news/redaction-tool/) for some more information probably with a better presentation, and a more user-centric view.

![Redaction tool in LibreOffice](https://dev-to-uploads.s3.amazonaws.com/i/nd44htj8x32irntcc2gk.png)

# What?

Redaction in its sanitization sense is the blacking out or deletion of text in a document, or the result of such an effort. It is intended to allow the selective disclosure of information in a document while keeping other parts of the document secret. Typically the result is a document that is suitable for publication or for dissemination to others than the intended audience of the original document. For example, when a document is subpoenaed in a court case, information not specifically relevant to the case at hand is often redacted. [Redaction in Wikipedia](https://en.wikipedia.org/wiki/Sanitization_(classified_information))

Although there are some proprietary software applications in the market for this purpose, they have their own limitations like lack of support for open/libre document formats. Thanks to LibreOffice's great support for various file formats, and our recent work on implementing this new feature on top of it, it is now possible to redact most of your documents without leaving the comfort of your favourite office suite.

# How?

* Open your document in LibreOffice
* Click (**Tools ▸ Redact**) from the main menu, and wait for your document to be prepared for redaction (converted to an internal meta-format, and transferred to Draw)
* Do the redaction by using the **“Rectangle Redaction”** and the **“Freeform Redaction”** tools on the **“Redaction Toolbar”**
* Save & share the in-redaction copies of the document with peers either in the modifiable (odg) or the verbatim (pdf) format at your option
* Once you are ready to finalize the redaction, click the desired option on the **“Redacted Export”** tool on the Redaction toolbar

Redaction command in the Tools menu of Writer:
![Redaction Command in Tools Menu of LibreOffice 6.3](https://dev-to-uploads.s3.amazonaws.com/i/x52qecyyw1umffpgkqx7.png)


Starting redaction in Draw (Redaction toolbar is in the green rectangle):
![Redaction Start in Draw Libreoffice 6.3](https://dev-to-uploads.s3.amazonaws.com/i/lxefm6exv4y83jxyg3kx.png)

Screenshot while redacting a document in LibreOffice:
![In-Redaction Screenshot from Libreoffice 6.3](https://dev-to-uploads.s3.amazonaws.com/i/hot515a7qd8147gjegu1.png)

Screenshot of a redacted document, finalized and exported as PDF:
![Redacted Finalized PDF Screenshot from Libreoffice 6.3](https://dev-to-uploads.s3.amazonaws.com/i/i6gbfd3476mn1x3dr624.png)

## Where and when?

The feature was developed for Collabora Office 6.0, directly on LibreOffice core master, and is already available in LibreOffice 6.3+, and also on all recent snaphots of Collabora Office. If you are going to try it with a Collabora Office snapshot, I recommend getting an 6.4 snapshot.

* [For more info and the snapshot](https://www.collaboraoffice.com/company-news/redaction-tool/)
* [For latest LibreOffice](https://www.libreoffice.org/download/download/)

# Tips

* As a result, you will have a pixellized version of the redacted document in PDF. There will be no selectable text in it, and the redacted content will be non-existent.
* During redaction, the redaction shapes will be transparent and in grey so that the user can see what they are redacting.
* There are currently 4 tools on the Redaction toolbar (from left to right): Rectangle Redaction, Freeform Redaction, Redacted Export, Direct Export to PDF
![Redaction Toolbar in Libreoffice 6.3](https://dev-to-uploads.s3.amazonaws.com/i/mpkyirxtrzd0qci114g0.png)
* The Rectangle Redaction tool allows the user to mark the content for redaction by drawing transparent rectangles covering the content
* The Freeform Redaction tool allows the user to mark the content for redaction by drawing freeform lines/polygons covering the content
* The “Redacted Export” button box has two options: “Redacted Export (Black)” and “Redacted Export (White).” When clicked, it will finalize your document (by converting the transparent grey redaction shapes to opaque black or white shapes), and export as a pixellized PDF file. The “White” option might be preferred to save toner while printing.
* The Direct Export to PDF button allows the user to take an in-redaction copy of the document in PDF to share as a verbatim copy for review

# Dev Notes
* Most of the redaction related methods are in the [SfxRedactionHelper](https://opengrok.libreoffice.org/xref/core/sfx2/source/doc/SfxRedactionHelper.cxx) class.
* Redaction toolbar is defined in [sd/uiconfig/sdraw/toolbar/redactionbar.xml](https://opengrok.libreoffice.org/xref/core/sd/uiconfig/sdraw/toolbar/redactionbar.xml).
* When user clicks the "Redact" option on the menu, we;
  * Create GDIMetaFile objects (one for each page),
  * Open a new Draw document
  * Insert each GDIMetafile into a new Draw page
  * Make sure position and size is correct
  * Adjust the page size and margins to match the source document
  * Automatically open/show the redaction toolbar if it isnot already opened
* When user clicks on one of the two Redacted Export buttons on the toolbar, we;
  * Make all redaction shapes opaque and black/white (based on user choice)
  * Ask for save location for the pdf
  * Catch the page objects in the pdfexport filter, and pixellize
  * Change the redaction shapes back to transparent/gray after export

And here is a list of related commits if you would like to see what other changes were done:

1. [Redaction: Handle multiple Writer pages](https://gerrit.libreoffice.org/65847)
2. [Add Redaction Toolbar](https://gerrit.libreoffice.org/66706)
3. [Forge the freeform redaction tool](https://gerrit.libreoffice.org/66916)
4. [Make the text on Redaction toolbar buttons visible](https://gerrit.libreoffice.org/66968)
5. [Support bitmap PDF export for Redaction](https://gerrit.libreoffice.org/67108)
6. [Handle redaction finalization: Black](https://gerrit.libreoffice.org/67517)
7. [Use named shapes for redaction](https://gerrit.libreoffice.org/68031)
8. [Add style options to redaction export](https://gerrit.libreoffice.org/68072)
9. [Temp icons for the redactedexport commands](Temp icons for the redactedexport commands)
10. [Create the SfxRedactionHelper class](https://gerrit.libreoffice.org/68338)
11. [Handle different page sizes for redaction](https://gerrit.libreoffice.org/69909)
12. [Enable redaction for Impress](https://gerrit.libreoffice.org/69910)
13. [Add RedactDoc to Tools menu of Impress](https://gerrit.libreoffice.org/69911)
14. [Protect page position during redaction](https://gerrit.libreoffice.org/70839)
15. [Add direct pdf export to the Redaction toolbar](https://gerrit.libreoffice.org/70863)
16. [tdf#125063: Don't depend on content size for Page sizing](https://gerrit.libreoffice.org/71627)
17. [Respect page margins of the source doc during redaction](https://gerrit.libreoffice.org/71929)
18. [Redaction: First steps](https://gerrit.libreoffice.org/64858)
19. [Add method DocumentToGraphicRenderer::getPageCount()](https://gerrit.libreoffice.org/65971)
20. [Redaction: Adjust offset for multiple Calc pages](https://gerrit.libreoffice.org/66605)
21. [Add Redaction toolbar icons from colibre to tango](https://gerrit.libreoffice.org/76285) *(by Noel Grandin)*
22. [tdf#124377: enable anti-aliasing metafile during redaction](https://gerrit.libreoffice.org/79266) *(by Aron Budea)*