Hello All, I've recently been using pdfbox to provide an embedded PDF viewer in one of our applications. The PDF orientation can either be landscape or portrait and to save my users having to tilt their heads to one side when using landscape mode I had a go at patching pdfbox to produce a more user 'comfortable' display ;)
I've patched my local trunk copy and the attached diff makes the necessary changes to the PDFPagePanel class. I basically copied some of the code from the PDPage.convertToImage method, I'm sure there is a more elegant way of doing this but without understanding how the code works my quick and dirty patch does the trick. Regards Robert Stone Systems Consultant Rostrvm Solutions Ltd www.rostrvm.com
Index: src/main/java/org/apache/pdfbox/pdfviewer/PDFPagePanel.java =================================================================== --- src/main/java/org/apache/pdfbox/pdfviewer/PDFPagePanel.java (revision 1036459) +++ src/main/java/org/apache/pdfbox/pdfviewer/PDFPagePanel.java (working copy) @@ -18,6 +18,7 @@ import java.awt.Dimension; import java.awt.Graphics; +import java.awt.Graphics2D; import java.io.IOException; @@ -39,6 +40,7 @@ private PDPage page; private PageDrawer drawer = null; private Dimension pageDimension = null; + private Dimension drawDimension = null; /** * Constructor. @@ -59,7 +61,16 @@ { page = pdfPage; PDRectangle pageSize = page.findMediaBox(); - pageDimension = pageSize.createDimension(); + drawDimension = pageSize.createDimension(); + int rotation = page.findRotation(); + if (rotation == 90 || rotation == 270) + { + pageDimension = new Dimension(drawDimension.height, drawDimension.width); + } + else + { + pageDimension = drawDimension; + } setSize( pageDimension ); setBackground( java.awt.Color.white ); } @@ -73,7 +84,16 @@ { g.setColor( getBackground() ); g.fillRect( 0, 0, getWidth(), getHeight() ); - drawer.drawPage( g, page, pageDimension ); + + int rotation = page.findRotation(); + if (rotation == 90 || rotation == 270) + { + Graphics2D g2D = (Graphics2D)g; + g2D.translate(pageDimension.getWidth(), 0.0f); + g2D.rotate(Math.toRadians(rotation)); + } + + drawer.drawPage( g, page, drawDimension ); } catch( IOException e ) {