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

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

Introduction

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

Prototype

PdfName IM

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

Click Source Link

Document

A name

Usage

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

License:Open Source License

public void renderImage(ImageRenderInfo renderInfo) {
    List<Rectangle> areasToBeCleaned = getImageAreasToBeCleaned(renderInfo);

    if (areasToBeCleaned == null) {
        chunks.add(new PdfCleanUpContentChunk.Image(false, null));
    } else {//from w ww  .java 2 s .  c o m
        try {
            PdfImageObject pdfImage = renderInfo.getImage();
            byte[] imageBytes = processImage(pdfImage.getImageAsBytes(), areasToBeCleaned);

            if (renderInfo.getRef() == null && pdfImage != null) { // true => inline image
                PdfDictionary dict = pdfImage.getDictionary();
                PdfObject imageMask = dict.get(PdfName.IMAGEMASK);
                Image image = Image.getInstance(imageBytes);

                if (imageMask == null) {
                    imageMask = dict.get(PdfName.IM);
                }

                if (imageMask != null && imageMask.equals(PdfBoolean.PDFTRUE)) {
                    image.makeMask();
                }

                PdfContentByte canvas = getContext().getCanvas();
                canvas.addImage(image, 1, 0, 0, 1, 0, 0, true);
            } else if (pdfImage != null && imageBytes != pdfImage.getImageAsBytes()) {
                chunks.add(new PdfCleanUpContentChunk.Image(true, imageBytes));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}