public void createPdfLayout ( Dimension dim ) { if ( pdfdocument != null ) //processing a PDF document { try { if ( createImage ) img = new BufferedImage ( dim . width , dim . height , BufferedImage . TYPE_INT_RGB ) ; Graphics2D ig = img . createGraphics ( ) ; log . info ( "Creating PDF boxes" ) ; VisualContext ctx = new VisualContext ( null , null ) ; boxtree = new CSSBoxTree ( ig , ctx , dim , baseurl ) ; boxtree . setConfig ( config ) ; boxtree . processDocument ( pdfdocument , startPage , endPage ) ; viewport = boxtree . getViewport ( ) ; root = boxtree . getDocument ( ) . getDocumentElement ( ) ; log . info ( "We have " + boxtree . getLastId ( ) + " boxes" ) ; viewport . initSubtree ( ) ; log . info ( "Layout for " + dim . width + "px" ) ; viewport . doLayout ( dim . width , true , true ) ; log . info ( "Resulting size: " + viewport . getWidth ( ) + "x" + viewport . getHeight ( ) + " (" + viewport + ")" ) ; log . info ( "Updating viewport size" ) ; viewport . updateBounds ( dim ) ; log . info ( "Resulting size: " + viewport . getWidth ( ) + "x" + viewport . getHeight ( ) + " (" + viewport + ")" ) ; if ( createImage && ( viewport . getWidth ( ) > dim . width || viewport . getHeight ( ) > dim . height ) ) { img = new BufferedImage ( Math . max ( viewport . getWidth ( ) , dim . width ) , Math . max ( viewport . getHeight ( ) , dim . height ) , BufferedImage . TYPE_INT_RGB ) ; ig = img . createGraphics ( ) ; } log . info ( "Positioning for " + img . getWidth ( ) + "x" + img . getHeight ( ) + "px" ) ; viewport . absolutePositions ( ) ; clearCanvas ( ) ; viewport . draw ( new GraphicsRenderer ( ig ) ) ; setPreferredSize ( new Dimension ( img . getWidth ( ) , img . getHeight ( ) ) ) ; revalidate ( ) ; } catch ( ParserConfigurationException e ) { e . printStackTrace ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } else if ( root != null ) //processing a DOM tree { super . createLayout ( dim ) ; } }
Creates the box tree for the PDF file .