Class InlineImageUtils

java.lang.Object
com.itextpdf.text.pdf.parser.InlineImageUtils

public final class InlineImageUtils extends Object
Utility methods to help with processing of inline images
Since:
5.0.4
  • Field Details

    • LOGGER

      private static final Logger LOGGER
    • inlineImageEntryAbbreviationMap

      private static final Map<PdfName,PdfName> inlineImageEntryAbbreviationMap
      Map between key abbreviations allowed in dictionary of inline images and their equivalent image dictionary keys
    • inlineImageColorSpaceAbbreviationMap

      private static final Map<PdfName,PdfName> inlineImageColorSpaceAbbreviationMap
      Map between value abbreviations allowed in dictionary of inline images for COLORSPACE
    • inlineImageFilterAbbreviationMap

      private static final Map<PdfName,PdfName> inlineImageFilterAbbreviationMap
      Map between value abbreviations allowed in dictionary of inline images for FILTER
  • Constructor Details

    • InlineImageUtils

      private InlineImageUtils()
  • Method Details

    • parseInlineImage

      public static InlineImageInfo parseInlineImage(PdfContentParser ps, PdfDictionary colorSpaceDic) throws IOException
      Parses an inline image from the provided content parser. The parser must be positioned immediately following the BI operator in the content stream. The parser will be left with current position immediately following the EI operator that terminates the inline image
      Parameters:
      ps - the content parser to use for reading the image.
      colorSpaceDic - a color space dictionary
      Returns:
      the parsed image
      Throws:
      IOException - if anything goes wring with the parsing
      InlineImageUtils.InlineImageParseException - if parsing of the inline image failed due to issues specific to inline image processing
    • parseInlineImageDictionary

      private static PdfDictionary parseInlineImageDictionary(PdfContentParser ps) throws IOException
      Parses the next inline image dictionary from the parser. The parser must be positioned immediately following the EI operator. The parser will be left with position immediately following the whitespace character that follows the ID operator that ends the inline image dictionary.
      Parameters:
      ps - the parser to extract the embedded image information from
      Returns:
      the dictionary for the inline image, with any abbreviations converted to regular image dictionary keys and values
      Throws:
      IOException - if the parse fails
    • getAlternateValue

      private static PdfObject getAlternateValue(PdfName key, PdfObject value)
      Transforms value abbreviations into their corresponding real value
      Parameters:
      key - the key that the value is for
      value - the value that might be an abbreviation
      Returns:
      if value is an allowed abbreviation for the key, the expanded value for that abbreviation. Otherwise, value is returned without modification
    • getComponentsPerPixel

      private static int getComponentsPerPixel(PdfName colorSpaceName, PdfDictionary colorSpaceDic)
      Parameters:
      colorSpaceName - the name of the color space. If null, a bi-tonal (black and white) color space is assumed.
      Returns:
      the components per pixel for the specified color space
    • computeBytesPerRow

      private static int computeBytesPerRow(PdfDictionary imageDictionary, PdfDictionary colorSpaceDic)
      Computes the number of unfiltered bytes that each row of the image will contain. If the number of bytes results in a partial terminating byte, this number is rounded up per the PDF specification
      Parameters:
      imageDictionary - the dictionary of the inline image
      Returns:
      the number of bytes per row of the image
    • parseUnfilteredSamples

      private static byte[] parseUnfilteredSamples(PdfDictionary imageDictionary, PdfDictionary colorSpaceDic, PdfContentParser ps) throws IOException
      Parses the samples of the image from the underlying content parser, ignoring all filters. The parser must be positioned immediately after the ID operator that ends the inline image's dictionary. The parser will be left positioned immediately following the EI operator. This is primarily useful if no filters have been applied.
      Parameters:
      imageDictionary - the dictionary of the inline image
      ps - the content parser
      Returns:
      the samples of the image
      Throws:
      IOException - if anything bad happens during parsing
    • parseInlineImageSamples

      private static byte[] parseInlineImageSamples(PdfDictionary imageDictionary, PdfDictionary colorSpaceDic, PdfContentParser ps) throws IOException
      Parses the samples of the image from the underlying content parser, accounting for filters The parser must be positioned immediately after the ID operator that ends the inline image's dictionary. The parser will be left positioned immediately following the EI operator. Note:This implementation does not actually apply the filters at this time
      Parameters:
      imageDictionary - the dictionary of the inline image
      ps - the content parser
      Returns:
      the samples of the image
      Throws:
      IOException - if anything bad happens during parsing
    • inlineImageStreamBytesAreComplete

      private static boolean inlineImageStreamBytesAreComplete(byte[] samples, PdfDictionary imageDictionary)