Search in sources :

Example 11 with PdfStream

use of com.itextpdf.kernel.pdf.PdfStream in project i7j-pdfsweep by itext.

the class PdfCleanUpProcessor method checkIfImageAndClean.

private void checkIfImageAndClean(List<PdfObject> operands) {
    PdfStream imageStream = getXObjectStream((PdfName) operands.get(0));
    if (PdfName.Image.equals(imageStream.getAsName(PdfName.Subtype))) {
        ImageRenderInfo encounteredImage = ((PdfCleanUpEventListener) getEventListener()).getEncounteredImage();
        FilteredImagesCache.FilteredImageKey key = filter.createFilteredImageKey(encounteredImage.getImage(), encounteredImage.getImageCtm(), document);
        PdfImageXObject imageToWrite = getFilteredImage(key, encounteredImage.getImageCtm());
        if (imageToWrite != null) {
            float[] ctm = pollNotAppliedCtm();
            writeNotAppliedGsParams(false, false);
            openNotWrittenTags();
            getCanvas().addXObjectWithTransformationMatrix(imageToWrite, ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
        }
    }
}
Also used : PdfImageXObject(com.itextpdf.kernel.pdf.xobject.PdfImageXObject) PdfStream(com.itextpdf.kernel.pdf.PdfStream) ImageRenderInfo(com.itextpdf.kernel.pdf.canvas.parser.data.ImageRenderInfo)

Example 12 with PdfStream

use of com.itextpdf.kernel.pdf.PdfStream in project i7j-pdfsweep by itext.

the class PdfCleanUpProcessor method filterImageMask.

private void filterImageMask(PdfImageXObject originalImage, PdfName maskKey, Matrix ctmForMasksFiltering, PdfImageXObject imageToWrite) {
    PdfStream maskStream = originalImage.getPdfObject().getAsStream(maskKey);
    if (maskStream == null || ctmForMasksFiltering == null) {
        return;
    }
    PdfImageXObject maskImageXObject = new PdfImageXObject(maskStream);
    if (!PdfCleanUpFilter.imageSupportsDirectCleanup(maskImageXObject)) {
        Logger logger = LoggerFactory.getLogger(PdfCleanUpProcessor.class);
        logger.error(CleanUpLogMessageConstant.IMAGE_MASK_CLEAN_UP_NOT_SUPPORTED);
        return;
    }
    FilteredImagesCache.FilteredImageKey k = filter.createFilteredImageKey(maskImageXObject, ctmForMasksFiltering, document);
    PdfImageXObject maskToWrite = getFilteredImage(k, null);
    if (maskToWrite != null) {
        imageToWrite.getPdfObject().put(maskKey, maskToWrite.getPdfObject());
    }
}
Also used : PdfImageXObject(com.itextpdf.kernel.pdf.xobject.PdfImageXObject) PdfStream(com.itextpdf.kernel.pdf.PdfStream) Logger(org.slf4j.Logger)

Example 13 with PdfStream

use of com.itextpdf.kernel.pdf.PdfStream in project i7j-pdfsweep by itext.

the class PdfCleanUpProcessor method popCanvasIfFormXObject.

private void popCanvasIfFormXObject(String operator, List<PdfObject> operands) {
    if ("Do".equals(operator)) {
        PdfStream formStream = getXObjectStream((PdfName) operands.get(0));
        if (PdfName.Form.equals(formStream.getAsName(PdfName.Subtype))) {
            PdfCanvas cleanedCanvas = popCleanedCanvas();
            PdfFormXObject newFormXObject = new PdfFormXObject((Rectangle) null);
            newFormXObject.getPdfObject().putAll(formStream);
            if (formStream.containsKey(PdfName.Resources)) {
                newFormXObject.put(PdfName.Resources, cleanedCanvas.getResources().getPdfObject());
            }
            newFormXObject.getPdfObject().setData(cleanedCanvas.getContentStream().getBytes());
            PdfName name = getCanvas().getResources().addForm(newFormXObject);
            getCanvas().getContentStream().getOutputStream().write(name).writeSpace().writeBytes(ByteUtils.getIsoBytes("Do\n"));
        }
    }
}
Also used : PdfName(com.itextpdf.kernel.pdf.PdfName) PdfFormXObject(com.itextpdf.kernel.pdf.xobject.PdfFormXObject) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas) PdfStream(com.itextpdf.kernel.pdf.PdfStream)

Example 14 with PdfStream

use of com.itextpdf.kernel.pdf.PdfStream in project i7j-pdfsweep by itext.

the class PdfCleanUpTool method removeRedactAnnots.

/**
 * Remove the redaction annotations.
 * This method is called after the annotations are processed.
 *
 * @throws IOException
 */
private void removeRedactAnnots() throws IOException {
    for (PdfRedactAnnotation annotation : redactAnnotations.keySet()) {
        PdfPage page = annotation.getPage();
        if (page != null) {
            page.removeAnnotation(annotation);
            PdfPopupAnnotation popup = annotation.getPopup();
            if (popup != null) {
                page.removeAnnotation(popup);
            }
        }
        PdfCanvas canvas = new PdfCanvas(page);
        PdfStream redactRolloverAppearance = annotation.getRedactRolloverAppearance();
        PdfString overlayText = annotation.getOverlayText();
        Rectangle annotRect = annotation.getRectangle().toRectangle();
        if (redactRolloverAppearance != null) {
            drawRolloverAppearance(canvas, redactRolloverAppearance, annotRect, redactAnnotations.get(annotation));
        } else if (overlayText != null && !overlayText.toUnicodeString().isEmpty()) {
            drawOverlayText(canvas, overlayText.toUnicodeString(), annotRect, annotation.getRepeat(), annotation.getDefaultAppearance(), annotation.getJustification());
        }
    }
}
Also used : PdfRedactAnnotation(com.itextpdf.kernel.pdf.annot.PdfRedactAnnotation) PdfPopupAnnotation(com.itextpdf.kernel.pdf.annot.PdfPopupAnnotation) Rectangle(com.itextpdf.kernel.geom.Rectangle) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas) PdfPage(com.itextpdf.kernel.pdf.PdfPage) PdfStream(com.itextpdf.kernel.pdf.PdfStream) PdfString(com.itextpdf.kernel.pdf.PdfString)

Aggregations

PdfStream (com.itextpdf.kernel.pdf.PdfStream)14 PdfNumber (com.itextpdf.kernel.pdf.PdfNumber)6 PdfImageXObject (com.itextpdf.kernel.pdf.xobject.PdfImageXObject)5 ExtendedITextTest (com.itextpdf.test.ExtendedITextTest)5 Test (org.junit.Test)5 PdfArray (com.itextpdf.kernel.pdf.PdfArray)4 PdfCanvas (com.itextpdf.kernel.pdf.canvas.PdfCanvas)4 UnitTest (com.itextpdf.test.annotations.type.UnitTest)4 Rectangle (com.itextpdf.kernel.geom.Rectangle)1 PdfName (com.itextpdf.kernel.pdf.PdfName)1 PdfNull (com.itextpdf.kernel.pdf.PdfNull)1 PdfPage (com.itextpdf.kernel.pdf.PdfPage)1 PdfResources (com.itextpdf.kernel.pdf.PdfResources)1 PdfString (com.itextpdf.kernel.pdf.PdfString)1 PdfPopupAnnotation (com.itextpdf.kernel.pdf.annot.PdfPopupAnnotation)1 PdfRedactAnnotation (com.itextpdf.kernel.pdf.annot.PdfRedactAnnotation)1 CanvasTag (com.itextpdf.kernel.pdf.canvas.CanvasTag)1 ImageRenderInfo (com.itextpdf.kernel.pdf.canvas.parser.data.ImageRenderInfo)1 PdfFormXObject (com.itextpdf.kernel.pdf.xobject.PdfFormXObject)1 LogMessages (com.itextpdf.test.annotations.LogMessages)1