1

I'm facing one issue while using the CleanUp method of PdfCleanUpProcess Class of ITextSharp, I'm Tring to redact text from PDF file, but when I call the CleanUp method it removes the whole line instead of a particular word, I'm providing correct coordinates of word here is a code sample

iTextSharp.text.pdf.PdfReader pdfReaderF = new iTextSharp.text.pdf.PdfReader(fileLocation);
iTextSharp.text.pdf.PdfStamper stamperF = new iTextSharp.text.pdf.PdfStamper(pdfReaderF, new FileStream(outputfile, FileMode.Create));
iTextSharp.xtra.iTextSharp.text.pdf.pdfcleanup.PdfCleanUpProcessor cleaner = new iTextSharp.xtra.iTextSharp.text.pdf.pdfcleanup.PdfCleanUpProcessor(listCleanUp, stamperF);
cleaner.CleanUp();
stamperF.Close();
pdfReaderF.Close();

Thanks

mkl
  • 90,588
  • 15
  • 125
  • 265
  • Please share the PDF in question. Or a different PDF which also allows to reproduce the issue, if you cannot share the original PDF. – mkl Mar 26 '19 at 07:46
  • This issue is for all pdf files – Nilesh Agotariya Mar 27 '19 at 11:05
  • i'm using itextsharp 5.5.13.0 – Nilesh Agotariya Mar 27 '19 at 11:23
  • I just tested the `PdfCleanUpProcessor` and what you claim did not happen, exactly a particular word was redacted, nothing more. Thus, your claim *"This issue is for all pdf files"* was a misstatement. (I was wondering how you tested all the PDFs in existence in that short a time. As it turns out, you didn't.) – mkl Mar 27 '19 at 11:41
  • That being said, there indeed is a known defect in iText(Sharp) redaction of *tagged PDF files* which relocated some text, cf. [this answer](https://stackoverflow.com/a/35453025/1729265). Probably that bug has not yet being fixed in the current release version and you have to apply the fix from that answer to your copy of iText. That answer is about the Java version of iText but the comments to [this question](https://stackoverflow.com/q/37835323/1729265) seem to imply that the fix similarly applies to iTextSharp. – mkl Mar 27 '19 at 11:47

1 Answers1

0

Try this code it worked for me just give the the coordinates of the rectangle.

IList<iTextSharp.xtra.iTextSharp.text.pdf.pdfcleanup.PdfCleanUpLocation> cleanUpLocations = new List<iTextSharp.xtra.iTextSharp.text.pdf.pdfcleanup.PdfCleanUpLocation>();
cleanUpLocations.Add(new iTextSharp.xtra.iTextSharp.text.pdf.pdfcleanup.PdfCleanUpLocation(i, new iTextSharp.text.Rectangle(X, Y, xx, yy), iTextSharp.text.BaseColor.WHITE));
iTextSharp.xtra.iTextSharp.text.pdf.pdfcleanup.PdfCleanUpProcessor cleaner = new iTextSharp.xtra.iTextSharp.text.pdf.pdfcleanup.PdfCleanUpProcessor(cleanUpLocations, stamper);
cleaner.CleanUp();
                        
Amine Ouadrani
  • 301
  • 2
  • 7