Example usage for com.itextpdf.text Image setBorderColor

List of usage examples for com.itextpdf.text Image setBorderColor

Introduction

In this page you can find the example usage for com.itextpdf.text Image setBorderColor.

Prototype

public void setBorderColor(final BaseColor borderColor) 

Source Link

Document

Sets the color of the border.

Usage

From source file:com.mycom.products.mywebsite.backend.util.DownloadHandler.java

License:Open Source License

@RequestMapping(value = "/user/{id}", method = RequestMethod.GET)
protected final void downloadUserInformation(@PathVariable int id, HttpServletRequest request,
        final HttpServletResponse response) throws ServletException, BusinessException, DocumentException {
    UserBean user = userService.select(id, FetchMode.EAGER);
    if (user == null) {
        return;/* w  w  w  .jav a 2  s.c om*/
    }
    Document document = new Document();
    document.setMargins(70, 70, 20, 20);

    try {
        response.setContentType("application/pdf");
        response.setHeader("Content-Disposition",
                "attachment; filename=\"" + user.getName() + "_profile.pdf\"");
        PdfWriter.getInstance(document, response.getOutputStream());
        document.open();
        Image profileImage = null;
        try {
            profileImage = Image.getInstance(user.getContent().getFilePath());
        } catch (Exception e) {
            // e.printStackTrace();
        }
        if (profileImage != null) {
            profileImage.setAlignment(Image.MIDDLE | Image.TEXTWRAP);
            profileImage.setBorder(Image.BOX);
            profileImage.setBorderWidth(5);
            BaseColor bgcolor = WebColors.getRGBColor("#E5E3E3");
            profileImage.setBorderColor(bgcolor);
            profileImage.scaleToFit(100, 100);
            document.add(profileImage);
        }
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);

        // Adding Table Data
        PdfPTable table = new PdfPTable(2); // 2 columns.
        table.setWidthPercentage(100); // Width 100%
        table.setSpacingBefore(15f); // Space before table
        table.setSpacingAfter(15f); // Space after table

        // Set Column widths
        float[] columnWidths = { 1f, 2f, };
        table.setWidths(columnWidths);

        // Name
        setTableHeader("Name", table);
        setTableContent(user.getName(), table);

        // Gender
        setTableHeader("Gender", table);
        String gender = "Male";
        if (user.getGender() == Gender.FEMALE) {
            gender = "Female";
        }
        setTableContent(gender, table);

        // Age
        setTableHeader("Age", table);
        setTableContent("" + user.getAge(), table);

        // Date of Birth
        setTableHeader("DOB", table);
        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
        setTableContent(dateFormatter.format(user.getDob()), table);

        // Email
        setTableHeader("Email", table);
        setTableContent(user.getEmail(), table);

        // NRC
        setTableHeader("NRC", table);
        setTableContent(user.getNrc(), table);

        // Phone
        setTableHeader("Phone", table);
        setTableContent(user.getPhone(), table);

        // Roles
        String roleStr = "";
        List<RoleBean> roles = user.getRoles();
        if (roles != null && roles.size() > 0) {
            Iterator<RoleBean> itr = roles.iterator();
            while (itr.hasNext()) {
                RoleBean role = itr.next();
                roleStr += role.getName();
                if (itr.hasNext()) {
                    roleStr += ",";
                }
            }
        }
        setTableHeader("Role(s)", table);
        setTableContent(roleStr, table);

        // Address
        setTableHeader("Address", table);
        setTableContent(user.getAddress(), table);

        document.add(table);
        document.add(new Paragraph(new Date().toString()));

    } catch (Exception e) {
        e.printStackTrace();

    }
    document.close();
}

From source file:com.vectorprint.report.itext.debug.DebugHelper.java

License:Open Source License

/**
 * When in debugging mode, adds a border to the image and calls {@link VectorPrintDocument#addHook(com.vectorprint.report.itext.VectorPrintDocument.AddElementHook)
 * } to be able to print debugging info and link for the image
 *
 * @param canvas//from  w w  w.jav  a2  s.  c o m
 * @param img
 * @param bordercolor
 * @param styleClass
 * @param extraInfo
 * @param settings
 * @param layerAware
 * @param document
 */
public static void debugImage(PdfContentByte canvas, Image img, Color bordercolor, String styleClass,
        String extraInfo, EnhancedMap settings, LayerManager layerAware, VectorPrintDocument document) {
    if (null != img) {
        img.setBorder(Rectangle.BOX);
        img.setBorderWidth(0.3f);
        img.setBorderColor(itextHelper.fromColor(bordercolor));
        if (styleClass == null) {
            log.warning("not showing link to styleClass because there is no styleClass");
            return;
        }
        img.setAnnotation(new Annotation(DEBUG,
                "click for link to styleClass information (" + styleClass + extraInfo + ")"));
        document.addHook(new VectorPrintDocument.AddElementHook(
                VectorPrintDocument.AddElementHook.INTENTION.DEBUGIMAGE, img, null, styleClass));
    }
}

From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.AbstractContentFactory.java

License:Open Source License

protected Paragraph decorateImage(Image i, String caption) {

    Paragraph p = new Paragraph("", IMAGE_CAPTION);
    p.setAlignment(Element.ALIGN_CENTER);
    i.setAlignment(Element.ALIGN_CENTER);
    i.setBorder(Image.BOX);/*from w ww  . ja  va 2 s .c  o m*/
    i.setBorderWidth(3f);
    i.setBorderColor(new BaseColor(52, 90, 138));
    p.add(i);

    Paragraph captionP = new Paragraph(caption, IMAGE_CAPTION);
    captionP.setAlignment(Element.ALIGN_CENTER);
    //p.add(Chunk.NEWLINE);
    p.add(captionP);

    //p.setKeepTogether(true);
    return p;
}

From source file:utils.pdf.cv_templates.Template1.java

private void addImage(User user) throws DocumentException, IOException {
    Image photo_img;
    if (!user.photo.id.equals("")) {
        photo_img = Image// w ww.  j  a  v a  2 s .c  o m
                .getInstance(String.format("https://s3.amazonaws.com/aunclickdelempleo2/" + user.photo.id));
    } else {
        photo_img = Image.getInstance(String.format("public/images/orientation/photo/ic_profile.png"));
    }

    photo_img.setAbsolutePosition(40, 670);
    photo_img.setAlignment(Image.LEFT | Image.TEXTWRAP);
    photo_img.setBorder(Image.BOX);
    photo_img.setBorderWidth(10);
    photo_img.setBorderColor(BaseColor.WHITE);
    photo_img.scaleToFit(1000, 130);
    document.add(photo_img);
}

From source file:utils.pdf.cv_templates.Template1.java

private void addImageTelephone() throws DocumentException, IOException {
    Image phone_img;
    phone_img = Image.getInstance(String.format("public/images/orientation/cv-templates/CV1/ic_mobile.png"));
    phone_img.setAbsolutePosition(175, 708);
    phone_img.setAlignment(Image.LEFT | Image.TEXTWRAP);
    phone_img.setBorder(Image.BOX);
    phone_img.setBorderWidth(10);//from w  w  w.  j  a v  a 2 s  . c om
    phone_img.setBorderColor(BaseColor.WHITE);
    phone_img.scaleToFit(1000, 18);
    document.add(phone_img);
}

From source file:utils.pdf.cv_templates.Template1.java

private void addImageEmail() throws DocumentException, IOException {
    Image email_img;
    email_img = Image.getInstance(String.format("public/images/orientation/cv-templates/CV1/ic_mail.png"));
    email_img.setAbsolutePosition(173, 690);
    email_img.setAlignment(Image.LEFT | Image.TEXTWRAP);
    email_img.setBorder(Image.BOX);
    email_img.setBorderWidth(10);//w w w .ja va  2 s  .c om
    email_img.setBorderColor(BaseColor.WHITE);
    email_img.scaleToFit(1000, 11);
    document.add(email_img);
}

From source file:utils.pdf.cv_templates.Template1.java

private void addImageAddress() throws DocumentException, IOException {
    Image address_img;
    address_img = Image//from  w ww  . j a  v a2  s  . c  o  m
            .getInstance(String.format("public/images/orientation/cv-templates/CV1/ic_location.png"));
    address_img.setAbsolutePosition(173, 730);
    address_img.setAlignment(Image.LEFT | Image.TEXTWRAP);
    address_img.setBorder(Image.BOX);
    address_img.setBorderWidth(10);
    address_img.setBorderColor(BaseColor.WHITE);
    address_img.scaleToFit(1000, 18);
    document.add(address_img);
}

From source file:utils.pdf.cv_templates.Template1.java

private void addImageLine() throws DocumentException, IOException {
    Image line_img;
    line_img = Image//from   w  ww  . ja v  a  2 s  . com
            .getInstance(String.format("public/images/orientation/cv-templates/CV1/ic_barra_lineas3.png"));
    line_img.setAbsolutePosition(40, 50);
    line_img.setAlignment(Image.LEFT | Image.TEXTWRAP);
    line_img.setBorder(Image.BOX);
    line_img.setBorderWidth(10);
    line_img.setBorderColor(BaseColor.WHITE);
    line_img.scaleToFit(1000, 100);
    document.add(line_img);
}

From source file:utils.pdf.cv_templates.Template1.java

private void addImageLine1() throws DocumentException, IOException {
    Image line_img;
    line_img = Image//from   w w  w.j av  a 2  s.c  om
            .getInstance(String.format("public/images/orientation/cv-templates/CV1/ic_barra_lineas3.png"));
    line_img.setAbsolutePosition(40, 150);
    line_img.setAlignment(Image.LEFT | Image.TEXTWRAP);
    line_img.setBorder(Image.BOX);
    line_img.setBorderWidth(10);
    line_img.setBorderColor(BaseColor.WHITE);
    line_img.scaleToFit(1000, 100);
    document.add(line_img);
}

From source file:utils.pdf.cv_templates.Template1.java

private void addImageLine2() throws DocumentException, IOException {
    Image line_img;
    line_img = Image//w w w .  j av a2  s  . c o m
            .getInstance(String.format("public/images/orientation/cv-templates/CV1/ic_barra_lineas3.png"));
    line_img.setAbsolutePosition(40, 250);
    line_img.setAlignment(Image.LEFT | Image.TEXTWRAP);
    line_img.setBorder(Image.BOX);
    line_img.setBorderWidth(10);
    line_img.setBorderColor(BaseColor.WHITE);
    line_img.scaleToFit(1000, 100);
    document.add(line_img);
}