Example #1
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 #2
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 #3
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 #4
0
 /**
  * Create a Java colorspace for this colorspace.
  *
  * @return A color space that can be used for Java AWT operations.
  * @throws IOException If there is an error creating the color space.
  */
 public ColorSpace createColorSpace() throws IOException {
   InputStream profile = null;
   ColorSpace cSpace = null;
   try {
     profile = stream.getUnfilteredStream();
     ICC_Profile iccProfile = ICC_Profile.getInstance(profile);
     cSpace = new ICC_ColorSpace(iccProfile);
   } finally {
     if (profile != null) {
       profile.close();
     }
   }
   return cSpace;
 }
Example #5
0
 private byte[] getLookupData() throws IOException {
   COSBase lookupTable = array.getObject(3);
   byte[] data = null;
   if (lookupTable instanceof COSString) {
     data = ((COSString) lookupTable).getBytes();
   } else if (lookupTable instanceof COSStream) {
     // Data will be small so just load the whole thing into memory for
     // easier processing
     COSStream lookupStream = (COSStream) lookupTable;
     InputStream input = lookupStream.getUnfilteredStream();
     ByteArrayOutputStream output = new ByteArrayOutputStream(1024);
     byte[] buffer = new byte[1024];
     int amountRead;
     while ((amountRead = input.read(buffer, 0, buffer.length)) != -1) {
       output.write(buffer, 0, amountRead);
     }
     data = output.toByteArray();
   } else if (lookupTable == null) {
     data = new byte[0];
   } else {
     throw new IOException("Error: Unknown type for lookup table " + lookupTable);
   }
   return data;
 }
Example #6
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 #7
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 #8
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 #9
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();
 }