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?