Class Image

java.lang.Object
pro.verron.officestamper.preset.Image

public final class Image extends Object
This class describes an image, which will be inserted into a document.
Since:
1.0.0
Author:
Joseph Verron, Romster
  • Constructor Details

    • Image

      public Image(InputStream source) throws IOException
      Constructor for Image.
      Parameters:
      source -
      • content of the image as InputStream
      Throws:
      IOException - if any.
    • Image

      public Image(InputStream source, @Nullable Integer maxWidth)
      Constructor for Image.
      Parameters:
      source - content of the image as InputStream
      maxWidth - max width of the image in twip
    • Image

      public Image(InputStream source, @Nullable Integer maxWidth, String filenameHint, String altText)
      Constructor for Image.
      Parameters:
      source - content of the image as InputStream
      maxWidth - max width of the image in twip
      filenameHint - filename hint for the image.
      altText - alternative text for the image.
    • Image

      public Image(byte[] imageBytes)
      Constructor for Image.
      Parameters:
      imageBytes -
      • content of the image as an array of the bytes
    • Image

      public Image(byte[] imageBytes, @Nullable Integer maxWidth)
      Constructor for Image.
      Parameters:
      imageBytes -
      • content of the image as an array of the bytes
      maxWidth -
      • max width of the image in twip
    • Image

      public Image(byte[] imageBytes, @Nullable Integer maxWidth, String filenameHint, String altText)
      Constructor for Image.
      Parameters:
      imageBytes - content of the image as an array of the bytes
      maxWidth - max width of the image in twip
      filenameHint - filename hint for the image.
      altText - alternative text for the image.
  • Method Details

    • getBytes

      public byte[] getBytes()

      Returns the byte content of the image.

      The bytes are lazily cached from the source InputStream on first access. Subsequent calls return the cached bytes without re-reading the stream.

      Returns:
      the byte content of the image
      Throws:
      OfficeStamperException - if the image bytes cannot be read from the source stream
    • getAltText

      public String getAltText()
      Returns the alternative text for the image.
      Returns:
      the alternative text
    • getFilenameHint

      public String getFilenameHint()
      Returns the filename hint for the image.
      Returns:
      the filename hint
    • getMaxWidth

      public Optional<Integer> getMaxWidth()
      Returns the maximum width of the image in twip, if specified.
      Returns:
      an Optional containing the maximum width in twip, or empty if not specified