Package org.apache.pdfbox.pdmodel.common

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


     */
    private void clipToRect(PDRectangle rectangle)
    {
        if (rectangle != null)
        {
            PDRectangle clip = rectangle.transform(getGraphicsState().getCurrentTransformationMatrix());
            getGraphicsState().intersectClippingPath(new Area(clip.toGeneralPath()));
        }
    }
View Full Code Here


            // get the CTM x Form Matrix transform
            Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();
            Matrix transform = Matrix.concatenate(ctm, form.getMatrix());

            // transform the bbox
            PDRectangle bbox = form.getBBox().transform(transform);

            // clip the bbox to prevent giant bboxes from consuming all memory
            Area clip = (Area)getGraphicsState().getCurrentClippingPath().clone();
            clip.intersect(new Area(bbox.toGeneralPath()));
            Rectangle2D clipRect = clip.getBounds2D();
            this.bbox = new PDRectangle((float)clipRect.getX(), (float)clipRect.getY(),
                                        (float)clipRect.getWidth(), (float)clipRect.getHeight());

            // apply the underlying Graphics2D device's DPI transform
            Shape deviceClip = xform.createTransformedShape(clip);
            Rectangle2D bounds = deviceClip.getBounds2D();
View Full Code Here

        // Distinction of case for visual and non-visual signature
        if (visualSignature == null) // non-visual signature
        {
            // Set rectangle for non-visual signature to 0 0 0 0
            signatureField.getWidget().setRectangle(new PDRectangle()); // rectangle array [ 0 0 0 0 ]
            // Clear AcroForm / Set DefaultRessource
            acroForm.setDefaultResources(null);
            // Set empty Appearance-Dictionary
            PDAppearanceDictionary ap = new PDAppearanceDictionary();

            COSStream apsStream = getDocument().createCOSStream();
            apsStream.createUnfilteredStream();
            PDAppearanceStream aps = new PDAppearanceStream(apsStream);
            COSDictionary cosObject = (COSDictionary) aps.getCOSObject();
            cosObject.setItem(COSName.SUBTYPE, COSName.FORM);
            cosObject.setItem(COSName.BBOX, new PDRectangle());

            ap.setNormalAppearance(aps);
            ap.getCOSObject().setDirect(true);
            signatureField.getWidget().setAppearance(ap);
        }
        else
        // visual signature
        {
            // Obtain visual signature object
            List<COSObject> cosObjects = visualSignature.getObjects();

            boolean annotNotFound = true;
            boolean sigFieldNotFound = true;
            COSDictionary acroFormDict = acroForm.getDictionary();
            for (COSObject cosObject : cosObjects)
            {
                if (!annotNotFound && !sigFieldNotFound)
                {
                    break;
                }

                COSBase base = cosObject.getObject();
                if (base != null && base instanceof COSDictionary)
                {
                    COSBase ft = ((COSDictionary) base).getItem(COSName.FT);
                    COSBase type = ((COSDictionary) base).getItem(COSName.TYPE);
                    COSBase apDict = ((COSDictionary) base).getItem(COSName.AP);

                    // Search for signature annotation
                    if (annotNotFound && COSName.ANNOT.equals(type))
                    {
                        COSDictionary cosBaseDict = (COSDictionary) base;

                        // Read and set the Rectangle for visual signature
                        COSArray rectAry = (COSArray) cosBaseDict.getItem(COSName.RECT);
                        PDRectangle rect = new PDRectangle(rectAry);
                        signatureField.getWidget().setRectangle(rect);
                        annotNotFound = false;
                    }

                    // Search for Signature-Field
View Full Code Here

    {
        COSArray array =
            (COSArray) this.getCOSDictionary().getDictionaryObject(BBOX);
        if (array != null)
        {
            return new PDRectangle(array);
        }
        return null;
    }
View Full Code Here

            float fontSize = 96;
            contentStream.setFont(font, fontSize);
            String text = "OVERLAY";
            //float sw = font.getStringWidth(text);
            //Too bad, base 14 fonts don't return character metrics.
            PDRectangle crop = page.getCropBox();
            float cx = crop.getWidth() / 2f;
            float cy = crop.getHeight() / 2f;
            AffineTransform transform = new AffineTransform();
            transform.translate(cx, cy);
            transform.rotate(Math.toRadians(45));
            transform.translate(-190 /* sw/2 */, 0);
            contentStream.setTextMatrix(transform);
View Full Code Here

            PDFont font = PDType1Font.HELVETICA_BOLD;
            float fontSize = 36.0f;

            for( PDPage page : doc.getPages() )
            {
                PDRectangle pageSize = page.getMediaBox();
                float stringWidth = font.getStringWidth( message )*fontSize/1000f;
                // calculate to center of the page
                int rotation = page.getRotation();
                boolean rotate = rotation == 90 || rotation == 270;
                float pageWidth = rotate ? pageSize.getHeight() : pageSize.getWidth();
                float pageHeight = rotate ? pageSize.getWidth() : pageSize.getHeight();
                double centeredXPosition = rotate ? pageHeight/2f : (pageWidth - stringWidth)/2f;
                double centeredYPosition = rotate ? (pageWidth - stringWidth)/2f : pageHeight/2f;
                // append the content to the existing stream
                PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, true,true);
                contentStream.beginText();
View Full Code Here

     *
     * @return The CropBox at this level in the hierarchy.
     */
    private PDRectangle getRotatedCropBox(PDPage page)
    {
        PDRectangle cropBox = page.getCropBox();
        int rotation = page.getRotation();
        if (rotation == 90 || rotation == 270)
        {
            return new PDRectangle(cropBox.getLowerLeftY(), cropBox.getLowerLeftX(),
                    cropBox.getHeight(), cropBox.getWidth());
        }
        else
        {
            return cropBox;
        }
View Full Code Here

            PDPage page = document.getPage(pageIndex);

            // auto portrait/landscape
            if (orientation == Orientation.AUTO)
            {
                PDRectangle cropBox = getRotatedCropBox(page);
                if (cropBox.getWidth() > cropBox.getHeight())
                {
                    format.setOrientation(PageFormat.LANDSCAPE);
                }
                else
                {
View Full Code Here

    public BufferedImage renderImage(int pageIndex, float scale, ImageType imageType)
            throws IOException
    {
        PDPage page = document.getPage(pageIndex);

        PDRectangle cropbBox = page.getCropBox();
        float widthPt = cropbBox.getWidth();
        float heightPt = cropbBox.getHeight();
        int widthPx = Math.round(widthPt * scale);
        int heightPx = Math.round(heightPt * scale);
        int rotationAngle = page.getRotation();

        // normalize the rotation angle
View Full Code Here

    public void renderPageToGraphics(int pageIndex, Graphics2D graphics, float scale)
            throws IOException
    {
        PDPage page = document.getPage(pageIndex);
        // TODO need width/wight calculations? should these be in PageDrawer?
        PDRectangle adjustedCropBox = page.getCropBox();
        renderPage(page, graphics, (int)adjustedCropBox.getWidth(), (int)adjustedCropBox.getHeight(), scale, scale);
    }
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.