Package com.itextpdf.text.pdf.parser
Class InlineImageUtils
- java.lang.Object
-
- com.itextpdf.text.pdf.parser.InlineImageUtils
-
public final class InlineImageUtils extends java.lang.Object
Utility methods to help with processing of inline images- Since:
- 5.0.4
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
InlineImageUtils.InlineImageParseException
Simple class in case users need to differentiate an exception from processing inline images vs other exceptions
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<PdfName,PdfName>
inlineImageColorSpaceAbbreviationMap
Map between value abbreviations allowed in dictionary of inline images for COLORSPACEprivate static java.util.Map<PdfName,PdfName>
inlineImageEntryAbbreviationMap
Map between key abbreviations allowed in dictionary of inline images and their equivalent image dictionary keysprivate static java.util.Map<PdfName,PdfName>
inlineImageFilterAbbreviationMap
Map between value abbreviations allowed in dictionary of inline images for FILTERprivate static Logger
LOGGER
-
Constructor Summary
Constructors Modifier Constructor Description private
InlineImageUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static int
computeBytesPerRow(PdfDictionary imageDictionary, PdfDictionary colorSpaceDic)
Computes the number of unfiltered bytes that each row of the image will contain.private static PdfObject
getAlternateValue(PdfName key, PdfObject value)
Transforms value abbreviations into their corresponding real valueprivate static int
getComponentsPerPixel(PdfName colorSpaceName, PdfDictionary colorSpaceDic)
private static boolean
inlineImageStreamBytesAreComplete(byte[] samples, PdfDictionary imageDictionary)
static InlineImageInfo
parseInlineImage(PdfContentParser ps, PdfDictionary colorSpaceDic)
Parses an inline image from the provided content parser.private static PdfDictionary
parseInlineImageDictionary(PdfContentParser ps)
Parses the next inline image dictionary from the parser.private static byte[]
parseInlineImageSamples(PdfDictionary imageDictionary, PdfDictionary colorSpaceDic, PdfContentParser ps)
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.private static byte[]
parseUnfilteredSamples(PdfDictionary imageDictionary, PdfDictionary colorSpaceDic, PdfContentParser ps)
Parses the samples of the image from the underlying content parser, ignoring all filters.
-
-
-
Field Detail
-
LOGGER
private static final Logger LOGGER
-
inlineImageEntryAbbreviationMap
private static final java.util.Map<PdfName,PdfName> inlineImageEntryAbbreviationMap
Map between key abbreviations allowed in dictionary of inline images and their equivalent image dictionary keys
-
inlineImageColorSpaceAbbreviationMap
private static final java.util.Map<PdfName,PdfName> inlineImageColorSpaceAbbreviationMap
Map between value abbreviations allowed in dictionary of inline images for COLORSPACE
-
-
Method Detail
-
parseInlineImage
public static InlineImageInfo parseInlineImage(PdfContentParser ps, PdfDictionary colorSpaceDic) throws java.io.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:
java.io.IOException
- if anything goes wring with the parsingInlineImageUtils.InlineImageParseException
- if parsing of the inline image failed due to issues specific to inline image processing
-
parseInlineImageDictionary
private static PdfDictionary parseInlineImageDictionary(PdfContentParser ps) throws java.io.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:
java.io.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 forvalue
- 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 java.io.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 imageps
- the content parser- Returns:
- the samples of the image
- Throws:
java.io.IOException
- if anything bad happens during parsing
-
parseInlineImageSamples
private static byte[] parseInlineImageSamples(PdfDictionary imageDictionary, PdfDictionary colorSpaceDic, PdfContentParser ps) throws java.io.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 imageps
- the content parser- Returns:
- the samples of the image
- Throws:
java.io.IOException
- if anything bad happens during parsing
-
inlineImageStreamBytesAreComplete
private static boolean inlineImageStreamBytesAreComplete(byte[] samples, PdfDictionary imageDictionary)
-
-