Class BinaryPartAbstractImage

java.lang.Object
Direct Known Subclasses:
ImageBmpPart, ImageEpsPart, ImageGifPart, ImageJpegPart, ImagePngPart, ImageTiffPart, MetafilePart

public abstract class BinaryPartAbstractImage
extends BinaryPart
  • Field Details

    • log

      protected static org.slf4j.Logger log
  • Constructor Details

  • Method Details

    • getImageInfo

      @Deprecated public org.apache.xmlgraphics.image.loader.ImageInfo getImageInfo()
      Deprecated.
    • setImageInfo

      @Deprecated public void setImageInfo​(org.apache.xmlgraphics.image.loader.ImageInfo imageInfo)
      Deprecated.
    • getRels

      public java.util.List<Relationship> getRels()
    • getRelLast

      public Relationship getRelLast()
    • setDensity

      public static void setDensity​(int density)
      Set the resolution at which a PDF or EPS is converted to PNG. For best quality, you should set this to match the target output device. Higher densities (eg 600) give better quality, at the expense of conversion time (and file size).
      Parameters:
      density -
    • getImageManager

      protected static org.apache.xmlgraphics.image.loader.ImageManager getImageManager()
    • createImagePart

      public static BinaryPartAbstractImage createImagePart​(WordprocessingMLPackage wordMLPackage, byte[] bytes) throws java.lang.Exception
      Create an image part from the provided byte array, attach it to the docx main document part, and return it.
      Parameters:
      wordMLPackage -
      sourcePart -
      bytes -
      Returns:
      Throws:
      java.lang.Exception
    • createImagePart

      public static BinaryPartAbstractImage createImagePart​(WordprocessingMLPackage wordMLPackage, java.io.File imageFile) throws java.lang.Exception
      Possibility to put directly an image filePath instead of giving an image byte array
      Parameters:
      wordMLPackage -
      imageFile -
      Throws:
      java.lang.Exception
    • createImageName

      @Deprecated public static java.lang.String createImageName​(Base sourcePart, java.lang.String proposedRelId, java.lang.String ext)
      Deprecated.
      This method assumes your package is a docx (not a pptx or xlsx).
      Parameters:
      sourcePart -
      proposedRelId -
      ext -
      Returns:
    • createImageName

      public static java.lang.String createImageName​(OpcPackage opcPackage, Base sourcePart, java.lang.String proposedRelId, java.lang.String ext)
      Parameters:
      opcPackage -
      sourcePart -
      proposedRelId -
      ext - extension eg png
      Returns:
    • createImagePart

      public static BinaryPartAbstractImage createImagePart​(OpcPackage opcPackage, Part sourcePart, byte[] bytes) throws java.lang.Exception
      Create an image part from the provided byte array, attach it to the source part (eg the main document part, a header part etc), and return it. Works for both docx and pptx. Note: this method creates a temp file (and attempts to delete it). That's because it uses org.apache.xmlgraphics
      Parameters:
      opcPackage -
      sourcePart -
      bytes -
      Returns:
      Throws:
      java.lang.Exception
    • createImagePart

      @Deprecated public static BinaryPartAbstractImage createImagePart​(OpcPackage opcPackage, Part sourcePart, byte[] bytes, java.lang.String mime, java.lang.String ext) throws java.lang.Exception
      Deprecated.
      Create an image part from the provided byte array, attach it to the source part (eg the main document part, a header part etc), and return it. Works for both docx and pptx. Knowing the MIME type allows you to avoid ImageInfo, but you'll probably also need to know the image dimensions
      Parameters:
      opcPackage -
      sourcePart -
      bytes -
      mime - MIME type eg image/png
      ext - filename extension eg png
      Returns:
      Throws:
      java.lang.Exception
    • createImagePart

      public static BinaryPartAbstractImage createImagePart​(OpcPackage opcPackage, Part sourcePart, byte[] bytes, java.lang.String mime) throws java.lang.Exception
      Create an image part from the provided byte array, attach it to the source part (eg the main document part, a header part etc), and return it. Works for both docx and pptx. Knowing the MIME type allows you to avoid ImageInfo, but you'll probably also need to know the image dimensions
      Parameters:
      opcPackage -
      sourcePart -
      bytes -
      mime - MIME type eg image/png
      Returns:
      Throws:
      java.lang.Exception
    • createImagePart

      public static BinaryPartAbstractImage createImagePart​(OpcPackage opcPackage, Part sourcePart, java.io.File imageFile) throws java.lang.Exception
      Create an image part from the provided filePath image, attach it to the source part (eg the main document part, a header part etc), and return it. Works for both docx and pptx.
      Parameters:
      opcPackage -
      sourcePart -
      filePath -
      Returns:
      Throws:
      java.lang.Exception
    • createLinkedImagePart

      public static BinaryPartAbstractImage createLinkedImagePart​(WordprocessingMLPackage wordMLPackage, java.net.URL fileurl) throws java.lang.Exception
      Create a linked image part, and attach it as a rel of the docx main document part
      Parameters:
      wordMLPackage -
      fileurl -
      Returns:
      Throws:
      java.lang.Exception
    • createLinkedImagePart

      public static BinaryPartAbstractImage createLinkedImagePart​(OpcPackage opcPackage, Part sourcePart, java.net.URL url) throws java.lang.Exception
      Create a linked image part, and attach it as a rel of the specified source part (eg a header part). The current behaviour is that the part is added to the package, but since the target mode of the rel is external, the part is redundant.
      Parameters:
      wordMLPackage -
      sourcePart -
      url -
      Returns:
      Throws:
      java.lang.Exception
    • createImageInline

      @Deprecated public Inline createImageInline​(java.lang.String filenameHint, java.lang.String altText, int id1, int id2) throws java.lang.Exception
      Deprecated.
      Create a element suitable for this image, which can be _embedded_ in w:p/w:r/w:drawing. If the image is wider than the page, it will be scaled automatically. To avoid the deprecated warning, use the same method, but with an additional argument of false appended.
      Parameters:
      filenameHint - Any text, for example the original filename
      altText - Like HTML's alt text
      id1 - An id unique in the document
      id2 - Another id unique in the document None of these things seem to be exposed in Word 2007's user interface, but Word won't open the document if any of the attributes these go in (except @ desc) aren't present!
      Throws:
      java.lang.Exception
    • createImageInline

      public Inline createImageInline​(java.lang.String filenameHint, java.lang.String altText, int id1, int id2, boolean link) throws java.lang.Exception
      Create a element suitable for this image, which can be linked or embedded in w:p/w:r/w:drawing. If the image is wider than the page, it will be scaled automatically.
      Parameters:
      filenameHint - Any text, for example the original filename
      altText - Like HTML's alt text
      id1 - An id unique in the document
      id2 - Another id unique in the document
      link - true if this is to be linked not embedded None of these things seem to be exposed in Word 2007's user interface, but Word won't open the document if any of the attributes these go in (except @ desc) aren't present!
      Throws:
      java.lang.Exception
    • createImageInline

      public Inline createImageInline​(java.lang.String filenameHint, java.lang.String altText, int id1, int id2, boolean link, int maxWidth) throws java.lang.Exception
      Parameters:
      filenameHint -
      altText -
      id1 -
      id2 -
      link -
      maxWidth -
      Returns:
      Throws:
      java.lang.Exception
      Since:
      3.3.0
    • createImageInline

      @Deprecated public Inline createImageInline​(java.lang.String filenameHint, java.lang.String altText, int id1, int id2, long cx) throws java.lang.Exception
      Deprecated.
      Create a element suitable for this image, which can be _embedded_ in w:p/w:r/w:drawing. To avoid the deprecated warning, use the same method, but with an additional argument of false appended.
      Parameters:
      filenameHint - Any text, for example the original filename
      altText - Like HTML's alt text
      id1 - An id unique in the document
      id2 - Another id unique in the document
      cx - Image width in twip None of these things seem to be exposed in Word 2007's user interface, but Word won't open the document if any of the attributes these go in (except @ desc) aren't present!
      Throws:
      java.lang.Exception
    • createImageInline

      public Inline createImageInline​(java.lang.String filenameHint, java.lang.String altText, int id1, int id2, long cx, boolean link) throws java.lang.Exception
      Create a element suitable for this image, which can be _embedded_ in w:p/w:r/w:drawing.
      Parameters:
      filenameHint - Any text, for example the original filename
      altText - Like HTML's alt text
      id1 - An id unique in the document
      id2 - Another id unique in the document
      cx - Image width in twip
      link - true if this is to be linked not embedded None of these things seem to be exposed in Word 2007's user interface, but Word won't open the document if any of the attributes these go in (except @ desc) aren't present!
      Throws:
      java.lang.Exception
    • createImageInline

      public Inline createImageInline​(java.lang.String filenameHint, java.lang.String altText, int id1, int id2, long cx, long cy, boolean link) throws java.lang.Exception
      Create a element suitable for this image, which can be linked or embedded in w:p/w:r/w:drawing, specifying height and width. Note that you'd ordinarily use one of the methods which don't require you to specify height (cy).
      Parameters:
      filenameHint - Any text, for example the original filename
      altText - Like HTML's alt text
      id1 - An id unique in the document
      id2 - Another id unique in the document None of these things seem to be exposed in Word 2007's user interface, but Word won't open the document if any of the attributes these go in (except @ desc) aren't present!
      cx - Image width in EMU
      cy - Image height in EMU
      link - true if this is to be linked not embedded
      Throws:
      java.lang.Exception
    • getImageInfo

      public static org.apache.xmlgraphics.image.loader.ImageInfo getImageInfo​(java.net.URL url) throws java.lang.Exception
      Throws:
      java.lang.Exception
    • main

      public static void main​(java.lang.String[] args) throws java.lang.Exception
      Throws:
      java.lang.Exception
    • displayImageInfo

      public static void displayImageInfo​(org.apache.xmlgraphics.image.loader.ImageInfo info)
    • getImage

      public static byte[] getImage​(WordprocessingMLPackage wmlPkg, Graphic graphic)
      Convenience method, given a Graphic in a document, to get the byte[] representing the associated image The method assumes your image is in the main document part (as opposed to a header/footer etc)
      Parameters:
      wmlPkg -
      graphic -
      Returns:
    • convertToPNG

      public static void convertToPNG​(java.io.InputStream is, java.io.OutputStream os, int density) throws java.io.IOException, java.lang.InterruptedException
      Convert image formats which are not supported by Word (eg EPS, PDF), into ones which are. This requires ImageMagick to be on your system's path (renamed to imconvert); for EPS and PDF images, Ghostscript is also required.
      Parameters:
      is -
      os -
      density - PixelsPerInch
      Throws:
      java.io.IOException
      java.lang.InterruptedException
    • copy2

      public static void copy2​(java.io.InputStream is, java.io.OutputStream os) throws java.io.IOException
      Throws:
      java.io.IOException