Ravi Hegde created PDFBOX-1427:
----------------------------------
Summary: Rotation is not working
Key: PDFBOX-1427
URL: https://issues.apache.org/jira/browse/PDFBOX-1427
Project: PDFBox
Issue Type: Bug
Components: PDModel
Affects Versions: 1.7.1
Environment: Ubuntu 11.10 64 bit on Intel® Core™ i5-2430M CPU. Sun JDK
"1.6.0_30" (build 1.6.0_30-b12) Java HotSpot(TM) 64-Bit Server VM (build
20.5-b03, mixed mode).
Reporter: Ravi Hegde
PDFToImage creates empty images when PDF with rotation is provided as input.
Rotation logic in PDPage is not correct. Because of this problem PDF contents
are rendered outside the graphics area. Hence it creates empty images. Patch
file is below. Tested on pdf
http://eeweb.poly.edu/~yao/EE3414/image_filtering.pdf
---------------------------------------------------------------------
---
/data/pdf/pdfbox/pdfbox-svn/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java
2012-10-14 08:45:34.275123749 +0530
+++
/data/pdf/pdfbox/pdfbox-1.7.1/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java
2012-10-14 13:37:16.887054874 +0530
@@ -708,8 +708,13 @@
//TODO The following reduces accuracy. It should really be a
Dimension2D.Float.
Dimension pageDimension = new Dimension( (int)widthPt, (int)heightPt );
BufferedImage retval = null;
- float rotation = (float)Math.toRadians(findRotation());
- if (rotation != 0)
+ int rotationAngle = findRotation();
+ //PDF spec does not say rotation angle should be within 360 degrees
+ //Restrict rotation to -360 to +360 degrees range.
+ rotationAngle = rotationAngle % 360;
+ float rotation = (float)Math.toRadians(rotationAngle);
+ //Flip the image horizontally only for +/-90 and +/-270 degree rotation
+ if ((rotationAngle % 180) != 0)
{
retval = new BufferedImage( heightPx, widthPx, imageType );
}
@@ -722,7 +727,26 @@
graphics.clearRect( 0, 0, retval.getWidth(), retval.getHeight() );
if (rotation != 0)
{
- graphics.translate(retval.getWidth(), 0.0f);
+ int translateX = 0;
+ int translateY = 0;
+ switch(rotationAngle) {
+ case -270:
+ case 90:
+ translateX = retval.getWidth();
+ break;
+
+ case -90:
+ case 270:
+ translateY = retval.getHeight();
+ break;
+
+ case -180:
+ case 180:
+ translateX = retval.getWidth();
+ translateY = retval.getHeight();
+ break;
+ }
+ graphics.translate(translateX,translateY);
graphics.rotate(rotation);
}
graphics.scale( scaling, scaling );
---------------------------------------------------------------------
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira