private void _generateImagesPB(
      FileVersion fileVersion,
      PDPage pdPage,
      int dpi,
      int height,
      int width,
      boolean thumbnail,
      int index)
      throws Exception {

    // Generate images

    RenderedImage renderedImage =
        pdPage.convertToImage(BufferedImage.TYPE_INT_RGB, PropsValues.DL_FILE_ENTRY_THUMBNAIL_DPI);

    if (height != 0) {
      renderedImage = ImageProcessorUtil.scale(renderedImage, width, height);
    } else {
      renderedImage = ImageProcessorUtil.scale(renderedImage, width);
    }

    // Store images

    String tempFileId =
        DLUtil.getTempFileId(fileVersion.getFileEntryId(), fileVersion.getVersion());

    File thumbnailTempFile = null;

    try {
      if (thumbnail) {
        thumbnailTempFile = getThumbnailTempFile(tempFileId);

        thumbnailTempFile.createNewFile();

        ImageIO.write(renderedImage, THUMBNAIL_TYPE, new FileOutputStream(thumbnailTempFile));

        addFileToStore(
            fileVersion.getCompanyId(), THUMBNAIL_PATH,
            getThumbnailFilePath(fileVersion), thumbnailTempFile);
      } else {
        thumbnailTempFile = getPreviewTempFile(tempFileId, index);

        thumbnailTempFile.createNewFile();

        ImageIO.write(renderedImage, PREVIEW_TYPE, new FileOutputStream(thumbnailTempFile));

        addFileToStore(
            fileVersion.getCompanyId(), PREVIEW_PATH,
            getPreviewFilePath(fileVersion, index), thumbnailTempFile);
      }
    } finally {
      FileUtil.delete(thumbnailTempFile);
    }
  }
Пример #2
0
  protected Image getImage(InputStream is, byte[] bytes) throws PortalException, SystemException {

    try {
      if (is != null) {
        bytes = FileUtil.getBytes(is);
      }

      ImageBag imageBag = ImageProcessorUtil.read(bytes);

      RenderedImage renderedImage = imageBag.getRenderedImage();
      String type = imageBag.getType();

      if (renderedImage == null) {
        throw new ImageTypeException();
      }

      int height = renderedImage.getHeight();
      int width = renderedImage.getWidth();
      int size = bytes.length;

      Image image = new ImageImpl();

      image.setTextObj(bytes);
      image.setType(type);
      image.setHeight(height);
      image.setWidth(width);
      image.setSize(size);

      return image;
    } catch (IOException ioe) {
      throw new SystemException(ioe);
    } finally {
      if (is != null) {
        try {
          is.close();
        } catch (IOException ioe) {
          if (_log.isWarnEnabled()) {
            _log.warn(ioe);
          }
        }
      }
    }
  }