Class: Image

Core.PDFNet. Image


new Image()

Image class provides common methods for working with PDF images. Note: PDF::Element contains a similar interface used to access image data. To create the Image object from image PDF::Element, pass the Element's SDF/Cos dictionary to Image constructor (i.e. Image image(element->GetXObject()) )

Members


<static> InputFilter

Properties:
Name Type Description
e_none number
e_jpeg number
e_jp2 number
e_flate number
e_g3 number
e_g4 number
e_ascii_hex number

Methods


<static> createDirectFromMemory(doc, buf, width, height, bpc, color_space, input_format)

Directly embed the image that is already compressed using the Image::InputFilter format. The function can be used to pass-through pre-compressed image data.
Parameters:
Name Type Description
doc Core.PDFNet.PDFDoc | Core.PDFNet.SDFDoc | Core.PDFNet.FDFDoc A document to which the image should be added. The 'Doc' object can be obtained using Obj::GetDoc() or PDFDoc::GetSDFDoc().
buf ArrayBuffer | Int8Array | Uint8Array | Uint8ClampedArray The stream or buffer containing compressed image data. The compression format must match the input_format parameter.
width number The width of the image, in samples.
height number The height of the image, in samples.
bpc number The number of bits used to represent each color component.
color_space Core.PDFNet.ColorSpace The color space in which image samples are specified.
input_format number
PDFNet.Image.InputFilter = {
	e_none : 0
	e_jpeg : 1
	e_jp2 : 2
	e_flate : 3
	e_g3 : 4
	e_g4 : 5
	e_ascii_hex : 6
}
Image::InputFilter describing the format of pre-compressed image data.
Returns:
A promise that resolves to pDF::Image object representing the embedded image.
Type
Promise.<Core.PDFNet.Image>

<static> createDirectFromStream(doc, image_data, width, height, bpc, color_space, input_format)

Embed the raw image data taking into account specified compression hints. Note: see the above method for details.
Parameters:
Name Type Description
doc Core.PDFNet.PDFDoc | Core.PDFNet.SDFDoc | Core.PDFNet.FDFDoc
image_data Core.PDFNet.FilterReader
width number
height number
bpc number
color_space Core.PDFNet.ColorSpace
input_format number
PDFNet.Image.InputFilter = {
	e_none : 0
	e_jpeg : 1
	e_jp2 : 2
	e_flate : 3
	e_g3 : 4
	e_g4 : 5
	e_ascii_hex : 6
}
Returns:
A promise that resolves to an object of type: "PDFNet.Image"
Type
Promise.<Core.PDFNet.Image>

<static> createFromMemory(doc, buf, width, height, bpc, color_space [, encoder_hints])

Create and embed an Image. Embed the raw image data taking into account specified compression hints. By default the function will compress all images using Flate compression. It is possible to fine tune compression or to select a different compression algorithm using 'encoder_hints' object.
Parameters:
Name Type Argument Description
doc Core.PDFNet.PDFDoc | Core.PDFNet.SDFDoc | Core.PDFNet.FDFDoc A document to which the image should be added. The 'Doc' object can be obtained using Obj::GetDoc() or PDFDoc::GetSDFDoc().
buf ArrayBuffer | Int8Array | Uint8Array | Uint8ClampedArray The stream or buffer containing image data. The image data must not be compressed and must follow PDF format for sample representation (please refer to section 4.8.2 'Sample Representation' in PDF Reference Manual for details).
width number The width of the image, in samples.
height number The height of the image, in samples.
bpc number The number of bits used to represent each color component.
color_space Core.PDFNet.ColorSpace The color space in which image samples are represented.
encoder_hints Core.PDFNet.Obj <optional>
An optional parameter that can be used to fine tune compression or to select a different compression algorithm. See Image::Create() for details.
Returns:
A promise that resolves to pDF::Image object representing the embedded image.
Type
Promise.<Core.PDFNet.Image>

<static> createFromMemory2(doc, buf [, encoder_hints])

Create and embed an Image. Embed the raw image data taking into account specified compression hints. Note: see Image::Create for details.
Parameters:
Name Type Argument Description
doc Core.PDFNet.PDFDoc | Core.PDFNet.SDFDoc | Core.PDFNet.FDFDoc
buf ArrayBuffer | Int8Array | Uint8Array | Uint8ClampedArray
encoder_hints Core.PDFNet.Obj <optional>
Returns:
A promise that resolves to an object of type: "PDFNet.Image"
Type
Promise.<Core.PDFNet.Image>

<static> createFromObj( [image_xobject])

Create an image from an existing image represented as a SDF/Cos object. Note: To create the Image object from image PDF::Element, pass the Element's SDF/Cos dictionary to Image constructor (i.e. Image image(element->GetXObject()))
Parameters:
Name Type Argument Description
image_xobject Core.PDFNet.Obj <optional>
Returns:
A promise that resolves to an object of type: "PDFNet.Image"
Type
Promise.<Core.PDFNet.Image>

<static> createFromStream(doc, image_data, width, height, bpc, color_space [, encoder_hints])

Create and embed an Image. Embed the raw image data taking into account specified compression hints. Note: see Image::Create for details.
Parameters:
Name Type Argument Description
doc Core.PDFNet.PDFDoc | Core.PDFNet.SDFDoc | Core.PDFNet.FDFDoc
image_data Core.PDFNet.FilterReader
width number
height number
bpc number
color_space Core.PDFNet.ColorSpace
encoder_hints Core.PDFNet.Obj <optional>
Returns:
A promise that resolves to an object of type: "PDFNet.Image"
Type
Promise.<Core.PDFNet.Image>

<static> createFromStream2(doc, image_data [, encoder_hints])

Create and embed an Image. Embed the raw image data taking into account specified compression hints. Note: see Image::Create for details. Note: PDFNet takes ownership of the filter
Parameters:
Name Type Argument Description
doc Core.PDFNet.PDFDoc | Core.PDFNet.SDFDoc | Core.PDFNet.FDFDoc
image_data Core.PDFNet.Filter
encoder_hints Core.PDFNet.Obj <optional>
Returns:
A promise that resolves to an object of type: "PDFNet.Image"
Type
Promise.<Core.PDFNet.Image>

<static> createFromURL(doc, url [, encoder_hints] [, options])

This function will fully download the image url as a memory buffer and embed it in the supplied PDFDoc.
Parameters:
Name Type Argument Description
doc Core.PDFNet.PDFDoc | Core.PDFNet.SDFDoc | Core.PDFNet.FDFDoc the PDF document in which to embed the image
url string The image url to download and embed.
encoder_hints number <optional>
options object <optional>
Additional options
Properties
Name Type Description
withCredentials boolean Whether to set the withCredentials property on the XMLHttpRequest
customHeaders object An object containing custom HTTP headers to be used when downloading the document
Returns:
A promise that resolves to an object of type: "Image"
Type
Promise.<Core.PDFNet.Image>

<static> createImageMask(doc, buf, width, height [, encoder_hints])

Create and embed an ImageMask. Embed the raw image data taking into account specified compression hints. The ImageMask can be used as a stencil mask for painting in the current color or as an explicit mask specifying which areas of the image to paint and which to mask out. One of the most important uses of stencil masking is for painting character glyphs represented as bitmaps.
Parameters:
Name Type Argument Description
doc Core.PDFNet.PDFDoc | Core.PDFNet.SDFDoc | Core.PDFNet.FDFDoc A document to which the image should be added. The 'Doc' object can be obtained using Obj::GetDoc() or PDFDoc::GetSDFDoc().
buf ArrayBuffer | Int8Array | Uint8Array | Uint8ClampedArray The stream or buffer containing image data stored in 1 bit per sample format. The image data must not be compressed and must follow PDF format for sample representation (please refer to section 4.8.2 'Sample Representation' in PDF Reference Manual for details).
width number The width of the image, in samples.
height number The height of the image, in samples.
encoder_hints Core.PDFNet.Obj <optional>
An optional parameter that can be used to fine tune compression or to select a different compression algorithm. See Image::Create() for details.
Returns:
A promise that resolves to pDF::Image object representing the embedded ImageMask.
Type
Promise.<Core.PDFNet.Image>

<static> createImageMaskFromStream(doc, image_data, width, height [, encoder_hints])

Create and embed an ImageMask. Note: see Image::CreateImageMask for details.
Parameters:
Name Type Argument Description
doc Core.PDFNet.PDFDoc | Core.PDFNet.SDFDoc | Core.PDFNet.FDFDoc
image_data Core.PDFNet.FilterReader
width number
height number
encoder_hints Core.PDFNet.Obj <optional>
Returns:
A promise that resolves to an object of type: "PDFNet.Image"
Type
Promise.<Core.PDFNet.Image>

<static> createSoftMask(doc, buf, width, height, bpc [, encoder_hints])

create and embed a Soft Mask. Embed the raw image data taking into account specified compression hints. A soft-mask image (see "Soft-Mask Images" in PDF Reference Manual) is used as a source of mask shape or mask opacity values in the transparent imaging model.
Parameters:
Name Type Argument Description
doc Core.PDFNet.PDFDoc | Core.PDFNet.SDFDoc | Core.PDFNet.FDFDoc A document to which the image should be added. The 'Doc' object can be obtained using Obj::GetDoc() or PDFDoc::GetSDFDoc().
buf ArrayBuffer | Int8Array | Uint8Array | Uint8ClampedArray The stream or buffer containing image data represented in DeviceGray color space (i.e. one component per sample). The image data must not be compressed and must follow PDF format for sample representation (please refer to section 4.8.2 'Sample Representation' in PDF Reference Manual for details).
width number The width of the image, in samples.
height number The height of the image, in samples.
bpc number The number of bits used to represent each color component.
encoder_hints Core.PDFNet.Obj <optional>
An optional parameter that can be used to fine tune compression or to select a different compression algorithm. See Image::Create() for details. Note: this feature is available only in PDF 1.4 and higher.
Returns:
A promise that resolves to an object of type: "PDFNet.Image"
Type
Promise.<Core.PDFNet.Image>

<static> createSoftMaskFromStream(doc, image_data, width, height, bpc [, encoder_hints])

Create and embed a Soft Mask. Embed the raw image data taking into account specified compression hints. Note: see Image::CreateSoftMask for details.
Parameters:
Name Type Argument Description
doc Core.PDFNet.PDFDoc | Core.PDFNet.SDFDoc | Core.PDFNet.FDFDoc
image_data Core.PDFNet.FilterReader
width number
height number
bpc number
encoder_hints Core.PDFNet.Obj <optional>
Returns:
A promise that resolves to an object of type: "PDFNet.Image"
Type
Promise.<Core.PDFNet.Image>

copy()

Copy Constructor
Returns:
A promise that resolves to an object of type: "PDFNet.Image"
Type
Promise.<Core.PDFNet.Image>

exportAsPngFromStream(writer)

Saves this image to a PNG output stream.
Parameters:
Name Type Description
writer Core.PDFNet.FilterWriter FilterWriter used to write to the output stream.
Returns:
Type
Promise.<void>

exportAsTiffFromStream(writer)

Saves this image to a TIFF output stream.
Parameters:
Name Type Description
writer Core.PDFNet.FilterWriter FilterWriter used to write to the output stream.
Returns:
Type
Promise.<void>

exportFromStream(writer)

Saves this image to the output stream. (0 PNG, 1 TIF, 2 JPEG).
Parameters:
Name Type Description
writer Core.PDFNet.FilterWriter A pointer to FilterWriter used to write to the output stream. If the parameter is null, nothing will be written to the output stream, but the function returns the format identifier.
Returns:
A promise that resolves to the number indicating the selected image format: Note: see the overloaded Image::Export method for more information.
Type
Promise.<number>

getBitsPerComponent()

Returns:
A promise that resolves to the number of bits used to represent each color component. Only a single value may be specified; the number of bits is the same for all color components. Valid values are 1, 2, 4, 8, and 16.
Type
Promise.<number>

getComponentNum()

Returns:
A promise that resolves to the number of color components per sample.
Type
Promise.<number>

getDecodeArray()

Returns:
A promise that resolves to decode array or NULL if the parameter is not specified. A decode object is an array of numbers describing how to map image samples into the range of values appropriate for the images color space . If ImageMask is true, the array must be either [0 1] or [1 0]; otherwise, its length must be twice the number of color components required by ColorSpace. Default value depends on the color space, See Table 4.36 in PDF Ref. Manual.
Type
Promise.<Core.PDFNet.Obj>

getImageColorSpace()

Returns:
A promise that resolves to the SDF object representing the color space in which image samples are specified or NULL if: the image is an image mask or is compressed using JPXDecode with missing ColorSpace entry in image dictionary. The returned color space may be any type of color space except Pattern.
Type
Promise.<Core.PDFNet.ColorSpace>

getImageData()

Returns:
A promise that resolves to a stream (filter) containing decoded image data
Type
Promise.<Core.PDFNet.Filter>

getImageDataSize()

Returns:
A promise that resolves to the size of image data in bytes
Type
Promise.<number>

getImageHeight()

Returns:
A promise that resolves to the height of the image, in samples.
Type
Promise.<number>

getImageRenderingIntent()

Returns:
A promise that resolves to the color rendering intent to be used in rendering the image.
Type
Promise.<number>
Example
Return value enum:
<pre>
PDFNet.GState.RenderingIntent = {
	e_absolute_colorimetric : 0
	e_relative_colorimetric : 1
	e_saturation : 2
	e_perceptual : 3
}
</pre>

getImageWidth()

Returns:
A promise that resolves to the width of the image, in samples.
Type
Promise.<number>

getMask()

Returns:
A promise that resolves to an image XObject defining an image mask to be applied to this image (See 'Explicit Masking', 4.8.5), or an array specifying a range of colors to be applied to it as a color key mask (See 'Color Key Masking'). If IsImageMask() return true, this method will return NULL.
Type
Promise.<Core.PDFNet.Obj>

getSDFObj()

Returns:
A promise that resolves to the underlying SDF/Cos object
Type
Promise.<Core.PDFNet.Obj>

getSoftMask()

Returns:
A promise that resolves to an image XObject defining a Soft Mask to be applied to this image (See section 7.5.4 'Soft-Mask Images' in PDF Reference Manual), or NULL if the image does not have the soft mask.
Type
Promise.<Core.PDFNet.Obj>

isImageInterpolate()

Returns:
A promise that resolves to a boolean indicating whether image interpolation is to be performed.
Type
Promise.<boolean>

isImageMask()

Returns:
A promise that resolves to a boolean indicating whether the inline image is to be treated as an image mask.
Type
Promise.<boolean>

isValid()

Returns:
A promise that resolves to whether this is a valid raster image. If the function returns false the underlying SDF/Cos object is not a valid raster image and this Image object should be treated as null.
Type
Promise.<boolean>

setMask(image_mask)

set an Explicit Image Mask.
Parameters:
Name Type Description
image_mask Core.PDFNet.Image An Image object which serves as an explicit mask for the base (this) image. The base image and the image mask need not have the same resolution (Width and Height values), but since all images are defined on the unit square in user space, their boundaries on the page will coincide; that is, they will overlay each other. The image mask indicates which places on the page are to be painted and which are to be masked out (left unchanged). Unmasked areas are painted with the corresponding portions of the base image; masked areas are not. Note: image_mask must be a valid image mask (i.e. image_mask.IsImageMask() must return true.
Returns:
Type
Promise.<void>

setMaskWithObj(mask)

set a Color Key Mask.
Parameters:
Name Type Description
mask Core.PDFNet.Obj is an Cos/SDF array specifying a range of colors to be masked out. Samples in the image that fall within this range are not painted, allowing the existing background to show through. The effect is similar to that of the video technique known as chroma-key. For details of the array format please refer to section 4.8.5 'Color Key Masking' in PDF Reference Manual. Note: the current document takes the ownership of the given SDF object.
Returns:
Type
Promise.<void>

setSoftMask(soft_mask)

set a Soft Mask.
Parameters:
Name Type Description
soft_mask Core.PDFNet.Image is a subsidiary Image object defining a soft-mask image (See section 7.5.4 'Soft-Mask Images' in PDF Reference Manual) to be used as a source of mask shape or mask opacity values in the transparent imaging model. The alpha source parameter in the graphics state determines whether the mask values are interpreted as shape or opacity.
Returns:
Type
Promise.<void>