Beispiel #1
0
 /**
  * This will return a list of alternate color spaces(PDColorSpace) if the display application does
  * not support this icc stream.
  *
  * @return A list of alternate color spaces.
  * @throws IOException If there is an error getting the alternate color spaces.
  */
 public List getAlternateColorSpaces() throws IOException {
   COSBase alternate = stream.getDictionaryObject(COSName.getPDFName("Alternate"));
   COSArray alternateArray = null;
   if (alternate == null) {
     alternateArray = new COSArray();
     int numComponents = getNumberOfComponents();
     String csName = null;
     if (numComponents == 1) {
       csName = PDDeviceGray.NAME;
     } else if (numComponents == 3) {
       csName = PDDeviceRGB.NAME;
     } else if (numComponents == 4) {
       csName = PDDeviceCMYK.NAME;
     } else {
       throw new IOException("Unknown colorspace number of components:" + numComponents);
     }
     alternateArray.add(COSName.getPDFName(csName));
   } else {
     if (alternate instanceof COSArray) {
       alternateArray = (COSArray) alternate;
     } else if (alternate instanceof COSName) {
       alternateArray = new COSArray();
       alternateArray.add(alternate);
     } else {
       throw new IOException(
           "Error: expected COSArray or COSName and not " + alternate.getClass().getName());
     }
   }
   List retval = new ArrayList();
   for (int i = 0; i < alternateArray.size(); i++) {
     retval.add(PDColorSpaceFactory.createColorSpace((COSName) alternateArray.get(i)));
   }
   return new COSArrayList(retval, alternateArray);
 }
Beispiel #2
0
 private COSArray getRangeArray(int n) {
   COSArray rangeArray = (COSArray) stream.getDictionaryObject(COSName.getPDFName("Range"));
   if (rangeArray == null) {
     rangeArray = new COSArray();
     stream.setItem(COSName.getPDFName("Range"), rangeArray);
     while (rangeArray.size() < n * 2) {
       rangeArray.add(new COSFloat(-100));
       rangeArray.add(new COSFloat(100));
     }
   }
   return rangeArray;
 }