Example usage for org.apache.pdfbox.cos COSName COLORSPACE

List of usage examples for org.apache.pdfbox.cos COSName COLORSPACE

Introduction

In this page you can find the example usage for org.apache.pdfbox.cos COSName COLORSPACE.

Prototype

COSName COLORSPACE

To view the source code for org.apache.pdfbox.cos COSName COLORSPACE.

Click Source Link

Usage

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

License:Apache License

private void writeColorSpace(PDColorSpace colorSpace) throws IOException {
    COSName key = null;/*from  w  ww . j a  v a 2  s  .c  om*/
    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);
}

From source file:pdfpicmangler.PDPng.java

License:Open Source License

/**
 * Construct from a stream.// w ww  .j a  va2s  .  com
 * 
 * @param doc The document to create the image as part of.
 * @param is The stream that contains the png data.
 * @throws IOException If there is an error reading the png data.
 */
public PDPng(PDDocument doc, InputStream is) throws IOException {
    super(doc, "png");

    System.out.println("reading in png");

    COSDictionary dic = getCOSStream();

    dic.setItem(COSName.SUBTYPE, COSName.IMAGE);
    //dic.setItem(COSName.TYPE, COSName.XOBJECT);

    data = getCOSStream().createFilteredStream();

    readPng(is);

    setWidth(imageWidth);
    setHeight(imageHeight);
    dic.setInt(COSName.BITS_PER_COMPONENT, bitDepth);

    if ((colorType & PNG_TYPE_PALETTE) != 0) {
        getCOSStream().setItem(COSName.COLORSPACE, paldata);
    } else if ((colorType & PNG_TYPE_COLOR) != 0) {
        setColorSpace(PDDeviceRGB.INSTANCE);
    } else {
        setColorSpace(new PDDeviceGray());
    }

    COSDictionary filterParams = new COSDictionary();
    filterParams.setInt(COSName.PREDICTOR, 15); // png adaptive predictor
    filterParams.setInt(COSName.COLORS,
            ((colorType & PNG_TYPE_COLOR) == 0 || (colorType & PNG_TYPE_PALETTE) != 0) ? 1 : 3);
    filterParams.setInt(COSName.BITS_PER_COMPONENT, bitDepth);
    filterParams.setInt(COSName.COLUMNS, imageWidth);
    filterParams.setDirect(true);

    dic.setItem(COSName.DECODE_PARMS, filterParams);
    dic.setItem(COSName.FILTER, COSName.FLATE_DECODE);

    dic.setInt(COSName.LENGTH, dataLen);
    dic.getDictionaryObject(COSName.LENGTH).setDirect(true);
}

From source file:se.streamsource.streamflow.web.application.pdf.Underlay.java

License:Apache License

private void mergePage(COSArray array, PDPage page) {
    int layoutPageNum = pageCount % layoutPages.size();
    LayoutPage layoutPage = (LayoutPage) layoutPages.get(layoutPageNum);
    PDResources resources = page.findResources();
    if (resources == null) {
        resources = new PDResources();
        page.setResources(resources);// w  w  w .j av a2 s  .  c om
    }
    COSDictionary docResDict = resources.getCOSDictionary();
    COSDictionary layoutResDict = layoutPage.res;

    mergeArray(COSName.PROC_SET, docResDict, layoutResDict);
    mergeDictionary(COSName.COLORSPACE, docResDict, layoutResDict, layoutPage.objectNameMap);
    mergeDictionary(COSName.FONT, docResDict, layoutResDict, layoutPage.objectNameMap);
    mergeDictionary(COSName.XOBJECT, docResDict, layoutResDict, layoutPage.objectNameMap);
    mergeDictionary(COSName.EXT_G_STATE, docResDict, layoutResDict, layoutPage.objectNameMap);

    array.add(0, layoutPage.contents);

}