|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.faceless.pdf2.Redactor
public class Redactor
The Redactor can be used to redact (completely remove) text and images
from a PDF. This is quite simple to do - simply add a list of Area
objects on each PDFPage
, then call redact()
. Here's an
example showing how to remove any copies of the word "secret"
from a PDF.
PDF pdf = new PDF(new PDFReader(new File("private.pdf"))); PDFParser parser = new PDFParser(pdf); Redactor redactor = new Redactor(); for (int i=0;i<pdf.getNumberOfPages();i++) { PageExtractor extractor = parser.getPageExtractor(i); Collection all = extractor.getMatchingText("secret"); for (Iterator j = all.iterator();j.hasNext();) { PageExtractor.Text text = (PageExtractor.Text)j.next(); float[] corners = text.getCorners(); GeneralPath path = new GeneralPath(); path.moveTo(corners[0], corners[1]); path.lineTo(corners[2], corners[3]); path.lineTo(corners[4], corners[5]); path.lineTo(corners[6], corners[7]); Area area = new Area(path); redactor.addArea(text.getPage(), area); } } redactor.redact(); pdf.render(new FileOutputStream("public.pdf"));Redaction potentially has to rebuild the PDF structure, so will lock on the PDF object itself before running and on each page before processing it.
Constructor Summary | |
---|---|
Redactor()
Creates a new Redactor |
Method Summary | |
---|---|
void |
addArea(PDFPage page,
Area area)
Adds an area to redact out of the document. |
void |
redact()
Performs the redaction. |
void |
setRedactionColor(Paint color)
Sets the Paint to use to fill in any redacted areas. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Redactor()
Method Detail |
---|
public void addArea(PDFPage page, Area area)
page
- the page to redact the area fromarea
- the area to redact (in PDF page coordinates)public void setRedactionColor(Paint color)
new Color(0, true)
(a transparent color) to erase the content so the background can be seen,
or it could be a PDFPattern
to redact with a "stamp".
color
- the color to redact withpublic void redact() throws IOException
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |