Package org.apache.pdfbox.pdmodel.common

Examples of org.apache.pdfbox.pdmodel.common.PDRectangle


     * @return The BBox of the form.
     */
    @Override
    public PDRectangle getBBox()
    {
        PDRectangle retval = null;
        COSArray array = (COSArray) getCOSStream().getDictionaryObject(COSName.BBOX);
        if (array != null)
        {
            retval = new PDRectangle(array);
        }
        return retval;
    }
View Full Code Here


     * @return The Rect value of this annotation.
     */
    public PDRectangle getRectangle()
    {
        COSArray rectArray = (COSArray) dictionary.getDictionaryObject(COSName.RECT);
        PDRectangle rectangle = null;
        if (rectArray != null)
        {
            if (rectArray.size() == 4
                    && rectArray.get(0) instanceof COSNumber
                    && rectArray.get(1) instanceof COSNumber
                    && rectArray.get(2) instanceof COSNumber
                    && rectArray.get(3) instanceof COSNumber)
            {
                rectangle = new PDRectangle(rectArray);
            }
            else
            {
                LOG.warn(rectArray + " is not a rectangle array, returning null");
            }
View Full Code Here

                {
                    PDPage page = document.getPage(i);
                    List annotations = page.getAnnotations();
                    PDAnnotationRubberStamp rubberStamp = new PDAnnotationRubberStamp();
                    rubberStamp.setName(PDAnnotationRubberStamp.NAME_TOP_SECRET);
                    rubberStamp.setRectangle(new PDRectangle(200,100));
                    rubberStamp.setContents("A top secret note");

                    // create a PDXObjectImage with the given image file
                    String imageFilename = args[2];
                    PDImageXObject ximage;
                    if( imageFilename.toLowerCase().endsWith( ".jpg" ) )
                    {
                        ximage = JPEGFactory.createFromStream(document, new FileInputStream(imageFilename));
                    }
                    else if (imageFilename.toLowerCase().endsWith(".tif") || imageFilename.toLowerCase().endsWith(".tiff"))
                    {
                        ximage = CCITTFactory.createFromRandomAccess(document, new RandomAccessFile(new File(imageFilename),"r"));
                    }
                    else if (imageFilename.toLowerCase().endsWith(".gif") ||
                            imageFilename.toLowerCase().endsWith(".bmp") ||
                            imageFilename.toLowerCase().endsWith(".png"))
                    {
                        BufferedImage bim = ImageIO.read(new File(imageFilename));
                        ximage = LosslessFactory.createFromImage(document, bim);
                    }
                    else
                    {
                        throw new IOException( "Image type not supported: " + imageFilename );
                    }                   

                    // define and set the target rectangle
                    int lowerLeftX = 250;
                    int lowerLeftY = 550;
                    int formWidth = 150;
                    int formHeight = 25;
                    int imgWidth = 50;
                    int imgHeight = 25;
                   
                    PDRectangle rect = new PDRectangle();
                    rect.setLowerLeftX(lowerLeftX);
                    rect.setLowerLeftY(lowerLeftY);
                    rect.setUpperRightX(lowerLeftX + formWidth);
                    rect.setUpperRightY(lowerLeftY + formHeight);

                    // Create a PDFormXObject
                    PDStream stream = new PDStream(document);
                    OutputStream os = stream.createOutputStream();
                    PDFormXObject form = new PDFormXObject(stream);
View Full Code Here

                    {
                        PDAnnotation annot = (PDAnnotation)annotations.get( j );
                        if( annot instanceof PDAnnotationLink )
                        {
                            PDAnnotationLink link = (PDAnnotationLink)annot;
                            PDRectangle rect = link.getRectangle();
                            //need to reposition link rectangle to match text space
                            float x = rect.getLowerLeftX();
                            float y = rect.getUpperRightY();
                            float width = rect.getWidth();
                            float height = rect.getHeight();
                            int rotation = page.getRotation();
                            if( rotation == 0 )
                            {
                                PDRectangle pageSize = page.getMediaBox();
                                y = pageSize.getHeight() - y;
                            }
                            else if( rotation == 90 )
                            {
                                //do nothing
                            }
View Full Code Here

        if (yStep == 0)
        {
            yStep = pattern.getBBox().getHeight();
        }

        PDRectangle anchor = pattern.getBBox();
        return new Rectangle2D.Float(anchor.getLowerLeftX(), anchor.getLowerLeftY(), xStep, yStep);
    }
View Full Code Here

    private COSStream createOverlayStream(PDPage page, LayoutPage layoutPage, COSName xObjectId)
            throws IOException
    {
        // create a new content stream that executes the XObject content
        PDRectangle pageMediaBox = page.getMediaBox();
        float scale = 1;
        float hShift = (pageMediaBox.getWidth() - layoutPage.overlayMediaBox.getWidth()) / 2.0f;
        float vShift = (pageMediaBox.getHeight() - layoutPage.overlayMediaBox.getHeight()) / 2.0f;
        return createStream("q\nq " + scale + " 0 0 " + scale + " " + hShift + " " + vShift
                + " cm /" + xObjectId.getName() + " Do Q\nQ\n");
    }
View Full Code Here

                {
                    List annotations = page.getAnnotations();

                    PDAnnotationRubberStamp rs = new PDAnnotationRubberStamp();
                    rs.setName(PDAnnotationRubberStamp.NAME_TOP_SECRET);
                    rs.setRectangle(new PDRectangle(100, 100));
                    rs.setContents("A top secret note");

                    annotations.add(rs);
                }
View Full Code Here

            throws IOException
    {
        PDResources parent = pushResources(appearance);
        saveGraphicsState();

        PDRectangle bbox = appearance.getBBox();
        PDRectangle rect = annotation.getRectangle();
        Matrix matrix = appearance.getMatrix();

        // zero-sized rectangles are not valid
        if (rect.getWidth() > 0 && rect.getHeight() > 0)
        {
            // transformed appearance box
            PDRectangle transformedBox = bbox.transform(matrix);

            // compute a matrix which scales and translates the transformed appearance box to align
            // with the edges of the annotation's rectangle
            Matrix a = Matrix.getTranslatingInstance(rect.getLowerLeftX(), rect.getLowerLeftY());
            a.concatenate(Matrix.getScaleInstance(rect.getWidth() / transformedBox.getWidth(),
                    rect.getHeight() / transformedBox.getHeight()));
            a.concatenate(Matrix.getTranslatingInstance(-transformedBox.getLowerLeftX(),
                    -transformedBox.getLowerLeftY()));

            // Matrix shall be concatenated with A to form a matrix AA that maps from the appearance��s
            // coordinate system to the annotation’s rectangle in default user space
            Matrix aa = Matrix.concatenate(matrix, a);
View Full Code Here

        saveGraphicsState();

        // note: we don't transform the CTM using the stream's matrix, as TilingPaint handles this

        // clip to bounding box
        PDRectangle bbox = tilingPattern.getBBox();
        clipToRect(bbox);

        processStreamOperators(tilingPattern);

        restoreGraphicsState();
View Full Code Here

        // transform the CTM using the stream's matrix
        getGraphicsState().getCurrentTransformationMatrix().concatenate(contentStream.getMatrix());

        // clip to bounding box
        PDRectangle bbox = contentStream.getBBox();
        if (patternBBox != null)
        {
            bbox = patternBBox;
        }
        clipToRect(bbox);
View Full Code Here

TOP

Related Classes of org.apache.pdfbox.pdmodel.common.PDRectangle

Copyright © 2018 www.massapicom. 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.