0

I'm currently trying to redaction some information from a PDF using the iTextSharp library. The problem I'm running into is the fact that the content within the "redacted" area is still selectable and readable, which is a problem.

I have used two ways, first one being where I add the redactions manually using iTextSharp's annotation feature and then applying it.

`PdfStamper stamper = new PdfStamper(reader, new FileStream(fileName.Replace(oldFileName, replacementFileName), FileMode.Create, FileAccess.Write));
iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(500, 50, 200, 300); 
PdfAnnotation annotation = new PdfAnnotation(stamper.Writer, rect);
annotation.Title = "WORK PLEASE";
annotation.Put(PdfName.SUBTYPE, new PdfName("Redact"));
annotation.Put(PdfName.IC, new PdfArray(new[] { 0f, 0f, 0f }));
annotation.Put(PdfName.OPEN, PdfBoolean.PDFFALSE);
annotation.Put(PdfName.OC, new PdfArray(new[] { 1f, 0f, 0f }));
annotation.Put(PdfName.CONTENTS, new PdfString(string.Format("Icon: {0}", text)));
annotation.Put(PdfName.QUADPOINTS, new PdfArray (new [] {200,50,500,50,200,300,500,300}));
annotation.Put(PdfName.NAME, new PdfName(text));
stamper.AddAnnotation(annotation, 1);
//Applying the annotations here
DirectoryInfo outDir = new DirectoryInfo(destinationFolder);
if (!outDir.Exists) { 
    outDir.Create(); 
} 
PdfReader Reader = new PdfReader(destinationFolder + "\\WORK.pdf");
string output = destinationFolder + "\\hello.pdf";
Stream fos = new FileStream(output, FileMode.Create);
PdfStamper StamperWork = new PdfStamper(Reader, fos);
PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(StamperWork);
cleaner.CleanUp();
StamperWork.Close();
fos.Close();
Reader.Close();`

The other way I used was using the list of clean up locations:

PdfStamper stamper = new PdfStamper(reader, new FileStream(file.Replace(oldchar, repChar), FileMode.Create, FileAccess.Write));
    List<PdfCleanUpLocation> cleanUpLocations = new List<PdfCleanUpLocation>();
    cleanUpLocations.Add(new PdfCleanUpLocation(1, new iTextSharp.text.Rectangle(0f, 0f, 600f, 115f), iTextSharp.text.BaseColor.WHITE));
    PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
    cleaner.CleanUp();
    stamper.Close();
    reader.Close();

But, this still results in selectable text in the PDF. It basically looks like there are white rectangles over the area I want. The weird thing is if I just make the annotations on the PDF using the first method, open it up, and manually apply the redactions on Adobe Acrobat, it works.

Also, when I try to clean up a pdf file that already has redacted areas marked, there is still selectable/parsable text within the "redacted" areas. It might be a problem related to the library.

Does anyone have any insight to this issue?

  • Please share a PDF to reproduce the issue with. Furthermore, which iTextSharp version do you use? Cleanup is a fairly new feature, so you should use a very current version. – mkl Jun 10 '16 at 16:38
  • I'm currently using the latest one, 5.5.9. I wanted to send you a random PDF file from online (with my code applied) since the one I'm working with contains sensitive information. The interesting thing is that the clean up location works on this PDF: [link](https://drive.google.com/open?id=0B4dEtrpRnPK3ajVKT2NHQTE1RTQ), but not the one I'm currently using. (Sorry I can't share it). What could be the problem? – Billy Jones Jun 10 '16 at 17:07
  • *What could be the problem?* - There are many possible problems. Without a document for which the issue can be observed, it's essentially impossible to help. If you cannot provide such a document publicly, you might try to contact iText themselves, share a document under a NDA, and hire them to help. – mkl Jun 13 '16 at 09:57

0 Answers0