PrintImageLocations doesn't print images inside PDXObjectForm objects
---------------------------------------------------------------------
Key: PDFBOX-1203
URL: https://issues.apache.org/jira/browse/PDFBOX-1203
Project: PDFBox
Issue Type: Bug
Components: Utilities
Affects Versions: 1.6.0
Reporter: Ilija Pavlic
Priority: Minor
Some pdf store images inside forms to reuse them throughout the document.
PrintImageLocations misses such images.
A workaround that works for some documents:
if (xobject instanceof PDXObjectForm) {
Map images = ((PDXObjectForm)
xobject).getResources()
.getImages();
if (images != null) {
Iterator imageIter =
images.keySet().iterator();
while (imageIter.hasNext()) {
String key = (String)
imageIter.next();
PDXObjectImage image =
(PDXObjectImage) images.get(key);
String name = key;
//System.out.println("Writing
image:" + name);
//image.write2file(name);
try {
PDPage page =
getCurrentPage();
Matrix ctm =
getGraphicsState()
.getCurrentTransformationMatrix();
double
rotationInRadians = (page.findRotation() * Math.PI) / 180;
AffineTransform
rotation = new AffineTransform();
rotation.setToRotation(rotationInRadians);
AffineTransform
rotationInverse = rotation.createInverse();
Matrix
rotationInverseMatrix = new Matrix();
rotationInverseMatrix
.setFromAffineTransform(rotationInverse);
Matrix rotationMatrix =
new Matrix();
rotationMatrix.setFromAffineTransform(rotation);
Matrix unrotatedCTM =
ctm.multiply(rotationInverseMatrix);
float xScale =
unrotatedCTM.getXScale();
float yScale =
unrotatedCTM.getYScale();
imagesInformation.add(new ImageInformation(name, unrotatedCTM.getXPosition(),
unrotatedCTM.getYPosition(), xScale / 100f * image.getWidth(), yScale / 100f *
image.getHeight()));
} catch
(NoninvertibleTransformException e) {
throw new
WrappedIOException(e);
}
}
}
}
if (xobject instanceof PDXObjectImage) {
try {
PDXObjectImage image = (PDXObjectImage)
xobject;
PDPage page = getCurrentPage();
Matrix ctm = getGraphicsState()
.getCurrentTransformationMatrix();
double rotationInRadians =
(page.findRotation() * Math.PI) / 180;
AffineTransform rotation = new
AffineTransform();
rotation.setToRotation(rotationInRadians);
AffineTransform rotationInverse =
rotation.createInverse();
Matrix rotationInverseMatrix = new
Matrix();
rotationInverseMatrix
.setFromAffineTransform(rotationInverse);
Matrix rotationMatrix = new Matrix();
rotationMatrix.setFromAffineTransform(rotation);
Matrix unrotatedCTM =
ctm.multiply(rotationInverseMatrix);
float xScale = unrotatedCTM.getXScale();
float yScale = unrotatedCTM.getYScale();
imagesInformation.add(new
ImageInformation(objectName.getName(), unrotatedCTM.getXPosition(),
unrotatedCTM.getYPosition(), xScale / 100f * image.getWidth(), yScale / 100f *
image.getHeight()));
} catch (NoninvertibleTransformException e) {
throw new WrappedIOException(e);
}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira