Class ImagePlacement

ImagePlacement class

Represents characteristics of an image placed to Pdf document page.

public sealed class ImagePlacement

Properties

NameDescription
CompositingParameters { get; }Gets compositing parameters of graphics state active for the image placed to the page.
Image { get; }Gets related XImage resource object.
Matrix { get; }Current transformation matrix for this image.
Operator { get; }Operator used for displaying the image.
Page { get; }Gets the page containing the image.
Rectangle { get; }Gets rectangle of the Image.
Resolution { get; }Gets resolution of the Image.
Rotation { get; }Gets rotation angle of the Image.

Methods

NameDescription
Hide()Delete image from the page.
Replace(Stream)Replace image in collection with another image.
Save(Stream)Saves image with corresponding transformations: scaling, rotation and resolution.
Save(Stream, ImageFormat)Saves image with corresponding transformations: scaling, rotation and resolution.

Remarks

When an image is placed to a page it may have dimensions other than physical dimensions defined in Resources. The object ImagePlacement is intended to provide such information like dimensions, resolution and so on.

Examples

The example demonstrates how to find images on the first PDF document page and get images as bitmaps with visible dimensions.

// Open document
Document doc = new Document(@"D:\Tests\input.pdf");

// Create ImagePlacementAbsorber object to perform image placement search
ImagePlacementAbsorber abs = new ImagePlacementAbsorber();

// Accept the absorber for first page
doc.Pages[1].Accept(abs);

// Retrieve images with visible dimensions
foreach (ImagePlacement imagePlacement in abs.ImagePlacements)
{
    Bitmap scaledImage;
    using (MemoryStream imageStream = new MemoryStream())
    {
        // Retrieve image from resources
        imagePlacement.Image.Save(imageStream, ImageFormat.Png);
        Bitmap resourceImage = (Bitmap) Bitmap.FromStream(imageStream);
        // Create new bitmap with actual dimensions
        scaledImage = new Bitmap(resourceImage, (int)imagePlacement.Rectangle.Width, (int)imagePlacement.Rectangle.Height);
    }
} 

See Also