List of usage examples for com.itextpdf.text.pdf PdfDictionary getAsBoolean
public PdfBoolean getAsBoolean(final PdfName key)
PdfObject
as a PdfBoolean
, resolving indirect references. From source file:mkl.testarea.itext5.pdfcleanup.StrictPdfCleanUpProcessor.java
License:Open Source License
/** * Deletes redact annotations from the page and substitutes them with either OverlayText or RO object if it's needed. *//* www . j av a2 s . c o m*/ private void deleteRedactAnnots(int pageNum) throws IOException, DocumentException { Set<String> indirRefs = redactAnnotIndirRefs.get(pageNum); if (indirRefs == null || indirRefs.isEmpty()) { return; } PdfReader reader = pdfStamper.getReader(); PdfContentByte canvas = pdfStamper.getOverContent(pageNum); PdfDictionary pageDict = reader.getPageN(pageNum); PdfArray annotsArray = pageDict.getAsArray(PdfName.ANNOTS); // j is for access annotRect (i can be decreased, so we need to store additional index, // indicating current position in ANNOTS array in case if we don't remove anything for (int i = 0, j = 0; i < annotsArray.size(); ++i, ++j) { PdfIndirectReference annotIndRef = annotsArray.getAsIndirectObject(i); PdfDictionary annotDict = annotsArray.getAsDict(i); if (indirRefs.contains(annotIndRef.toString()) || indirRefs.contains(getParentIndRefStr(annotDict))) { PdfStream formXObj = annotDict.getAsStream(PdfName.RO); PdfString overlayText = annotDict.getAsString(PdfName.OVERLAYTEXT); if (fillCleanedArea && formXObj != null) { PdfArray rectArray = annotDict.getAsArray(PdfName.RECT); Rectangle annotRect = new Rectangle(rectArray.getAsNumber(0).floatValue(), rectArray.getAsNumber(1).floatValue(), rectArray.getAsNumber(2).floatValue(), rectArray.getAsNumber(3).floatValue()); insertFormXObj(canvas, pageDict, formXObj, clippingRects.get(j), annotRect); } else if (fillCleanedArea && overlayText != null && overlayText.toUnicodeString().length() > 0) { drawOverlayText(canvas, clippingRects.get(j), overlayText, annotDict.getAsString(PdfName.DA), annotDict.getAsNumber(PdfName.Q), annotDict.getAsBoolean(PdfName.REPEAT)); } annotsArray.remove(i--); // array size is changed, so we need to decrease i } } if (annotsArray.size() == 0) { pageDict.remove(PdfName.ANNOTS); } }