Example usage for com.itextpdf.text.pdf PdfName RO

List of usage examples for com.itextpdf.text.pdf PdfName RO

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfName RO.

Prototype

PdfName RO

To view the source code for com.itextpdf.text.pdf PdfName RO.

Click Source Link

Document

A name

Usage

From source file:mkl.testarea.itext5.pdfcleanup.StrictPdfCleanUpProcessor.java

License:Open Source License

/**
 * 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.
 *///from  ww w.  j  av  a2s.c o m
private List<PdfCleanUpLocation> extractLocationsFromRedactAnnot(int page, int annotIndex,
        PdfDictionary annotDict) {
    List<PdfCleanUpLocation> locations = new ArrayList<PdfCleanUpLocation>();
    List<Rectangle> markedRectangles = new ArrayList<Rectangle>();
    PdfArray quadPoints = annotDict.getAsArray(PdfName.QUADPOINTS);

    if (quadPoints.size() != 0) {
        markedRectangles.addAll(translateQuadPointsToRectangles(quadPoints));
    } else {
        PdfArray annotRect = annotDict.getAsArray(PdfName.RECT);
        markedRectangles
                .add(new Rectangle(annotRect.getAsNumber(0).floatValue(), annotRect.getAsNumber(1).floatValue(),
                        annotRect.getAsNumber(2).floatValue(), annotRect.getAsNumber(3).floatValue()));
    }

    clippingRects.put(annotIndex, markedRectangles);

    BaseColor cleanUpColor = null;
    PdfArray ic = annotDict.getAsArray(PdfName.IC);

    if (ic != null) {
        cleanUpColor = new BaseColor(ic.getAsNumber(0).floatValue(), ic.getAsNumber(1).floatValue(),
                ic.getAsNumber(2).floatValue());
    }

    PdfStream ro = annotDict.getAsStream(PdfName.RO);

    if (ro != null) {
        cleanUpColor = null;
    }

    for (Rectangle rect : markedRectangles) {
        locations.add(new PdfCleanUpLocation(page, rect, cleanUpColor));
    }

    return locations;
}

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.
 *//*from  w w w .  j  a  v a 2  s  . c  om*/
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);
    }
}