Examples of PDRectangle


Examples of org.pdfbox.pdmodel.common.PDRectangle

     * @return The fonts bouding box.
     */
    public PDRectangle getFontBoundingBox()
    {
        BoundingBox box = afm.getFontBBox();
        PDRectangle retval = null;
        if( box != null )
        {
            retval = new PDRectangle( box );
        }
        return retval;
    }
View Full Code Here

Examples of org.pdfbox.pdmodel.common.PDRectangle

    private void insertGeneratedAppearance( PDAnnotationWidget fieldWidget, OutputStream output,
        PDFont pdFont, List tokens, PDAppearanceStream appearanceStream ) throws IOException
    {
        PrintWriter printWriter = new PrintWriter( output, true );
        float fontSize = 0.0f;
        PDRectangle boundingBox = null;
        boundingBox = appearanceStream.getBoundingBox();
        if( boundingBox == null )
        {
            boundingBox = fieldWidget.getRectangle().createRetranslatedRectangle();
        }
        printWriter.println( "BT" );
        if( defaultAppearance != null )
        {
            String daString = defaultAppearance.getString();
            PDFStreamParser daParser = new PDFStreamParser(new ByteArrayInputStream( daString.getBytes() ), null );
            daParser.parse();
            List daTokens = daParser.getTokens();
            fontSize = calculateFontSize( pdFont, boundingBox, tokens, daTokens );
            int fontIndex = daTokens.indexOf( PDFOperator.getOperator( "Tf" ) );
            if(fontIndex != -1 )
            {
                daTokens.set( fontIndex-1, new COSFloat( fontSize ) );
            }
            ContentStreamWriter daWriter = new ContentStreamWriter(output);
            daWriter.writeTokens( daTokens );
        }
        printWriter.println( getTextPosition( boundingBox, pdFont, fontSize, tokens ) );
        int q = getQ();
        if( q == PDTextbox.QUADDING_LEFT )
        {
            //do nothing because left is default
        }
        else if( q == PDTextbox.QUADDING_CENTERED ||
                 q == PDTextbox.QUADDING_RIGHT )
        {
            float fieldWidth = boundingBox.getWidth();
            float stringWidth = (pdFont.getStringWidth( value )/1000)*fontSize;
            float adjustAmount = fieldWidth - stringWidth - 4;

            if( q == PDTextbox.QUADDING_CENTERED )
            {
View Full Code Here

Examples of org.pdfbox.pdmodel.common.PDRectangle

        return retval;
    }
   
    private PDRectangle getSmallestDrawnRectangle( PDRectangle boundingBox, List tokens )
    {
        PDRectangle smallest = boundingBox;
        for( int i=0; i<tokens.size(); i++ )
        {
            Object next = tokens.get( i );
            if( next == PDFOperator.getOperator( "re" ) )
            {
                COSNumber x = (COSNumber)tokens.get( i-4 );
                COSNumber y = (COSNumber)tokens.get( i-3 );
                COSNumber width = (COSNumber)tokens.get( i-2 );
                COSNumber height = (COSNumber)tokens.get( i-1 );
                PDRectangle potentialSmallest = new PDRectangle();
                potentialSmallest.setLowerLeftX( x.floatValue() );
                potentialSmallest.setLowerLeftY( y.floatValue() );
                potentialSmallest.setUpperRightX( x.floatValue() + width.floatValue() );
                potentialSmallest.setUpperRightY( y.floatValue() + height.floatValue() );
                if( smallest == null ||
                    smallest.getLowerLeftX() < potentialSmallest.getLowerLeftX() ||
                    smallest.getUpperRightY() > potentialSmallest.getUpperRightY() )
                {
                    smallest = potentialSmallest;
                }
               
            }
View Full Code Here

Examples of org.pdfbox.pdmodel.common.PDRectangle

            else
            {
                throw new IOException( "Error: Don't know how to calculate the position for non-simple fonts" );
            }
        }
        PDRectangle innerBox = getSmallestDrawnRectangle( boundingBox, tokens );
        float xInset = 2+ 2*(boundingBox.getWidth() - innerBox.getWidth());
        return Math.round(xInset) + " "+ pos + " Td";
    }
View Full Code Here

Examples of org.pdfbox.pdmodel.common.PDRectangle

                txtMark.setConstantOpacity((float)0.2);   // Make the highlight 20% transparent
               
                // Set the rectangle containing the markup

                float textWidth = (font.getStringWidth( "PDFBox" )/1000) * 18;
                PDRectangle position = new PDRectangle();
                position.setLowerLeftX(inch)
                position.setLowerLeftY( ph-inch-18 );
                position.setUpperRightX(72 + textWidth);
                position.setUpperRightY(ph-inch);
                txtMark.setRectangle(position);
               
                // work out the points forming the four corners of the annotations
                // set out in anti clockwise form (Completely wraps the text)
                // OK, the below doesn't match that description.
                // It's what acrobat 7 does and displays properly!
                float[] quads = new float[8];
               
                quads[0] = position.getLowerLeftX()// x1
                quads[1] = position.getUpperRightY()-2; // y1
                quads[2] = position.getUpperRightX(); // x2
                quads[3] = quads[1]; // y2
                quads[4] = quads[0]// x3
                quads[5] = position.getLowerLeftY()-2; // y3
                quads[6] = quads[2]; // x4
                quads[7] = quads[5]; // y5
               
                txtMark.setQuadPoints(quads);
                txtMark.setContents("Highlighted since it's important");
               
                annotations.add(txtMark);
               
                // Now add the link annotation, so the clickme works
                PDAnnotationLink txtLink = new PDAnnotationLink();
                txtLink.setBorderStyle(borderULine);
               
                // Set the rectangle containing the link

                textWidth = (font.getStringWidth( "Click Here" )/1000) * 18;
                position = new PDRectangle();
                position.setLowerLeftX(inch)
                position.setLowerLeftY( ph-(float)(1.5*inch)-20)// down a couple of points
                position.setUpperRightX(72 + textWidth);
                position.setUpperRightY(ph-(float)(1.5*inch));
                txtLink.setRectangle(position);
               
                // add an action
                PDActionURI action = new PDActionURI();
                action.setURI("http://www.pdfbox.org");
                txtLink.setAction(action);
               
                annotations.add(txtLink);
               
               
                // Now draw a few more annotations
               
                PDAnnotationSquareCircle aCircle =
                    new PDAnnotationSquareCircle( PDAnnotationSquareCircle.SUB_TYPE_CIRCLE);
                aCircle.setContents("Circle Annotation");
                aCircle.setInteriorColour(colourRed)// Fill in circle in red
                aCircle.setColour(colourBlue); // The border itself will be blue
                aCircle.setBorderStyle(borderThin);

                // Place the annotation on the page, we'll make this 1" round
                // 3" down, 1" in on the page
               
                position = new PDRectangle();
                position.setLowerLeftX(inch)
                position.setLowerLeftY(ph-(3*inch)-inch); // 1" height, 3" down
                position.setUpperRightX(2*inch); // 1" in, 1" width
                position.setUpperRightY(ph-(3*inch)); // 3" down
                aCircle.setRectangle(position);

                //  add to the annotations on the page
                annotations.add(aCircle);
               
                // Now a square annotation
               
                PDAnnotationSquareCircle aSquare =
                    new PDAnnotationSquareCircle( PDAnnotationSquareCircle.SUB_TYPE_SQUARE);
                aSquare.setContents("Square Annotation");
                aSquare.setColour(colourRed)// Outline in red, not setting a fill
                aSquare.setBorderStyle(borderThick);
               
                // Place the annotation on the page, we'll make this 1" (72points) square
                // 3.5" down, 1" in from the right on the page
               
                position = new PDRectangle(); // Reuse the variable, but note it's a new object!
                position.setLowerLeftX(pw-(2*inch))// 1" in from right, 1" wide
                position.setLowerLeftY(ph-(float)(3.5*inch) - inch); // 1" height, 3.5" down
                position.setUpperRightX(pw-inch); // 1" in from right
                position.setUpperRightY(ph-(float)(3.5*inch)); // 3.5" down
                aSquare.setRectangle(position);

                //  add to the annotations on the page
                annotations.add(aSquare);
               
                // Now we want to draw a line between the two, one end with an open arrow
               
                PDAnnotationLine aLine = new PDAnnotationLine();
               
                aLine.setEndPointEndingStyle( PDAnnotationLine.LE_OPEN_ARROW );
                aLine.setContents("Circle->Square")
                aLine.setCaption(true)// Make the contents a caption on the line
               
                // Set the rectangle containing the line
               
                position = new PDRectangle(); // Reuse the variable, but note it's a new object!
                position.setLowerLeftX(2*inch)// 1" in + width of circle
                position.setLowerLeftY(ph-(float)(3.5*inch)-inch); // 1" height, 3.5" down
                position.setUpperRightX(pw-inch-inch); // 1" in from right, and width of square
                position.setUpperRightY(ph-(3*inch)); // 3" down (top of circle)
                aLine.setRectangle(position);
               
                // Now set the line position itself
                float[] linepos = new float[4];
                linepos[0] = 2*inch;  // x1 = rhs of circle
View Full Code Here

Examples of org.pdfbox.pdmodel.common.PDRectangle

            //todo retval.setAllCap
            //todo retval.setSmallCap
            //todo retval.setForceBold
           
            HeaderTable header = ttf.getHeader();
            PDRectangle rect = new PDRectangle();
            rect.setLowerLeftX( header.getXMin() * 1000f/header.getUnitsPerEm() );
            rect.setLowerLeftY( header.getYMin() * 1000f/header.getUnitsPerEm() );
            rect.setUpperRightX( header.getXMax() * 1000f/header.getUnitsPerEm() );
            rect.setUpperRightY( header.getYMax() * 1000f/header.getUnitsPerEm() );
            fd.setFontBoundingBox( rect );
           
            HorizontalHeaderTable hHeader = ttf.getHorizontalHeader();
            fd.setAscent( hHeader.getAscender() * 1000f/header.getUnitsPerEm() );
            fd.setDescent( hHeader.getDescender() * 1000f/header.getUnitsPerEm() );
View Full Code Here

Examples of org.pdfbox.pdmodel.common.PDRectangle

        processStream( page, resources, page.getContents().getStream() );
        List annotations = page.getAnnotations();
        for( int i=0; i<annotations.size(); i++ )
        {
            PDAnnotation annot = (PDAnnotation)annotations.get( i );
            PDRectangle rect = annot.getRectangle();
            String appearanceName = annot.getAppearanceStream();
            PDAppearanceDictionary appearDictionary = annot.getAppearance();
            if( appearDictionary != null )
            {
                if( appearanceName == null )
                {
                    appearanceName = "default";
                }
                Map appearanceMap = appearDictionary.getNormalAppearance();
                PDAppearanceStream appearance =
                    (PDAppearanceStream)appearanceMap.get( appearanceName );
                if( appearance != null )
                {
                    g.translate( (int)rect.getLowerLeftX(), (int)-rect.getLowerLeftY()  );
                    //g.translate( 20, -20 );
                    processSubStream( page, appearance.getResources(), appearance.getStream() );
                    g.translate( (int)-rect.getLowerLeftX(), (int)+rect.getLowerLeftY()  );
                }
            }
        }
        // Transformations should be done in order
        // 1 - Translate
View Full Code Here

Examples of org.pdfbox.pdmodel.common.PDRectangle

     * @param pdfPage The page to draw.
     */
    public void setPage( PDPage pdfPage )
    {
        page = pdfPage;
        PDRectangle pageSize = page.findMediaBox();
        int rotation = page.findRotation();
        pageDimension = pageSize.createDimension();
        if( rotation == 90 || rotation == 270 )
        {
            pageDimension = new Dimension( pageDimension.height, pageDimension.width );
        }
        setSize( pageDimension );
View Full Code Here

Examples of org.pdfbox.pdmodel.common.PDRectangle

     * {@inheritDoc}
     */
    public PageFormat getPageFormat(int pageIndex)
    {
        PDPage page = (PDPage)getDocumentCatalog().getAllPages().get( pageIndex );
        PDRectangle mediaBox = page.findMediaBox();
        PageFormat format = new PageFormat();
        Paper paper = new Paper();
        //hmm the imageable area might need to be the CropBox instead
        //of the media box???
        double width=mediaBox.getWidth();
        double height=mediaBox.getHeight();
        if( width > height )
        {
            format.setOrientation( PageFormat.LANDSCAPE );
            width=mediaBox.getHeight();
            height=mediaBox.getWidth();
        }
        paper.setImageableArea( 0,0,width,height);
        paper.setSize( width, height );
        format.setPaper( paper );
        return format;
View Full Code Here

Examples of org.pdfbox.pdmodel.common.PDRectangle

     *
     * @return The bounding box for this appearance.
     */
    public PDRectangle getBoundingBox()
    {
        PDRectangle box = null;
        COSArray bbox = (COSArray)stream.getDictionaryObject( COSName.getPDFName( "BBox" ) );
        if( bbox != null )
        {
            box = new PDRectangle( bbox );
        }
        return box;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.