Skip to main content

ImageObject

Struct ImageObject 

Source
pub struct ImageObject {
    pub image_data: Vec<u8>,
    pub width: u32,
    pub height: u32,
    pub bits_per_component: u8,
    pub color_space: Name,
    pub matrix: Matrix,
    pub filter: Option<Name>,
    pub xobject_id: Option<ObjectId>,
    pub blend_mode: Option<BlendMode>,
    pub active: bool,
    pub marks: Vec<ContentMark>,
    pub clip_path: Option<ClipPath>,
}
Expand description

An image XObject to be placed on a page.

Fields§

§image_data: Vec<u8>

Raw image data (format depends on filter).

§width: u32

Image width in pixels.

§height: u32

Image height in pixels.

§bits_per_component: u8

Bits per color component.

§color_space: Name

Color space name (e.g., DeviceRGB, DeviceGray).

§matrix: Matrix

Transformation matrix (scales/positions the image on the page).

§filter: Option<Name>

Optional filter name (e.g., FlateDecode, DCTDecode).

§xobject_id: Option<ObjectId>

Optional pre-existing XObject ID. If set, the image is already stored in the document and will be referenced by this ID. If None, the caller must create the image stream and assign an ID before generating the content stream.

§blend_mode: Option<BlendMode>

Blend mode for compositing.

Corresponds to FPDFPageObj_GetBlendMode / FPDFPageObj_SetBlendMode.

§active: bool

Whether the object is active (visible).

Corresponds to FPDFPageObj_GetIsActive / FPDFPageObj_SetIsActive.

§marks: Vec<ContentMark>

Content marks attached to this object (for tagged PDF / accessibility).

Each mark corresponds to a BDCEMC pair wrapping this object in the content stream.

Corresponds to FPDFPageObj_CountMarks / FPDFPageObj_GetMark / etc.

§clip_path: Option<ClipPath>

Optional clipping path attached to this object.

Corresponds to FPDFPageObj_GetClipPath / FPDFPageObj_TransformClipPath.

Implementations§

Source§

impl ImageObject

Source

pub fn from_bitmap(bitmap: &Bitmap, matrix: Matrix) -> Self

Create an ImageObject from a rendered Bitmap.

Converts an Rgba32 (premultiplied-alpha) bitmap to RGB24, applies FlateDecode compression, and returns an ImageObject ready for embedding in a PDF page.

The matrix parameter controls placement on the page. A typical value for a w×h image at page coordinates (x, y) is Matrix::new(w as f64, 0.0, 0.0, h as f64, x, y).

§Panics

Panics if bitmap.format != BitmapFormat::Rgba32.

Source

pub fn from_jpeg_bytes( jpeg_data: Vec<u8>, matrix: Matrix, ) -> Result<Self, EditError>

Creates an image object embedding raw JPEG bytes directly (DCTDecode filter).

No decompression or recompression occurs — the JPEG data is stored as-is with a /Filter /DCTDecode stream entry. The JPEG SOF header is parsed to extract the image dimensions.

Returns an error if the provided bytes are not a recognisable JPEG (missing valid SOF0 or SOF2 marker).

Corresponds to FPDFImageObj_LoadJpegFile / FPDFImageObj_LoadJpegFileInline in PDFium’s fpdf_edit.h.

Source

pub fn transform(&mut self, m: &Matrix)

Applies a matrix transform by pre-multiplying into the object’s matrix.

Corresponds to FPDFPageObj_Transform.

Source

pub fn blend_mode(&self) -> Option<BlendMode>

Returns the blend mode for this object.

Corresponds to FPDFPageObj_GetBlendMode.

Source

pub fn page_obj_get_blend_mode(&self) -> Option<BlendMode>

Upstream-aligned alias for blend_mode().

Corresponds to FPDFPageObj_GetBlendMode.

Source

pub fn get_blend_mode(&self) -> Option<BlendMode>

👎Deprecated:

use page_obj_get_blend_mode() — matches upstream FPDFPageObj_GetBlendMode

Non-upstream alias — use page_obj_get_blend_mode().

Corresponds to FPDFPageObj_GetBlendMode.

Source

pub fn set_blend_mode(&mut self, mode: Option<BlendMode>)

Sets the blend mode for this object.

Corresponds to FPDFPageObj_SetBlendMode.

Source

pub fn metadata(&self) -> ImageMetadata

Returns metadata about this image object.

Corresponds to FPDFImageObj_GetImageMetadata.

Source

pub fn image_obj_get_image_metadata(&self) -> ImageMetadata

Upstream-aligned alias for metadata().

Corresponds to FPDFImageObj_GetImageMetadata.

Source

pub fn get_image_metadata(&self) -> ImageMetadata

👎Deprecated:

use image_obj_get_image_metadata() — matches upstream FPDFImageObj_GetImageMetadata

Source

pub fn raw_data(&self) -> &[u8]

Returns the raw (possibly compressed) image data.

Corresponds to FPDFImageObj_GetImageDataRaw.

Source

pub fn image_obj_get_image_data_raw(&self) -> &[u8]

Upstream-aligned alias for raw_data().

Corresponds to FPDFImageObj_GetImageDataRaw.

Source

pub fn get_image_data_raw(&self) -> &[u8]

👎Deprecated:

use image_obj_get_image_data_raw() — matches upstream FPDFImageObj_GetImageDataRaw

Source

pub fn decoded_data(&self) -> Result<Vec<u8>, EditError>

Returns the decoded (decompressed) image data.

If a filter is set (e.g. FlateDecode), the data is decompressed via the filter pipeline. If the image is uncompressed, returns the raw data unchanged.

Corresponds to FPDFImageObj_GetImageDataDecoded.

Source

pub fn image_obj_get_image_data_decoded(&self) -> Result<Vec<u8>, EditError>

Upstream-aligned alias for decoded_data().

Corresponds to FPDFImageObj_GetImageDataDecoded.

Source

pub fn get_image_data_decoded(&self) -> Result<Vec<u8>, EditError>

👎Deprecated:

use image_obj_get_image_data_decoded() — matches upstream FPDFImageObj_GetImageDataDecoded

Source

pub fn to_bitmap(&self) -> Result<Bitmap, EditError>

Decodes the image data and returns it as a Bitmap.

  • DeviceRGB images → BitmapFormat::Rgba32 (alpha = 255)
  • DeviceGray images → BitmapFormat::Gray8

Returns an error for unsupported color spaces or if the decoded data is too short for the declared dimensions.

Corresponds to FPDFImageObj_GetBitmap.

Source

pub fn image_obj_get_bitmap(&self) -> Result<Bitmap, EditError>

Upstream-aligned alias for to_bitmap().

Corresponds to FPDFImageObj_GetBitmap.

Source

pub fn get_bitmap(&self) -> Result<Bitmap, EditError>

👎Deprecated:

use image_obj_get_bitmap() — matches upstream FPDFImageObj_GetBitmap

Non-upstream alias — use image_obj_get_bitmap().

Corresponds to FPDFImageObj_GetBitmap.

Source

pub fn matrix(&self) -> &Matrix

Returns a reference to the transformation matrix.

Corresponds to FPDFPageObj_GetMatrix.

Source

pub fn page_obj_get_matrix(&self) -> &Matrix

Upstream-aligned alias for matrix().

Corresponds to FPDFPageObj_GetMatrix.

Source

pub fn get_matrix(&self) -> &Matrix

👎Deprecated:

use page_obj_get_matrix() — matches upstream FPDFPageObj_GetMatrix

Source

pub fn set_matrix(&mut self, matrix: Matrix)

Set the transformation matrix.

Corresponds to FPDFImageObj_SetMatrix.

Source

pub fn image_obj_set_matrix(&mut self, matrix: Matrix)

Upstream-aligned alias for set_matrix().

Corresponds to FPDFImageObj_SetMatrix.

Source

pub fn bounds(&self) -> Option<Rect>

Returns the bounding box of this image object in page coordinates.

The unit square [0,0]–[1,1] is mapped through self.matrix and the axis-aligned bounding box of the four transformed corners is returned.

Corresponds to FPDFPageObj_GetBounds for image objects.

Source

pub fn mark_count(&self) -> usize

Return the number of content marks on this object.

Corresponds to FPDFPageObj_CountMarks.

Source

pub fn page_obj_count_marks(&self) -> usize

Upstream-aligned alias for mark_count().

Corresponds to FPDFPageObj_CountMarks.

Source

pub fn count_marks(&self) -> usize

👎Deprecated:

use page_obj_count_marks() — matches upstream FPDFPageObj_CountMarks

Non-upstream alias — use page_obj_count_marks().

Corresponds to FPDFPageObj_CountMarks.

Source

pub fn mark(&self, index: usize) -> Option<&ContentMark>

Return the content mark at the given index, or None if out of range.

Corresponds to FPDFPageObj_GetMark.

Source

pub fn page_obj_get_mark(&self, index: usize) -> Option<&ContentMark>

Upstream-aligned alias for mark().

Corresponds to FPDFPageObj_GetMark.

Source

pub fn get_mark(&self, index: usize) -> Option<&ContentMark>

👎Deprecated:

use page_obj_get_mark() — matches upstream FPDFPageObj_GetMark

Non-upstream alias — use page_obj_get_mark().

Corresponds to FPDFPageObj_GetMark.

Source

pub fn add_mark(&mut self, name: impl Into<String>) -> &mut ContentMark

Add a new content mark with the given name and return a mutable reference to it.

Corresponds to FPDFPageObj_AddMark.

Source

pub fn remove_mark(&mut self, index: usize) -> bool

Remove the content mark at the given index.

Returns true if the index was valid and the mark was removed, false if out of range.

Corresponds to FPDFPageObj_RemoveMark.

Source

pub fn marks(&self) -> &[ContentMark]

Return a slice of all content marks on this object.

Source

pub fn marked_content_id(&self) -> Option<i64>

Return the marked content ID (/MCID) from the first mark that has one, or None if no mark carries an MCID.

Corresponds to FPDFPageObj_GetMarkedContentID.

Source

pub fn page_obj_get_marked_content_id(&self) -> Option<i64>

Upstream-aligned alias for marked_content_id().

Corresponds to FPDFPageObj_GetMarkedContentID.

Source

pub fn get_marked_content_id(&self) -> Option<i64>

👎Deprecated:

use page_obj_get_marked_content_id() — matches upstream FPDFPageObj_GetMarkedContentID

Non-upstream alias — use page_obj_get_marked_content_id().

Corresponds to FPDFPageObj_GetMarkedContentID.

Source

pub fn has_transparency(&self) -> bool

Returns true if this image object has any transparency.

An image object is considered transparent when it has a non-Normal blend mode.

Corresponds to FPDFPageObj_HasTransparency.

Source

pub fn is_transparent(&self) -> bool

👎Deprecated:

use has_transparency() — matches upstream FPDFPageObj_HasTransparency

Non-upstream convenience alias for has_transparency().

Prefer has_transparency(), which matches the upstream FPDFPageObj_HasTransparency name exactly.

Source

pub fn object_type(&self) -> u32

Returns the PDFium page-object-type constant for image objects: 3.

Corresponds to FPDFPageObj_GetType returning FPDF_PAGEOBJ_IMAGE.

Source

pub fn get_object_type(&self) -> u32

👎Deprecated:

use page_obj_get_type() — matches upstream FPDFPageObj_GetType

Non-upstream alias — use page_obj_get_type().

The actual upstream function is FPDFPageObj_GetType; there is no FPDFPageObj_GetObjectType.

Source

pub fn page_obj_get_type(&self) -> u32

Upstream-aligned alias for object_type().

Corresponds to FPDFPageObj_GetType.

Source

pub fn get_type(&self) -> u32

👎Deprecated:

use page_obj_get_type() — matches upstream FPDFPageObj_GetType

Source

pub fn filter_count(&self) -> usize

Returns the number of filters applied to this image’s data stream.

This implementation stores at most one filter; returns 1 when a filter is present, 0 otherwise.

Corresponds to FPDFImageObj_GetImageFilterCount.

Source

pub fn image_obj_get_image_filter_count(&self) -> usize

Upstream-aligned alias for filter_count().

Corresponds to FPDFImageObj_GetImageFilterCount.

Source

pub fn get_image_filter_count(&self) -> usize

👎Deprecated:

use image_obj_get_image_filter_count() — matches upstream FPDFImageObj_GetImageFilterCount

Non-upstream alias — use image_obj_get_image_filter_count().

Corresponds to FPDFImageObj_GetImageFilterCount.

Source

pub fn filter(&self, index: usize) -> Option<&str>

Returns the filter name at the given index as a &str, or None if the index is out of range.

Only index 0 is valid; any other index returns None.

Corresponds to FPDFImageObj_GetImageFilter.

Source

pub fn image_obj_get_image_filter(&self, index: usize) -> Option<&str>

Upstream-aligned alias for filter().

Corresponds to FPDFImageObj_GetImageFilter.

Source

pub fn get_image_filter(&self, index: usize) -> Option<&str>

👎Deprecated:

use image_obj_get_image_filter() — matches upstream FPDFImageObj_GetImageFilter

Non-upstream alias — use image_obj_get_image_filter().

Corresponds to FPDFImageObj_GetImageFilter.

Source

pub fn get_filter(&self, index: usize) -> Option<&str>

👎Deprecated:

use image_obj_get_image_filter() — matches upstream FPDFImageObj_GetImageFilter

Non-upstream alias — use image_obj_get_image_filter().

Corresponds to FPDFImageObj_GetImageFilter.

Source

pub fn pixel_size(&self) -> (u32, u32)

Returns the pixel dimensions of this image object.

Returns (width, height) in pixels.

Corresponds to FPDFImageObj_GetImagePixelSize.

Source

pub fn image_obj_get_image_pixel_size(&self) -> (u32, u32)

Upstream-aligned alias for pixel_size().

Corresponds to FPDFImageObj_GetImagePixelSize.

Source

pub fn get_image_pixel_size(&self) -> (u32, u32)

👎Deprecated:

use image_obj_get_image_pixel_size() — matches upstream FPDFImageObj_GetImagePixelSize

Non-upstream alias — use image_obj_get_image_pixel_size().

Corresponds to FPDFImageObj_GetImagePixelSize.

Source

pub fn rotated_bounds(&self) -> Option<[Point; 4]>

Returns the tight rotated bounding quadrilateral for this image object as 4 corner points in page coordinates.

The corners are computed by transforming the unit square [0,0]–[1,1] through the image’s placement matrix, giving the exact (possibly rotated) bounding quad.

Corresponds to FPDFPageObj_GetRotatedBounds.

Source

pub fn page_obj_get_rotated_bounds(&self) -> Option<[Point; 4]>

Upstream-aligned alias for rotated_bounds().

Corresponds to FPDFPageObj_GetRotatedBounds.

Source

pub fn get_rotated_bounds(&self) -> Option<[Point; 4]>

👎Deprecated:

use page_obj_get_rotated_bounds() — matches upstream FPDFPageObj_GetRotatedBounds

Non-upstream alias — use page_obj_get_rotated_bounds().

Corresponds to FPDFPageObj_GetRotatedBounds.

Source

pub fn rendered_bitmap( &self, _page_index: usize, _scale: f32, ) -> Result<Bitmap, EditError>

Returns the rendered bitmap for this image object at the given scale.

§Not Supported

Rendering a page object to bitmap requires a live CPDF_Document/CPDF_Page handle not available in rpdfium’s edit layer (read-only, ADR-002).

Corresponds to FPDFImageObj_GetRenderedBitmap.

Source

pub fn image_obj_get_rendered_bitmap( &self, page_index: usize, scale: f32, ) -> Result<Bitmap, EditError>

Upstream-aligned alias for rendered_bitmap().

Corresponds to FPDFImageObj_GetRenderedBitmap.

Source

pub fn get_rendered_bitmap( &self, page_index: usize, scale: f32, ) -> Result<Bitmap, EditError>

👎Deprecated:

use image_obj_get_rendered_bitmap() — matches upstream FPDFImageObj_GetRenderedBitmap

Non-upstream alias — use image_obj_get_rendered_bitmap().

Corresponds to FPDFImageObj_GetRenderedBitmap.

Source

pub fn icc_profile_data_decoded(&self) -> Option<&[u8]>

Returns the decoded ICC profile bytes embedded in this image object, if any.

Returns None if the image has no embedded ICC profile. ICC profile extraction requires parsing the image’s color space stream, which is not performed at the edit layer.

Corresponds to FPDFImageObj_GetIccProfileDataDecoded.

Source

pub fn image_obj_get_icc_profile_data_decoded(&self) -> Option<&[u8]>

Upstream-aligned alias for icc_profile_data_decoded().

Corresponds to FPDFImageObj_GetIccProfileDataDecoded.

Source

pub fn get_icc_profile_data_decoded(&self) -> Option<&[u8]>

👎Deprecated:

use image_obj_get_icc_profile_data_decoded() — matches upstream FPDFImageObj_GetIccProfileDataDecoded

Non-upstream alias — use image_obj_get_icc_profile_data_decoded().

Corresponds to FPDFImageObj_GetIccProfileDataDecoded.

Trait Implementations§

Source§

impl Clone for ImageObject

Source§

fn clone(&self) -> ImageObject

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ImageObject

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more