1

I want to provide PDF redaction functionality by using PdfCleanUpProcessor and the following code:

Rectangle redactionRectangle = new Rectangle(74, 503, 385, 761);
PdfReader pdfReader = new PdfReader(sourcePath);
PdfStamper pdfStamper = new PdfStamper(pdfReader,
    new FileStream(destinationPath, FileMode.Create));
List<PdfCleanUpLocation> cleanUpLocations = new List<PdfCleanUpLocation>
{
    new PdfCleanUpLocation(1, redactionRectangle, BaseColor.WHITE)
};
PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, pdfStamper);
cleaner.CleanUp();
pdfStamper.Close();

This works fine on PDFs with no images, but PDFs with images cause exceptions.

Running on the linked file throws:

The color depth 1 is not supported.

And running on the linked file throws:

Object reference not set to an instance of an object.

Draken
  • 3,134
  • 13
  • 34
  • 54
Narek Malkhasyan
  • 1,332
  • 1
  • 12
  • 22
  • 1
    *This works fine on PDFs with no images, but PDFs with images cause exceptions.* - It does not throw exceptions for all PDFs with images. But indeed, to do redaction iText needs to understand the image variant to be able to redact image areas. In case of certain colorspaces it does not understand the image data well enough to redact. And this most likely is where the exceptions are thrown. A small improvement obviously would be to throw exceptions meaningful in the context, and a bigger one would be understanding more image types. I don't know whether version 7 is better in this regard. – mkl Jun 27 '16 at 13:09
  • 1
    Concerning your second sample file: There is a difference in the behavior of IText/Java and iTextSharp/.Net: In contrast to iTextSharp there is no exception in iText, but the image itself is not redacted either (it merely is partially covered giving the impression of redaction at first glance). This second sample, BTW, is an interesting test for redaction code... ;) – mkl Jun 28 '16 at 08:24

0 Answers0