Example #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);
 }
Example #2
0
 /** Constructor, default DeviceRGB, hival 255. */
 public PDIndexed() {
   array = new COSArray();
   array.add(COSName.getPDFName(NAME));
   array.add(COSName.getPDFName(PDDeviceRGB.NAME));
   array.add(new COSInteger(255));
   array.add(com.progdan.pdf2txt.cos.COSNull.NULL);
 }
Example #3
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;
 }
Example #4
0
 /**
  * This will set the list of alternate color spaces. This should be a list of PDColorSpace
  * objects.
  *
  * @param list The list of colorspace objects.
  */
 public void setAlternateColorSpaces(List list) {
   COSArray altArray = null;
   if (list != null) {
     altArray = COSArrayList.converterToCOSArray(list);
   }
   stream.setItem(COSName.getPDFName("Alternate"), altArray);
 }
Example #5
0
 /**
  * This will set the metadata stream that is associated with this color space.
  *
  * @param metadata The new metadata stream.
  */
 public void setMetadata(COSStream metadata) {
   stream.setItem(COSName.getPDFName("Metadata"), metadata);
 }
Example #6
0
 /**
  * This will get the metadata stream for this object. Null if there is no metadata stream.
  *
  * @return The metadata stream, if it exists.
  */
 public COSStream getMetadata() {
   return (COSStream) stream.getDictionaryObject(COSName.getPDFName("Metadata"));
 }
Example #7
0
 /**
  * This will set the number of color components.
  *
  * @param n The number of color components.
  */
 public void setNumberOfComponents(int n) {
   stream.setItem(COSName.getPDFName("N"), new COSInteger(n));
 }
Example #8
0
 /**
  * This will return the number of color components. As of PDF 1.4 this will be 1,3,4.
  *
  * @return The number of components in this color space.
  * @throws IOException If there is an error getting the number of color components.
  */
 public int getNumberOfComponents() throws IOException {
   COSNumber n = (COSNumber) stream.getDictionaryObject(COSName.getPDFName("N"));
   return n.intValue();
 }