Package com.itextpdf.text.pdf.pdfcleanup
Class PdfCleanUpProcessor
- java.lang.Object
-
- com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpProcessor
-
public class PdfCleanUpProcessor extends java.lang.Object
Represents the main mechanism for cleaning a PDF document.- Since:
- 5.5.4
-
-
Field Summary
Fields Modifier and Type Field Description static double
arcTolerance
Used as the criterion of a good approximation of rounded line joins and line caps.private java.util.Map<java.lang.Integer,java.util.List<Rectangle>>
clippingRects
private int
currentXObjNum
private static java.lang.String
FILL_COLOR
static boolean
fillCleanedArea
static double
floatMultiplier
When a document with line arts is being cleaned up, there are lot of calculations with floating point numbers.private java.util.Map<java.lang.Integer,java.util.List<PdfCleanUpLocation>>
pdfCleanUpLocations
private PdfStamper
pdfStamper
private java.util.Map<java.lang.Integer,java.util.Set<java.lang.String>>
redactAnnotIndirRefs
private static java.lang.String
STROKE_COLOR
private static java.lang.String
XOBJ_NAME_PREFIX
-
Constructor Summary
Constructors Constructor Description PdfCleanUpProcessor(PdfStamper pdfStamper)
Creates aPdfCleanUpProcessor
object.PdfCleanUpProcessor(java.util.List<PdfCleanUpLocation> pdfCleanUpLocations, PdfStamper pdfStamper)
Creates aPdfCleanUpProcessor
object based on the givenList
ofPdfCleanUpLocation
s representing regions to be erased from the document.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addColoredRectangle(PdfContentByte canvas, PdfCleanUpLocation cleanUpLocation)
void
cleanUp()
Cleans the document by erasing all the areas which are either provided or extracted from redaction annotations.private void
cleanUpPage(int pageNum, java.util.List<PdfCleanUpLocation> cleanUpLocations)
private void
colorCleanedLocations(PdfContentByte canvas, java.util.List<PdfCleanUpLocation> cleanUpLocations)
private PdfCleanUpRegionFilter
createFilter(java.util.List<PdfCleanUpLocation> cleanUpLocations)
private void
deleteRedactAnnots(int pageNum)
Deletes redact annotations from the page and substitutes them with either OverlayText or RO object if it's needed.private void
drawOverlayText(PdfContentByte canvas, java.util.List<Rectangle> textRectangles, PdfString overlayText, PdfString otDA, PdfNumber otQ, PdfBoolean otRepeat)
private java.util.List<PdfCleanUpLocation>
extractLocationsFromRedactAnnot(int page, int annotIndex, PdfDictionary annotDict)
Extracts locations from the concrete annotation.private void
extractLocationsFromRedactAnnots()
Extracts locations from the redact annotations contained in the document.private java.util.List<PdfCleanUpLocation>
extractLocationsFromRedactAnnots(int page, PdfDictionary pageDict)
Extracts locations from the redact annotations contained in the document and applied to the given page.private PdfName
generateNameForXObj(PdfDictionary pageDict)
private java.lang.String
getParentIndRefStr(PdfDictionary dict)
private int
getXObjNum(PdfName xobjName)
private void
insertFormXObj(PdfContentByte canvas, PdfDictionary pageDict, PdfStream formXObj, java.util.List<Rectangle> clippingRects, Rectangle annotRect)
private java.util.Map<java.lang.Integer,java.util.List<PdfCleanUpLocation>>
organizeLocationsByPage(java.util.Collection<PdfCleanUpLocation> pdfCleanUpLocations)
(package private) java.util.Map<java.lang.String,java.util.List>
parseDAParam(PdfString DA)
private Font
retrieveFontFromAcroForm(PdfName fontName, PdfNumber size)
private void
saveRedactAnnotIndirRef(int page, java.lang.String indRefStr)
private void
setFillColor(PdfContentByte canvas, java.util.List fillColorArgs)
private void
setStrokeColor(PdfContentByte canvas, java.util.List strokeColorArgs)
private java.util.List<Rectangle>
translateQuadPointsToRectangles(PdfArray quadPoints)
-
-
-
Field Detail
-
floatMultiplier
public static double floatMultiplier
When a document with line arts is being cleaned up, there are lot of calculations with floating point numbers. All of them are translated into fixed point numbers by multiplying by this coefficient. Vary it to adjust the preciseness of the calculations.
-
fillCleanedArea
public static boolean fillCleanedArea
-
arcTolerance
public static double arcTolerance
Used as the criterion of a good approximation of rounded line joins and line caps.
-
XOBJ_NAME_PREFIX
private static final java.lang.String XOBJ_NAME_PREFIX
- See Also:
- Constant Field Values
-
STROKE_COLOR
private static final java.lang.String STROKE_COLOR
- See Also:
- Constant Field Values
-
FILL_COLOR
private static final java.lang.String FILL_COLOR
- See Also:
- Constant Field Values
-
currentXObjNum
private int currentXObjNum
-
pdfStamper
private PdfStamper pdfStamper
-
pdfCleanUpLocations
private java.util.Map<java.lang.Integer,java.util.List<PdfCleanUpLocation>> pdfCleanUpLocations
-
redactAnnotIndirRefs
private java.util.Map<java.lang.Integer,java.util.Set<java.lang.String>> redactAnnotIndirRefs
-
clippingRects
private java.util.Map<java.lang.Integer,java.util.List<Rectangle>> clippingRects
-
-
Constructor Detail
-
PdfCleanUpProcessor
public PdfCleanUpProcessor(java.util.List<PdfCleanUpLocation> pdfCleanUpLocations, PdfStamper pdfStamper)
Creates aPdfCleanUpProcessor
object based on the givenList
ofPdfCleanUpLocation
s representing regions to be erased from the document.- Parameters:
pdfCleanUpLocations
- list of locations to be cleaned up {@see PdfCleanUpLocation}pdfStamper
- APdfStamper
object representing the document which redaction applies to.
-
PdfCleanUpProcessor
public PdfCleanUpProcessor(PdfStamper pdfStamper)
Creates aPdfCleanUpProcessor
object. Regions to be erased from the document are extracted from the redact annotations contained inside the given document.- Parameters:
pdfStamper
- APdfStamper
object representing the document which redaction applies to.
-
-
Method Detail
-
cleanUp
public void cleanUp() throws java.io.IOException, DocumentException
Cleans the document by erasing all the areas which are either provided or extracted from redaction annotations.- Throws:
java.io.IOException
DocumentException
-
cleanUpPage
private void cleanUpPage(int pageNum, java.util.List<PdfCleanUpLocation> cleanUpLocations) throws java.io.IOException, DocumentException
- Throws:
java.io.IOException
DocumentException
-
createFilter
private PdfCleanUpRegionFilter createFilter(java.util.List<PdfCleanUpLocation> cleanUpLocations)
-
colorCleanedLocations
private void colorCleanedLocations(PdfContentByte canvas, java.util.List<PdfCleanUpLocation> cleanUpLocations)
-
addColoredRectangle
private void addColoredRectangle(PdfContentByte canvas, PdfCleanUpLocation cleanUpLocation)
-
organizeLocationsByPage
private java.util.Map<java.lang.Integer,java.util.List<PdfCleanUpLocation>> organizeLocationsByPage(java.util.Collection<PdfCleanUpLocation> pdfCleanUpLocations)
-
extractLocationsFromRedactAnnots
private void extractLocationsFromRedactAnnots()
Extracts locations from the redact annotations contained in the document.
-
extractLocationsFromRedactAnnots
private java.util.List<PdfCleanUpLocation> extractLocationsFromRedactAnnots(int page, PdfDictionary pageDict)
Extracts locations from the redact annotations contained in the document and applied to the given page.
-
saveRedactAnnotIndirRef
private void saveRedactAnnotIndirRef(int page, java.lang.String indRefStr)
-
extractLocationsFromRedactAnnot
private java.util.List<PdfCleanUpLocation> extractLocationsFromRedactAnnot(int page, int annotIndex, PdfDictionary annotDict)
Extracts locations from the concrete annotation. Note: annotation can consist not only of one area specified by the RECT entry, but also of multiple areas specified by the QuadPoints entry in the annotation dictionary.
-
translateQuadPointsToRectangles
private java.util.List<Rectangle> translateQuadPointsToRectangles(PdfArray quadPoints)
-
deleteRedactAnnots
private void deleteRedactAnnots(int pageNum) throws java.io.IOException, DocumentException
Deletes redact annotations from the page and substitutes them with either OverlayText or RO object if it's needed.- Throws:
java.io.IOException
DocumentException
-
insertFormXObj
private void insertFormXObj(PdfContentByte canvas, PdfDictionary pageDict, PdfStream formXObj, java.util.List<Rectangle> clippingRects, Rectangle annotRect) throws java.io.IOException
- Throws:
java.io.IOException
-
drawOverlayText
private void drawOverlayText(PdfContentByte canvas, java.util.List<Rectangle> textRectangles, PdfString overlayText, PdfString otDA, PdfNumber otQ, PdfBoolean otRepeat) throws DocumentException, java.io.IOException
- Throws:
DocumentException
java.io.IOException
-
parseDAParam
java.util.Map<java.lang.String,java.util.List> parseDAParam(PdfString DA) throws java.io.IOException
- Throws:
java.io.IOException
-
getParentIndRefStr
private java.lang.String getParentIndRefStr(PdfDictionary dict)
-
generateNameForXObj
private PdfName generateNameForXObj(PdfDictionary pageDict)
-
getXObjNum
private int getXObjNum(PdfName xobjName)
-
setFillColor
private void setFillColor(PdfContentByte canvas, java.util.List fillColorArgs)
-
setStrokeColor
private void setStrokeColor(PdfContentByte canvas, java.util.List strokeColorArgs)
-
-