Example usage for com.itextpdf.text.pdf PdfContentByte setGState

List of usage examples for com.itextpdf.text.pdf PdfContentByte setGState

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfContentByte setGState.

Prototype

public void setGState(final PdfGState gstate) 

Source Link

Document

Sets the graphic state

Usage

From source file:org.gephi.preview.plugin.renderers.ArrowRenderer.java

License:Open Source License

public void renderStraight(RenderTarget target, Item item, float x1, float y1, float x2, float y2, float radius,
        float size, Color color) {
    Edge edge = (Edge) item.getSource();
    PVector direction = new PVector(x2, y2);
    direction.sub(new PVector(x1, y1));
    direction.normalize();/*from  w  ww.j  a  v a2s  .com*/

    PVector p1 = new PVector(direction.x, direction.y);
    p1.mult(radius);
    p1.add(new PVector(x2, y2));

    PVector p1r = new PVector(direction.x, direction.y);
    p1r.mult(radius - size);
    p1r.add(new PVector(x2, y2));

    PVector p2 = new PVector(-direction.y, direction.x);
    p2.mult(size * BASE_RATIO);
    p2.add(p1r);

    PVector p3 = new PVector(direction.y, -direction.x);
    p3.mult(size * BASE_RATIO);
    p3.add(p1r);

    if (target instanceof ProcessingTarget) {
        PGraphics graphics = ((ProcessingTarget) target).getGraphics();
        graphics.noStroke();
        graphics.fill(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
        graphics.triangle(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
    } else if (target instanceof SVGTarget) {
        SVGTarget svgTarget = (SVGTarget) target;
        Element arrowElem = svgTarget.createElement("polyline");
        arrowElem.setAttribute("points",
                String.format(Locale.ENGLISH, "%f,%f %f,%f %f,%f", p1.x, p1.y, p2.x, p2.y, p3.x, p3.y));
        arrowElem.setAttribute("class",
                edge.getSource().getNodeData().getId() + " " + edge.getTarget().getNodeData().getId());
        arrowElem.setAttribute("fill", svgTarget.toHexString(color));
        arrowElem.setAttribute("fill-opacity", (color.getAlpha() / 255f) + "");
        arrowElem.setAttribute("stroke", "none");
        svgTarget.getTopElement(SVGTarget.TOP_ARROWS).appendChild(arrowElem);
    } else if (target instanceof PDFTarget) {
        PDFTarget pdfTarget = (PDFTarget) target;
        PdfContentByte cb = pdfTarget.getContentByte();
        cb.moveTo(p1.x, -p1.y);
        cb.lineTo(p2.x, -p2.y);
        cb.lineTo(p3.x, -p3.y);
        cb.closePath();
        cb.setRGBColorFill(color.getRed(), color.getGreen(), color.getBlue());
        if (color.getAlpha() < 255) {
            cb.saveState();
            float alpha = color.getAlpha() / 255f;
            PdfGState gState = new PdfGState();
            gState.setFillOpacity(alpha);
            cb.setGState(gState);
        }
        cb.fill();
        if (color.getAlpha() < 255) {
            cb.restoreState();
        }
    }
}

From source file:org.gephi.preview.plugin.renderers.EdgeLabelRenderer.java

License:Open Source License

public void renderPDF(PDFTarget target, String label, float x, float y, Color color, float outlineSize,
        Color outlineColor) {/*from ww w  .  j  av  a 2 s  .co  m*/
    PdfContentByte cb = target.getContentByte();
    cb.setRGBColorFill(color.getRed(), color.getGreen(), color.getBlue());
    BaseFont bf = target.getBaseFont(font);
    float textHeight = getTextHeight(bf, font.getSize(), label);
    if (outlineSize > 0) {
        cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_STROKE);
        cb.setRGBColorStroke(outlineColor.getRed(), outlineColor.getGreen(), outlineColor.getBlue());
        cb.setLineWidth(outlineSize);
        cb.setLineJoin(PdfContentByte.LINE_JOIN_ROUND);
        cb.setLineCap(PdfContentByte.LINE_CAP_ROUND);
        if (outlineColor.getAlpha() < 255) {
            cb.saveState();
            float alpha = outlineColor.getAlpha() / 255f;
            PdfGState gState = new PdfGState();
            gState.setStrokeOpacity(alpha);
            cb.setGState(gState);
        }
        cb.beginText();
        cb.setFontAndSize(bf, font.getSize());
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, label, x, -y - (textHeight / 2f), 0f);
        cb.endText();
        if (outlineColor.getAlpha() < 255) {
            cb.restoreState();
        }
    }
    cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
    cb.beginText();
    cb.setFontAndSize(bf, font.getSize());
    cb.showTextAligned(PdfContentByte.ALIGN_CENTER, label, x, -y - (textHeight / 2f), 0f);
    cb.endText();
}

From source file:org.gephi.preview.plugin.renderers.EdgeRenderer.java

License:Open Source License

public void renderSelfLoop(Item nodeItem, float thickness, Color color, PreviewProperties properties,
        RenderTarget renderTarget) {// w  w w .jav  a 2s .c o m
    Float x = nodeItem.getData(NodeItem.X);
    Float y = nodeItem.getData(NodeItem.Y);
    Float size = nodeItem.getData(NodeItem.SIZE);
    Node node = (Node) nodeItem.getSource();

    PVector v1 = new PVector(x, y);
    v1.add(size, -size, 0);

    PVector v2 = new PVector(x, y);
    v2.add(size, size, 0);

    if (renderTarget instanceof ProcessingTarget) {
        PGraphics graphics = ((ProcessingTarget) renderTarget).getGraphics();
        graphics.strokeWeight(thickness);
        graphics.stroke(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
        graphics.noFill();
        graphics.bezier(x, y, v1.x, v1.y, v1.x, v2.y, x, y);
    } else if (renderTarget instanceof SVGTarget) {
        SVGTarget svgTarget = (SVGTarget) renderTarget;

        Element selfLoopElem = svgTarget.createElement("path");
        selfLoopElem.setAttribute("d", String.format(Locale.ENGLISH, "M %f,%f C %f,%f %f,%f %f,%f", x, y, v1.x,
                v1.y, v2.x, v2.y, x, y));
        selfLoopElem.setAttribute("class", node.getNodeData().getId());
        selfLoopElem.setAttribute("stroke", svgTarget.toHexString(color));
        selfLoopElem.setAttribute("stroke-opacity", (color.getAlpha() / 255f) + "");
        selfLoopElem.setAttribute("stroke-width", Float.toString(thickness * svgTarget.getScaleRatio()));
        selfLoopElem.setAttribute("fill", "none");
        svgTarget.getTopElement(SVGTarget.TOP_EDGES).appendChild(selfLoopElem);
    } else if (renderTarget instanceof PDFTarget) {
        PDFTarget pdfTarget = (PDFTarget) renderTarget;
        PdfContentByte cb = pdfTarget.getContentByte();
        cb.moveTo(x, -y);
        cb.curveTo(v1.x, -v1.y, v2.x, -v2.y, x, -y);
        cb.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue());
        cb.setLineWidth(thickness);
        if (color.getAlpha() < 255) {
            cb.saveState();
            float alpha = color.getAlpha() / 255f;
            PdfGState gState = new PdfGState();
            gState.setStrokeOpacity(alpha);
            cb.setGState(gState);
        }
        cb.stroke();
        if (color.getAlpha() < 255) {
            cb.restoreState();
        }
    }
}

From source file:org.gephi.preview.plugin.renderers.EdgeRenderer.java

License:Open Source License

public void renderCurvedEdge(Item edgeItem, Item sourceItem, Item targetItem, float thickness, Color color,
        PreviewProperties properties, RenderTarget renderTarget) {
    Edge edge = (Edge) edgeItem.getSource();
    Float x1 = sourceItem.getData(NodeItem.X);
    Float x2 = targetItem.getData(NodeItem.X);
    Float y1 = sourceItem.getData(NodeItem.Y);
    Float y2 = targetItem.getData(NodeItem.Y);

    //Curved edgs
    PVector direction = new PVector(x2, y2);
    direction.sub(new PVector(x1, y1));
    float length = direction.mag();
    direction.normalize();/*from w w  w. j  ava 2 s  . co  m*/

    float factor = properties.getFloatValue(BEZIER_CURVENESS) * length;

    // normal vector to the edge
    PVector n = new PVector(direction.y, -direction.x);
    n.mult(factor);

    // first control point
    PVector v1 = new PVector(direction.x, direction.y);
    v1.mult(factor);
    v1.add(new PVector(x1, y1));
    v1.add(n);

    // second control point
    PVector v2 = new PVector(direction.x, direction.y);
    v2.mult(-factor);
    v2.add(new PVector(x2, y2));
    v2.add(n);

    if (renderTarget instanceof ProcessingTarget) {
        PGraphics graphics = ((ProcessingTarget) renderTarget).getGraphics();
        graphics.strokeWeight(thickness);
        graphics.stroke(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
        graphics.noFill();
        graphics.bezier(x1, y1, v1.x, v1.y, v2.x, v2.y, x2, y2);
    } else if (renderTarget instanceof SVGTarget) {
        SVGTarget svgTarget = (SVGTarget) renderTarget;
        Element edgeElem = svgTarget.createElement("path");
        edgeElem.setAttribute("class",
                edge.getSource().getNodeData().getId() + " " + edge.getTarget().getNodeData().getId());
        edgeElem.setAttribute("d", String.format(Locale.ENGLISH, "M %f,%f C %f,%f %f,%f %f,%f", x1, y1, v1.x,
                v1.y, v2.x, v2.y, x2, y2));
        edgeElem.setAttribute("stroke", svgTarget.toHexString(color));
        edgeElem.setAttribute("stroke-width", Float.toString(thickness * svgTarget.getScaleRatio()));
        edgeElem.setAttribute("stroke-opacity", (color.getAlpha() / 255f) + "");
        edgeElem.setAttribute("fill", "none");
        svgTarget.getTopElement(SVGTarget.TOP_EDGES).appendChild(edgeElem);
    } else if (renderTarget instanceof PDFTarget) {
        PDFTarget pdfTarget = (PDFTarget) renderTarget;
        PdfContentByte cb = pdfTarget.getContentByte();
        cb.moveTo(x1, -y1);
        cb.curveTo(v1.x, -v1.y, v2.x, -v2.y, x2, -y2);
        cb.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue());
        cb.setLineWidth(thickness);
        if (color.getAlpha() < 255) {
            cb.saveState();
            float alpha = color.getAlpha() / 255f;
            PdfGState gState = new PdfGState();
            gState.setStrokeOpacity(alpha);
            cb.setGState(gState);
        }
        cb.stroke();
        if (color.getAlpha() < 255) {
            cb.restoreState();
        }
    }
}

From source file:org.gephi.preview.plugin.renderers.EdgeRenderer.java

License:Open Source License

public void renderStraightEdge(Item edgeItem, Item sourceItem, Item targetItem, float thickness, Color color,
        PreviewProperties properties, RenderTarget renderTarget) {
    Edge edge = (Edge) edgeItem.getSource();
    Float x1 = sourceItem.getData(NodeItem.X);
    Float x2 = targetItem.getData(NodeItem.X);
    Float y1 = sourceItem.getData(NodeItem.Y);
    Float y2 = targetItem.getData(NodeItem.Y);

    //Target radius - to start at the base of the arrow
    Float targetRadius = edgeItem.getData(TARGET_RADIUS);
    //Avoid edge from passing the node's center:
    if (targetRadius != null && targetRadius < 0) {
        PVector direction = new PVector(x2, y2);
        direction.sub(new PVector(x1, y1));
        direction.normalize();/*from   w  ww.j  a  va 2s.  c om*/
        direction = new PVector(direction.x, direction.y);
        direction.mult(targetRadius);
        direction.add(new PVector(x2, y2));
        x2 = direction.x;
        y2 = direction.y;
    }
    //Source radius
    Float sourceRadius = edgeItem.getData(SOURCE_RADIUS);
    //Avoid edge from passing the node's center:
    if (sourceRadius != null && sourceRadius < 0) {
        PVector direction = new PVector(x1, y1);
        direction.sub(new PVector(x2, y2));
        direction.normalize();
        direction = new PVector(direction.x, direction.y);
        direction.mult(sourceRadius);
        direction.add(new PVector(x1, y1));
        x1 = direction.x;
        y1 = direction.y;
    }

    if (renderTarget instanceof ProcessingTarget) {
        PGraphics graphics = ((ProcessingTarget) renderTarget).getGraphics();
        graphics.strokeWeight(thickness);
        graphics.strokeCap(PGraphics.SQUARE);
        graphics.stroke(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
        graphics.noFill();
        graphics.line(x1, y1, x2, y2);
    } else if (renderTarget instanceof SVGTarget) {
        SVGTarget svgTarget = (SVGTarget) renderTarget;
        Element edgeElem = svgTarget.createElement("path");
        edgeElem.setAttribute("class",
                edge.getSource().getNodeData().getId() + " " + edge.getTarget().getNodeData().getId());
        edgeElem.setAttribute("d", String.format(Locale.ENGLISH, "M %f,%f L %f,%f", x1, y1, x2, y2));
        edgeElem.setAttribute("stroke", svgTarget.toHexString(color));
        DecimalFormat df = new DecimalFormat("#.########");
        edgeElem.setAttribute("stroke-width", df.format(thickness * svgTarget.getScaleRatio()));
        edgeElem.setAttribute("stroke-opacity", (color.getAlpha() / 255f) + "");
        edgeElem.setAttribute("fill", "none");
        svgTarget.getTopElement(SVGTarget.TOP_EDGES).appendChild(edgeElem);
    } else if (renderTarget instanceof PDFTarget) {
        PDFTarget pdfTarget = (PDFTarget) renderTarget;
        PdfContentByte cb = pdfTarget.getContentByte();
        cb.moveTo(x1, -y1);
        cb.lineTo(x2, -y2);
        cb.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue());
        cb.setLineWidth(thickness);
        if (color.getAlpha() < 255) {
            cb.saveState();
            float alpha = color.getAlpha() / 255f;
            PdfGState gState = new PdfGState();
            gState.setStrokeOpacity(alpha);
            cb.setGState(gState);
        }
        cb.stroke();
        if (color.getAlpha() < 255) {
            cb.restoreState();
        }
    }
}

From source file:org.gephi.preview.plugin.renderers.NodeLabelRenderer.java

License:Open Source License

public void renderPDF(PDFTarget target, Node node, String label, float x, float y, int fontSize, Color color,
        float outlineSize, Color outlineColor, boolean showBox, Color boxColor) {
    Font font = fontCache.get(fontSize);
    PdfContentByte cb = target.getContentByte();
    BaseFont bf = target.getBaseFont(font);

    //Box//from   w w w.  j  av  a  2  s  .c  om
    if (showBox) {
        cb.setRGBColorFill(boxColor.getRed(), boxColor.getGreen(), boxColor.getBlue());
        if (boxColor.getAlpha() < 255) {
            cb.saveState();
            float alpha = boxColor.getAlpha() / 255f;
            PdfGState gState = new PdfGState();
            gState.setFillOpacity(alpha);
            cb.setGState(gState);
        }
        float textWidth = getTextWidth(bf, fontSize, label);
        float textHeight = getTextHeight(bf, fontSize, label);

        //A height of just textHeight seems to be half the text height sometimes
        //BaseFont getAscentPoint and getDescentPoint may be not very precise
        cb.rectangle(x - textWidth / 2f - outlineSize / 2f, -y - outlineSize / 2f - textHeight,
                textWidth + outlineSize, textHeight * 2f + outlineSize);

        cb.fill();
        if (boxColor.getAlpha() < 255) {
            cb.restoreState();
        }
    }

    cb.setRGBColorFill(color.getRed(), color.getGreen(), color.getBlue());
    float textHeight = getTextHeight(bf, fontSize, label);
    if (outlineSize > 0) {
        cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_STROKE);
        cb.setRGBColorStroke(outlineColor.getRed(), outlineColor.getGreen(), outlineColor.getBlue());
        cb.setLineWidth(outlineSize);
        cb.setLineJoin(PdfContentByte.LINE_JOIN_ROUND);
        cb.setLineCap(PdfContentByte.LINE_CAP_ROUND);
        if (outlineColor.getAlpha() < 255) {
            cb.saveState();
            float alpha = outlineColor.getAlpha() / 255f;
            PdfGState gState = new PdfGState();
            gState.setStrokeOpacity(alpha);
            cb.setGState(gState);
        }
        cb.beginText();
        cb.setFontAndSize(bf, font.getSize());
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, label, x, -y - (textHeight / 2f), 0f);
        cb.endText();
        if (outlineColor.getAlpha() < 255) {
            cb.restoreState();
        }
    }
    cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
    cb.beginText();
    cb.setFontAndSize(bf, font.getSize());
    cb.showTextAligned(PdfContentByte.ALIGN_CENTER, label, x, -y - (textHeight / 2f), 0f);
    cb.endText();
}

From source file:org.gephi.preview.plugin.renderers.NodeRenderer.java

License:Open Source License

public void renderPDF(Item item, PDFTarget target, PreviewProperties properties) {
    Float x = item.getData(NodeItem.X);
    Float y = item.getData(NodeItem.Y);
    Float size = item.getData(NodeItem.SIZE);
    size /= 2f;/*  w w  w . j a  v  a  2 s .  co m*/
    Color color = item.getData(NodeItem.COLOR);
    Color borderColor = ((DependantColor) properties.getValue(PreviewProperty.NODE_BORDER_COLOR))
            .getColor(color);
    float borderSize = properties.getFloatValue(PreviewProperty.NODE_BORDER_WIDTH);
    float alpha = properties.getFloatValue(PreviewProperty.NODE_OPACITY) / 100f;

    PdfContentByte cb = target.getContentByte();
    cb.setRGBColorStroke(borderColor.getRed(), borderColor.getGreen(), borderColor.getBlue());
    cb.setLineWidth(borderSize);
    cb.setRGBColorFill(color.getRed(), color.getGreen(), color.getBlue());
    if (alpha < 1f) {
        cb.saveState();
        PdfGState gState = new PdfGState();
        gState.setFillOpacity(alpha);
        gState.setStrokeOpacity(alpha);
        cb.setGState(gState);
    }
    cb.circle(x, -y, size);
    if (borderSize > 0) {
        cb.fillStroke();
    } else {
        cb.fill();
    }
    if (alpha < 1f) {
        cb.restoreState();
    }
}

From source file:org.h819.commons.file.MyPDFUtils.java

/**
 * ??//from  www .  ja  v a2s . com
 *
 * @param srcPdf         ?
 * @param destPdf        
 * @param waterMarkText  ?
 * @param waterMarkImage ?
 */
public static void addWaterMarkFile(File srcPdf, File destPdf, String waterMarkText, File waterMarkImage)
        throws IOException, DocumentException {

    if (waterMarkText == null && waterMarkImage == null)
        throw new FileNotFoundException(waterMarkText + " " + waterMarkImage + " all null.");

    if (srcPdf == null || !srcPdf.exists() || !srcPdf.isFile())
        throw new FileNotFoundException("pdf file :  '" + srcPdf + "' does not exsit.");

    if (!FilenameUtils.getExtension(srcPdf.getAbsolutePath()).toLowerCase().equals("pdf"))
        return;

    if (waterMarkImage != null) {
        if (!waterMarkImage.exists() || !waterMarkImage.isFile())
            throw new FileNotFoundException("img file :  '" + srcPdf + "' does not exsit.");

        if (!FilenameUtils.getExtension(waterMarkImage.getAbsolutePath()).toLowerCase().equals("png"))
            throw new FileNotFoundException("image file '" + srcPdf
                    + "'  not png.(???? pdf )");
    }

    PdfReader reader = getPdfReader(srcPdf);

    int n = reader.getNumberOfPages();
    PdfStamper stamper = getPdfStamper(srcPdf, destPdf);

    //
    //        HashMap<String, String> moreInfo = new HashMap<String, String>();
    //        moreInfo.put("Author", "H819 create");
    //        moreInfo.put("Producer", "H819 Producer");
    //        Key = CreationDate, Value = D:20070425182920
    //        Key = Producer, Value = TH-OCR 2000 (C++/Win32)
    //        Key = Author, Value = TH-OCR 2000
    //        Key = Creator, Value = TH-OCR PDF Writer

    // stamp.setMoreInfo(moreInfo);

    // text
    Phrase text = null;
    if (waterMarkText != null) {
        //
        Font bfont = getPdfFont();
        bfont.setSize(35);
        bfont.setColor(new BaseColor(192, 192, 192));
        text = new Phrase(waterMarkText, bfont);
    }
    // image watermark
    Image img = null;
    float w = 0;
    float h = 0;
    if (waterMarkImage != null) {
        img = Image.getInstance(waterMarkImage.getAbsolutePath());
        w = img.getScaledWidth();
        h = img.getScaledHeight();
        //  img.
        img.setRotationDegrees(45);

    }

    // transparency
    PdfGState gs1 = new PdfGState();
    gs1.setFillOpacity(0.5f);
    // properties
    PdfContentByte over;
    Rectangle pageSize;
    float x, y;
    // loop over every page
    for (int i = 1; i <= n; i++) {
        pageSize = reader.getPageSizeWithRotation(i);
        x = (pageSize.getLeft() + pageSize.getRight()) / 2;
        y = (pageSize.getTop() + pageSize.getBottom()) / 2;
        //  pdf pdf ???
        over = stamper.getOverContent(i);
        // ?
        // over = stamp.getUnderContent(i);
        // ?? over.beginText(); over.endText(); ?
        // ,?,:????
        over.saveState(); //??
        over.setGState(gs1);

        if (waterMarkText != null && waterMarkImage != null) { // 
            if (i % 2 == 1) {
                ColumnText.showTextAligned(over, Element.ALIGN_CENTER, text, x, y, 45);
            } else
                over.addImage(img, w, 0, 0, h, x - (w / 2), y - (h / 2));
        } else if (waterMarkText != null) { //?

            ColumnText.showTextAligned(over, Element.ALIGN_CENTER, text, x, y, 45);
            //?? ,?, :?????
            // ...

        } else { //?
            over.addImage(img, w, 0, 0, h, x - (w / 2), y - (h / 2));
        }

        over.restoreState();//???
    }

    stamper.close();
    reader.close();

}

From source file:org.yale.cs.graphics.gephi.imagepreview.ImageNodes.java

License:Open Source License

public void renderImagePDF(ImageItem item, PDFTarget target, PreviewProperties properties, File directory) {

    Image image = item.renderPDF(directory);

    if (image == null) {
        logger.log(Level.WARNING, "Unable to load image: {0}", item.getSource());
        return;/*from  w ww  .  j av  a 2s  .c o m*/
    }

    Float x = item.getData(NodeItem.X);
    Float y = item.getData(NodeItem.Y);
    Float size = item.getData(NodeItem.SIZE);

    float alpha = properties.getFloatValue(IMAGE_OPACITY) / 100f;

    PdfContentByte cb = target.getContentByte();

    if (alpha < 1f) {
        cb.saveState();
        PdfGState gState = new PdfGState();
        gState.setFillOpacity(alpha);
        gState.setStrokeOpacity(alpha);
        cb.setGState(gState);
    }

    image.setAbsolutePosition(x - size / 2, -y - size / 2);
    image.scaleToFit(size, size);
    try {
        cb.addImage(image);
    } catch (DocumentException ex) {
        logger.log(Level.SEVERE, "Unable to add image to document: " + item.getSource(), ex);
    }

    if (alpha < 1f) {
        cb.restoreState();
    }
}

From source file:PDF.CrearPDF_Ficha.java

public static void drawRectangle(PdfContentByte content, float x, float y, float width, float height) {
    try {/*from   ww  w .  ja v a 2s.c o m*/

        content.saveState();

        PdfGState state = new PdfGState();
        content.setGState(state);
        content.setRGBColorFill(232, 232, 232);
        content.setColorStroke(BaseColor.BLUE);
        content.setLineWidth((float) .5);
        content.rectangle(x, y, width, height);
        content.fillStroke();
        content.restoreState();

        BaseFont bf = BaseFont.createFont();
        float fontSize = 15f;
        Phrase phrase = new Phrase("Foto", new Font(bf, fontSize));
        ColumnText.showTextAligned(content, Element.ALIGN_CENTER, phrase, 475, 687, 0);
    } catch (DocumentException ex) {
        Logger.getLogger(CrearPDF_Ficha.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(CrearPDF_Ficha.class.getName()).log(Level.SEVERE, null, ex);
    }
}