Ejemplo n.º 1
0
  // *
  public final ImageRecord getMetadata(BufferedImage bi) throws DjatokaException {
    if (bi == null) throw new DjatokaException("Image Does Not Exist");

    logger.debug("getMetadata(BufferedImage): " + bi.getWidth());
    try {
      ImageRecord r = new ImageRecord();

      r.setWidth(bi.getWidth());
      r.setHeight(bi.getHeight());

      r.setDWTLevels(DEFAULT_LEVELS);
      r.setLevels(DEFAULT_LEVELS);

      r.setBitDepth(bi.getColorModel().getPixelSize());
      r.setNumChannels(bi.getColorModel().getNumColorComponents());
      // r.setCompositingLayerCount(getNumberOfPages(r)); // 'bi' refers to just one page extracted
      // from the PDF file.
      // logger.debug("r2: "+r.toString());

      // TODO

      return r;
    } catch (Exception e) {
      throw new DjatokaException(e);
    }
  }
Ejemplo n.º 2
0
  /**
   * Returns PDF props in ImageRecord
   *
   * @param r ImageRecord containing absolute file path of PDF file.
   * @return a populated ImageRecord object
   * @throws DjatokaException
   */
  @Override
  public final ImageRecord getMetadata(ImageRecord r) throws DjatokaException {
    if ((r.getImageFile() == null || !new File(r.getImageFile()).exists()) && r.getObject() == null)
      throw new DjatokaException("Image Does Not Exist: " + r.toString());
    logger.debug("Get metadata: " + r.toString());
    try {
      DjatokaDecodeParam params = new DjatokaDecodeParam();
      BufferedImage bi = process(r, params);

      r.setWidth(bi.getWidth());
      r.setHeight(bi.getHeight());
      r.setDWTLevels(DEFAULT_LEVELS);
      r.setLevels(DEFAULT_LEVELS);
      r.setBitDepth(bi.getColorModel().getPixelSize());
      r.setNumChannels(bi.getColorModel().getNumColorComponents());

      // r.setCompositingLayerCount(getNumberOfPages(r)); // Semantics: number of pages in the PDF
      // file.
      HashMap<String, String> pdfProps = (HashMap<String, String>) getPDFProperties(r);
      int n = Integer.parseInt(pdfProps.remove("Pages"));
      r.setCompositingLayerCount(n);

      // Since it is not possible for the viewer to query about a specific page's width and height
      // (because in Djatoka's point of view a PDF is just one image with various compositing
      // layers, which are the pages),
      // at this point right here we query the PDF file about the size of all pages and store this
      // information in a Map. This map can be returned by getMetadata by setting it as the
      // instProps member of the
      // ImageRecord class, which Djatoka already implements and which is returned as JSON to the
      // viewer JS.
      // The viewer then has to store this information and later query it instead of asking Djatoka
      // (getMetadata) again.
      // Map<String, String> instProps = getPagesSizes(r);
      r.setInstProps(pdfProps);
      logger.debug("instProps: " + r.getInstProps());

      logger.debug("Get metadata: " + r.toString());
    } catch (Exception e) {
      throw new DjatokaException(e);
    }

    return r;
  }