Example usage for org.apache.pdfbox.cos COSDictionary getKeyForValue

List of usage examples for org.apache.pdfbox.cos COSDictionary getKeyForValue

Introduction

In this page you can find the example usage for org.apache.pdfbox.cos COSDictionary getKeyForValue.

Prototype

public COSName getKeyForValue(Object value) 

Source Link

Document

Search in the map for the value that matches the parameter and return the first key that maps to that value.

Usage

From source file:fi.nls.oskari.printout.printing.PDPageContentStream.java

License:Apache License

private void writeColorSpace(PDColorSpace colorSpace) throws IOException {
    COSName key = null;// w  ww. j ava 2s .  c o m
    if (colorSpace instanceof PDDeviceGray || colorSpace instanceof PDDeviceRGB
            || colorSpace instanceof PDDeviceCMYK) {
        key = COSName.getPDFName(colorSpace.getName());
    } else {
        COSDictionary colorSpaces = (COSDictionary) resources.getCOSDictionary()
                .getDictionaryObject(COSName.COLORSPACE);
        if (colorSpaces == null) {
            colorSpaces = new COSDictionary();
            resources.getCOSDictionary().setItem(COSName.COLORSPACE, colorSpaces);
        }
        key = colorSpaces.getKeyForValue(colorSpace.getCOSObject());

        if (key == null) {
            int counter = 0;
            String csName = "CS";
            while (colorSpaces.containsValue(csName + counter)) {
                counter++;
            }
            key = COSName.getPDFName(csName + counter);
            colorSpaces.setItem(key, colorSpace);
        }
    }
    key.writePDF(output);
    appendRawCommands(SPACE);
}