Example usage for org.apache.pdfbox.pdmodel.graphics.color PDColor getComponents

List of usage examples for org.apache.pdfbox.pdmodel.graphics.color PDColor getComponents

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel.graphics.color PDColor getComponents.

Prototype

public float[] getComponents() 

Source Link

Document

Returns the components of this color value.

Usage

From source file:com.tekstosense.segmenter.data.Text.java

License:Open Source License

private static String getColorString(PDColor c) {
    String colorString = "";
    //ccheck suitable for getcomponents   
    float[] rgb = c.getComponents();
    if (rgb.length == 1) {
        int grey = (int) rgb[0] * 255;
        colorString = Integer.toHexString(grey);
        if (colorString.length() == 1) {
            colorString = "0" + colorString;
        }/*from  w  w w.j a  va2s  .c  om*/
        colorString = colorString + colorString + colorString;
    } else {
        for (int colorIndex = 0; colorIndex < 3; colorIndex++) {
            int color = (int) rgb[colorIndex] * 255;
            String s = Integer.toHexString(color);
            if (s.length() == 1) {
                s = "0" + s;
            }
            colorString += s;
        }
    }

    return "#" + colorString;
}

From source file:org.fit.pdfdom.PDFBoxTree.java

License:Open Source License

/**
 * Creates a CSS rgb specification from a PDF color
 * @param pdcolor//  ww w .ja  v  a  2  s .  c  o m
 * @return the rgb() string
 */
protected String colorString(PDColor pdcolor) {
    String color = null;
    try {
        float[] rgb = pdcolor.getColorSpace().toRGB(pdcolor.getComponents());
        color = colorString(rgb[0], rgb[1], rgb[2]);
    } catch (IOException e) {
        log.error("colorString: IOException: {}", e.getMessage());
    }
    return color;
}