Class Image

All Implemented Interfaces:
Dimensions

public class Image extends Box
Represents an image to be inserted into the document.
  • Method Details

    • getCaption

      public Box getCaption()
      The caption as a box, or null if there's no caption.
    • load

      public static Image load(Path imagePath, long maxWidth, long maxHeight, @Nullable @Nullable Block block, Config config, FontManager fontManager, Bookmarks bookmarks, Sections sections, HyphenDictionary hyphenDictionary, org.apache.pdfbox.pdmodel.PDDocument pdDoc) throws IOException
      Loads an image as a new element. The size of the box is the aspect ratio of the image zoomed to fit in the specified max width and height. The image is entirely height (no depth). In other words, the baseline is at the bottom of the image.
      Throws:
      IOException
    • layOutHorizontally

      public long layOutHorizontally(long x, long y, org.apache.pdfbox.pdmodel.PDPageContentStream contents) throws IOException
      Description copied from class: Element
      Add the element to the contents as part of a horizontal sequence.
      Overrides:
      layOutHorizontally in class Box
      Parameters:
      x - the left-most point of the element.
      y - the baseline of the element.
      contents - the stream to add the element to.
      Returns:
      how much to move right afterward.
      Throws:
      IOException
    • layOutVertically

      public long layOutVertically(long x, long y, org.apache.pdfbox.pdmodel.PDPageContentStream contents) throws IOException
      Description copied from class: Element
      Add the element to the contents as part of a vertical sequence.
      Overrides:
      layOutVertically in class Box
      Parameters:
      x - the left-most point of the element.
      y - the upper-left point of the element.
      contents - the stream to add the element to.
      Returns:
      how much to move down afterward.
      Throws:
      IOException
    • toString

      public String toString()
      Overrides:
      toString in class Box
    • preprocessImage

      public static Path preprocessImage(Path origPath, long maxWidth, long maxHeight) throws IOException
      Make a copy of this image, ensuring that its resolution is not unnecessarily high. Note that the cached file will be recomputed if it's missing or old, but not if the resolution (width or height) change. In that case the cache directory should be deleted. The cache is based on the filename. Two different files with the same filename will clash.
      Parameters:
      origPath - the path of the original (possibly high-res) image.
      maxWidth - the width of the space this image will fit in.
      maxHeight - the height of the space this image will fit in.
      Returns:
      a path to the image to load instead (possibly equal to origPath).
      Throws:
      IOException - if something goes wrong with processing the image.