public class PageImageArea extends PageArea
An instance of PageImageArea
class is used as return value of the following methods:
Parser.getImages()
Parser.getImages(PageAreaOptions)
Parser.getImages(int)
Parser.getImages(int, PageAreaOptions)
See the usage examples there.
Constructor and Description |
---|
PageImageArea(InputStream imageStream,
FileType fileType,
double rotation)
Initializes a new instance of the
PageImageArea class. |
PageImageArea(InputStream imageStream,
FileType fileType,
double rotation,
Page page,
Rectangle rectangle)
Initializes a new instance of the
PageImageArea class. |
Modifier and Type | Method and Description |
---|---|
FileType |
getFileType()
Gets the format of the image.
|
InputStream |
getImageStream()
Returns the image stream.
|
double |
getRotation()
Gets the rotation angle of the image.
|
getPage, getRectangle, setRectangle
public PageImageArea(InputStream imageStream, FileType fileType, double rotation)
PageImageArea
class.imageStream
- The stream of the image.fileType
- The format of the image.rotation
- The rotation angle of the image.public PageImageArea(InputStream imageStream, FileType fileType, double rotation, Page page, Rectangle rectangle)
PageImageArea
class.imageStream
- The stream of the image.fileType
- The format of the image.rotation
- The rotation angle of the image.page
- The page that contains the image.rectangle
- The rectangular area that contains the image.public FileType getFileType()
FileType
class that represents the format of the image.public double getRotation()
public InputStream getImageStream()
The following example shows how to save images to files:
// Create an instance of Parser class
try (Parser parser = new Parser(Constants.SampleZip)) {
// Extract images from document
Iterable<PageImageArea> images = parser.getImages();
// Check if images extraction is supported
if (images == null) {
System.out.println("Page images extraction isn't supported");
return;
}
int imageNumber = 0;
// Iterate over images
for (PageImageArea image : images) {
// Open the image stream
try (InputStream imageStream = image.getImageStream()) {
// Create the file to save image
try (OutputStream destStream = new FileOutputStream(imageNumber + image.getFileType().getExtension())) {
byte[] buffer = new byte[4096];
int readed = 0;
do {
// Read data from the image stream
readed = imageStream.read(buffer, 0, buffer.length);
if (readed > 0) {
// Write data to the file stream
destStream.write(buffer, 0, readed);
}
}
while (readed > 0);
}
imageNumber++;
}
}
}
Copyright © 2019. All rights reserved.