public final class ImagePlacement extends Object
Represents characteristics of an image placed to Pdf document page.
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.getPages().get_Item(1).accept(abs);
// Retrieve images with visible dimensions
for (ImagePlacement imagePlacement : (Iterable<ImagePlacement>)
abs.getImagePlacements())
{
BufferedImage scaledImage;
ByteArrayOutputStream imageStream = new ByteArrayOutputStream())
// Retrieve image from resources
imagePlacement.getImage().save(imageStream, ImageFormatInternal.Png);
BufferedImage resourceImage = (BufferedImage) ImageIO.read(imageStream);
// Create new bitmap with actual dimensions
scaledImage = new BufferedImage(resourceImage, (int)imagePlacement.getRectangle().getWidth(), (int)imagePlacement.getRectangle().getHeight());
}
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.
Modifier and Type | Method and Description |
---|---|
CompositingParameters |
getCompositingParameters()
Gets compositing parameters of graphics state active for the image placed to the page.
|
XImage |
getImage()
Gets related XImage resource object.
|
Matrix |
getMatrix()
Current transformation matrix for this image.
|
Page |
getPage()
Gets the page containing the image.
|
Rectangle |
getRectangle()
Gets rectangle of the Image.
|
Resolution |
getResolution()
Gets resolution of the Image.
|
float |
getRotation()
Gets rotation angle of the Image.
|
void |
replace(InputStream image)
Replace image in collection with another image.
|
void |
save(OutputStream outputStream)
Saves image with corresponding transformations: scaling, rotation and resolution.
|
void |
save(OutputStream outputStream,
ImageType format)
Saves image with corresponding transformations: scaling, rotation and resolution.
|
public Matrix getMatrix()
Current transformation matrix for this image.
public Rectangle getRectangle()
Gets rectangle of the Image.
public float getRotation()
Gets rotation angle of the Image.
public Resolution getResolution()
Gets resolution of the Image.
public XImage getImage()
Gets related XImage resource object.
public Page getPage()
Gets the page containing the image.
public CompositingParameters getCompositingParameters()
Gets compositing parameters of graphics state active for the image placed to the page.
public void replace(InputStream image)
Replace image in collection with another image.
image
- Stream containing image data.public void save(OutputStream outputStream)
Saves image with corresponding transformations: scaling, rotation and resolution.
outputStream
- Stream where image will be savedpublic void save(OutputStream outputStream, ImageType format)
Saves image with corresponding transformations: scaling, rotation and resolution.
outputStream
- Stream where image will be savedformat
- Format which will be used for image enconding. ImageFormat