|
||||||||||
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. |
static void |
contractAreaAlongBaseline(float[] corners,
float amount)
When redacting individual words in the middle of a line of kerned text, an additional character on either side may also be redacted. |
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
public static void contractAreaAlongBaseline(float[] corners, float amount)
PageExtractor.Text.getCorners()
by an amount in this way, to allow
for this effect.
corners
- an array of n*8 coordinates of the form [x1,y1,x2,y2,x3,y3,x4,x4],
specifying the clockwise outline of the text where the baseline of the text runs
from (x1,y1) to (x4,y4). This array will be modified.amount
- what proportion of the height of the line to trim from each end
of the line. Typically this value would be about 0.1 to 0.2.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |