1 31 package org.pdfbox.pdfviewer; 32 33 import java.awt.Dimension ; 34 import java.awt.Graphics ; 35 36 import java.io.IOException ; 37 38 import javax.swing.JPanel ; 39 40 import org.pdfbox.pdmodel.PDPage; 41 42 import org.pdfbox.pdmodel.common.PDRectangle; 43 44 50 public class PDFPagePanel extends JPanel 51 { 52 53 private PDPage page; 54 private PageDrawer drawer = null; 55 private Dimension pageDimension = null; 56 57 62 public PDFPagePanel() throws IOException 63 { 64 drawer = new PageDrawer(); 65 } 66 67 72 public void setPage( PDPage pdfPage ) 73 { 74 page = pdfPage; 75 PDRectangle pageSize = page.findMediaBox(); 76 int rotation = page.findRotation(); 77 pageDimension = pageSize.createDimension(); 78 if( rotation == 90 || rotation == 270 ) 79 { 80 pageDimension = new Dimension ( pageDimension.height, pageDimension.width ); 81 } 82 setSize( pageDimension ); 83 setBackground( java.awt.Color.white ); 84 } 85 86 89 public void paint(Graphics g ) 90 { 91 try 92 { 93 g.setColor( getBackground() ); 94 g.fillRect( 0, 0, getWidth(), getHeight() ); 95 drawer.drawPage( g, page, pageDimension ); 96 } 97 catch( IOException e ) 98 { 99 e.printStackTrace(); 100 } 101 } 102 } | Popular Tags |