예제 #1
0
  public Map<String, Image> getImages() {
    Map<String, Image> images = new HashMap<String, Image>();
    COSDictionary xobjectsDictionary =
        (COSDictionary) getDictionary().getDictionaryObject(COSName.XOBJECT);
    if (xobjectsDictionary == null) {
      return images;
    }

    for (COSName objName : xobjectsDictionary.keySet()) {
      try {
        COSBase xobject = xobjectsDictionary.getDictionaryObject(objName);
        if (xobject instanceof COSStream) {
          COSStream xstream = (COSStream) xobject;
          String subtype = xstream.getNameAsString(COSName.SUBTYPE);
          if (!subtype.equals("Image")) {
            continue;
          }

          PDFunction tintTransformer = getTintTransformer(xstream);

          PDStream pdstream = new PDStream(xstream);
          byte[] data = getStreamData(pdstream);
          Image image = processStream(data, tintTransformer);
          if (image != null) {
            images.put(objName.getName(), image);
          }
        }
      } catch (Exception e) {
        LOG.error("error while creating a image", e);
      }
    }

    return images;
  }