Example usage for com.itextpdf.text.pdf PdfPCell PdfPCell

List of usage examples for com.itextpdf.text.pdf PdfPCell PdfPCell

Introduction

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

Prototype

public PdfPCell() 

Source Link

Document

Constructs an empty PdfPCell.

Usage

From source file:imprimer.java

public void quitter_territoire() {

    Document document = new Document(PageSize.A4);
    try {/*from  www  . j  a  v a 2  s  .  com*/
        PdfWriter.getInstance(document, new FileOutputStream("quitter territoire.pdf"));

        document.open();
        imagee(document);

        document.open();
        imagee(document);
        SimpleDateFormat td = new SimpleDateFormat("dd-MM-yyyy");
        java.util.Date now = new java.util.Date();
        String tdnow = td.format(now);
        Paragraph pa = new Paragraph("Autorisation de quitter le territoire",
                FontFactory.getFont(FontFactory.TIMES, 30, Font.UNDERLINE, BaseColor.DARK_GRAY));
        pa.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(pa);
        for (int i = 0; i < 4; i++) {
            document.add(new Paragraph(" "));
        }

        //      cell = new PdfPCell(new Phrase("Fusion de 2 cellules de la premire colonne"));
        //      cell.setRowspan(2);
        //      table.addCell(cell);
        PdfPTable table = new PdfPTable(2);
        PdfPCell cell = new PdfPCell();
        //contenu du tableau.
        table.addCell("\nNom:\n\n");
        table.addCell("\n\n");
        table.addCell("\nPrenom:\n\n");
        table.addCell("\n\n");
        table.addCell("\nGRADE :\n\n");
        table.addCell("\n\n");
        table.addCell("\nADRESSE PERSONNELLE :\n\n");
        table.addCell("\n\n");
        table.addCell("\nAFFECTATION :\n\n");
        table.addCell("\n\n");

        cell = new PdfPCell(
                new Phrase("\nJai  lhonneur de solliciter une autorisation  dabsence.\n\n"));
        cell.setColspan(2);
        table.addCell(cell);

        table.addCell("\nDU:\n\n");
        table.addCell("\n\n");
        table.addCell("\nAU:\n\n");
        table.addCell("\n\n");
        table.addCell("\nMOTIF :\n\n");
        table.addCell("\n\n");
        table.addCell("\nAVIS DU  CHEF \nDETABLISSEMENT:\n\n");
        table.addCell("\n\nFAVORABLE.def\n\n");
        cell = new PdfPCell(new Phrase("\nFait  Ouarzazate le :" + tdnow + "\n\n"));
        cell.setColspan(2);

        table.addCell(cell);
        table.addCell("Signature du  demandeur\n\n\n\n\n\n\n\n\n");
        table.addCell("Cachet  et  signature\n\n\n\n\n\n\n\n");
        document.add(table);
        document.close();
        Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.OPEN)) {
            desktop.open(new File("quitter territoire.pdf"));
        } else {
            System.out.println("Open is not supported");
        }

    } catch (Exception ex) {
        System.out.print("catch");
    }
}

From source file:bd.gov.forms.web.FormBuilder.java

License:Open Source License

@RequestMapping(value = "/individualpdf", method = RequestMethod.GET)
public String individualpdf(@RequestParam(value = "formId", required = true) String formId,
        @RequestParam(value = "entryId", required = true) String entryId, ModelMap model,
        HttpServletResponse response) throws IOException {

    byte[] fileContent = formDao.getTemplateContent(formId);
    Form form = formDao.getFormWithFields(formId);
    form.setEntryId(entryId);// ww w.j a v  a 2s. com

    form = formDao.getEntry(form);
    String report = "";

    Document document = new Document();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    if (fileContent != null) {
        report = new String(fileContent, "UTF8");

        for (Field field : form.getFields()) {
            if (fieldTypeIsNotOfFileOrNoteOrSection(field)) {
                report = report.replaceAll("#" + field.getColName() + ":label#", field.getLabel());
                report = report.replaceAll("#" + field.getColName() + ":value#", field.getStrVal());
            }
        }
    }

    else {
        // step 2
        try {
            response.reset();
            response.setContentType("application/pdf");
            response.setHeader("Content-disposition", "inline; filename=test.pdf");

            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0);
            response.setHeader("Pragma", "No-cache");

            PdfWriter writer = PdfWriter.getInstance(document, baos);
            // step 3
            document.open();

            PdfPCell space;
            space = new PdfPCell();
            space.setBorder(Rectangle.NO_BORDER);
            space.setColspan(2);
            space.setFixedHeight(8);

            PdfPTable table = new PdfPTable(2);
            PdfPCell cell;

            report += "<table cellspacing='0' cellpadding='0' style='border:1px solid #aaa;width:98%;'>";

            for (Field field : form.getFields()) {
                if (fieldTypeIsNotOfFileOrNoteOrSection(field)) {

                    report += field.getLabel();

                    report += field.getStrVal();

                    table.setWidths(new int[] { 1, 2 });
                    table.addCell(field.getLabel());
                    //cell = new PdfPCell();
                    //cell.setCellEvent(new TextFields(1));
                    table.addCell(field.getStrVal());

                }
            }

            document.add(table);
            document.close();
            ServletOutputStream out = response.getOutputStream();
            baos.writeTo(out);
            out.flush();

        }

        catch (Exception ex) {
            System.out.println("Could not print reasone::" + ex.toString());

        }

    }

    return null;

}

From source file:bd.gov.forms.web.FormBuilder.java

License:Open Source License

@RequestMapping(value = "/pdfExport", method = RequestMethod.GET)
public String pdfExport(@RequestParam(value = "formId", required = true) String formId,
        @RequestParam(value = "page", required = false) Integer page,
        @RequestParam(value = "colName", required = false) String colName,
        @RequestParam(value = "colVal", required = false) String colVal,
        @RequestParam(value = "sortCol", required = false) String sortCol,
        @RequestParam(value = "sortDir", required = false) String sortDir, ModelMap model,
        HttpServletResponse response, HttpServletRequest request) throws IOException {

    Document document = new Document();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    // step 2/* w  w  w .j a  v a 2  s  . co m*/
    try {
        response.reset();
        response.setContentType("application/pdf");
        response.setHeader("Content-disposition", "inline; filename=test.pdf");

        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        response.setHeader("Pragma", "No-cache");

        PdfWriter writer = PdfWriter.getInstance(document, baos);
        // step 3
        document.open();

        Form form = null;
        //System.out.println("The form id is 1:"+formId);
        if (formId != null) {
            form = formDao.getFormWithFields(formId);
        }

        if (form != null) {
            if (form.getStatus() != 2) {//2-active, 3-deactive
                model.put("doneMessage", "msg.access.denied");
                model.put("doneMsgType", "failed");

                return "redirect:done.htm";
            }
            initForm(form);
        }

        List<Field> fieldList = form.getFields();

        if (fieldList.isEmpty()) {
            System.out.println("The list size is zero");
        }

        PdfPCell space;
        space = new PdfPCell();
        space.setBorder(Rectangle.NO_BORDER);
        space.setColspan(2);
        space.setFixedHeight(8);

        PdfPTable table = new PdfPTable(2);
        PdfPCell cell;

        //PdfPCell cell;                
        table.setWidths(new int[] { 1, 2 });

        int i = 0;
        for (Field f : fieldList) {
            if ("text".equals(f.getType())) {

                table.addCell(f.getLabel());
                cell = new PdfPCell();
                cell.setCellEvent(new TextFields(1, i));
                table.addCell(cell);

            } else if ("textarea".equals(f.getType())) {
                table.addCell(f.getLabel());
                cell = new PdfPCell();
                cell.setCellEvent(new TextFields(1, i));
                cell.setFixedHeight(60);
                table.addCell(cell);

            } else if ("select".equals(f.getType())) {
                table.addCell(f.getType());
                cell = new PdfPCell();
                cell.setCellEvent(new ChoiceFields(3, f.getList().toArray()));
                table.addCell(cell);
                //table.addCell(space);
                System.out.println("ajsdhd");
            }
            i++;
        }

        /*
          for(Field f : fieldList)
          {  
                
        if( "radio".equals(f.getType()) )
        {    
            System.out.println("List "+f.getList()+"  Oppt"+f.getOptions()+ "    df"+f.getColName());
                    
            writer = PdfWriter.getInstance(document, new FileOutputStream("TextFieldForm.pdf"));
                 
            //writer.addJavaScript(Utilities.readFileToString(""));
            // add the radio buttons
            PdfContentByte canvas = writer.getDirectContent();
            Font font = new Font(FontFamily.HELVETICA, 14);
            Rectangle rect;
            PdfFormField field;
            PdfFormField radiogroup = PdfFormField.createRadioButton(writer, true);
            radiogroup.setFieldName("language");
            RadioCheckField radio;
            for (int i = 0; i < 2; i++) 
            {
                rect = new Rectangle(40, 806 - i * 40, 60, 788 - i * 40);
                radio = new RadioCheckField(writer, rect, null, f.getLabel());
                radio.setBorderColor(GrayColor.GRAYBLACK);
                radio.setBackgroundColor(GrayColor.GRAYWHITE);
                radio.setCheckType(RadioCheckField.TYPE_CIRCLE);
                field = radio.getRadioField();
                radiogroup.addKid(field);
                        
                writer.addAnnotation(field);
                       
                ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                    new Phrase(f.getLabel(), font), 70, 790 - i * 40, 0);
            }
            //table.addCell(f.getLabel());
            //cell = new PdfPCell();
                    
            //document.add(radiogroup);
            //writer.addAnnotation(radiogroup);
                    
                
        }
                
          }       */

        // Add submit button   
        PushbuttonField submitBtn = new PushbuttonField(writer, new Rectangle(400, 700, 370, 670),
                "submitPOST");
        //submitBtn.setBackgroundColor(Color.GRAY);
        submitBtn.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED);
        submitBtn.setText("Submit");
        submitBtn.setOptions(PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT);
        PdfFormField submitField = submitBtn.getField();
        submitField.setAction(
                PdfAction.createSubmitForm("http://localhost:8084/GovForm-07-02/formBuilder/pdfresponse.htm",
                        null, PdfAction.SUBMIT_HTML_FORMAT));

        writer.addAnnotation(submitField);

        document.add(table);

        System.out.println("Pdf creation successful");

        document.close();

        ServletOutputStream out = response.getOutputStream();
        baos.writeTo(out);
        out.flush();

    } catch (Exception ex) {
        System.out.println("Could not print reasone::" + ex.toString());

    }

    //////////////////////////////////////// email part////////////////////////////  
    //email functionalities
    // Recipient's email ID needs to be mentioned.
    String to = "tanviranik@gmail.com";

    // Sender's email ID needs to be mentioned
    String from = "tanvir_cse@yahoo.com";

    // Assuming you are sending email from localhost
    String host = "localhost";

    // Get system properties
    Properties properties = System.getProperties();

    // Setup mail server
    properties.setProperty("mail.smtp.host", host);

    // Get the default Session object.
    Session session = Session.getDefaultInstance(properties);

    try {
        // Create a default MimeMessage object.
        MimeMessage message = new MimeMessage(session);

        // Set From: header field of the header.
        message.setFrom(new InternetAddress(from));

        // Set To: header field of the header.
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

        // Set Subject: header field
        message.setSubject("This is the Subject Line!");

        // Now set the actual message
        message.setText("This is actual message");

        // Send message
        Transport.send(message);
        System.out.println("Sent message successfully....");
    } catch (MessagingException mex) {
        mex.printStackTrace();
    }
    //////////////////////////////////////// email part////////////////////////////

    return null;

}

From source file:be.kcbj.placemat.Placemat.java

License:Open Source License

private PdfPCell generateCell(Sponsor sponsor, float cellHeight) throws IOException, BadElementException {
    int numLines = 0;
    Paragraph p = new Paragraph();

    if (sponsor.image != null) {
        Image image = Image.getInstance(SponsorManager.getImageUrl(sponsor.image));
        if (sponsor.imageWidth != 0) {
            image.scaleToFit(sponsor.imageWidth, 1000);
        } else if (sponsor.imageHeight != 0) {
            image.scaleToFit(1000, sponsor.imageHeight);
        }/* www .  jav  a  2s .com*/
        Chunk imageChunk = new Chunk(image, 0, 0, true);
        p.add(imageChunk);
    }

    if (sponsor.twoColumns) {
        StringBuilder sb = new StringBuilder();
        if (sponsor.name != null) {
            sb.append(sponsor.name);
        }
        if (sponsor.name2 != null) {
            if (sb.length() > 0) {
                sb.append(" - ");
            }
            sb.append(sponsor.name2);
        }
        if (sponsor.address != null) {
            if (sb.length() > 0) {
                sb.append(" - ");
            }
            sb.append(sponsor.address);
        }
        if (sponsor.address2 != null) {
            if (sb.length() > 0) {
                sb.append(" - ");
            }
            sb.append(sponsor.address2);
        }
        p.add(Chunk.NEWLINE);
        p.add(new Chunk(sb.toString(), new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL)));
        numLines++;
    } else {
        if (sponsor.twoRows && sponsor.image != null) {
            p.add(Chunk.NEWLINE);
        }
        if (sponsor.name != null) {
            p.add(generateFittedChunk(sponsor.name, Font.BOLD));
            numLines++;
        }
        if (sponsor.name2 != null) {
            p.add(Chunk.NEWLINE);
            p.add(generateFittedChunk(sponsor.name2, Font.BOLD));
            numLines++;
        }
        if (sponsor.address != null) {
            p.add(new Chunk("\n\n", new Font(Font.FontFamily.HELVETICA, 2, Font.NORMAL)));
            p.add(new Chunk(sponsor.address, new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
            numLines++;
        }
        if (sponsor.address2 != null) {
            p.add(Chunk.NEWLINE);
            p.add(new Chunk(sponsor.address2, new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
            numLines++;
        }
    }
    p.setPaddingTop(0);
    p.setSpacingBefore(0);
    p.setAlignment(Element.ALIGN_CENTER);
    p.setMultipliedLeading(numLines <= 3 ? 1.3f : 1.1f);

    PdfPCell cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setFixedHeight(cellHeight);
    if (sponsor.twoColumns) {
        cell.setColspan(2);
    }
    if (sponsor.twoRows) {
        cell.setRowspan(2);
        if (sponsor.image == null) {
            p.setMultipliedLeading(p.getMultipliedLeading() * 1.5f);
        }
    }
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setCellEvent(CELL_EVENT);
    cell.setPaddingBottom(4);
    cell.addElement(p);
    if (sponsor.isTodo()) {
        cell.setBackgroundColor(BaseColor.ORANGE);
    }

    return cell;
}

From source file:be.mxs.common.util.pdf.general.chuk.GeneralPDFCreator.java

protected void printSignature() {
    try {/*from w w  w  . j  a  va2  s.  co m*/
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        cell = new PdfPCell();
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(
                new Paragraph(getTran("report.monthly", "signature").toUpperCase() + "\n\n\n\n\n\n\n\n",
                        FontFactory.getFont(FontFactory.HELVETICA,
                                Math.round((double) 8 * fontSizePercentage / 100.0), Font.ITALIC)));
        cell.setColspan(1);
        cell.setBorder(PdfPCell.BOX);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
        table.addCell(cell);
        doc.add(table);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:be.rheynaerde.poolsheets.AbstractPoolSheet.java

License:Open Source License

protected void buildBoutOrder(Document document) throws DocumentException {
    PdfPTable table = new PdfPTable(configuration.getBoutOrderColumns());
    BoutOrder mo = configuration.getBoutOrder();
    if (mo.getNrOfBouts() == 0)
        return;//from w ww . ja  v  a  2  s  .c o m
    int rows = mo.getNrOfBouts() / configuration.getBoutOrderColumns();
    if (mo.getNrOfBouts() % configuration.getBoutOrderColumns() != 0)
        rows++;
    int shortComing = (rows - (mo.getNrOfBouts() % rows)) % rows;
    for (int i = 0; i < rows - shortComing; i++) {
        for (int j = 0; j < configuration.getBoutOrderColumns(); j++) {
            int boutNumber = j * rows + i;
            table.addCell(getBoutCell(mo, boutNumber));
        }
        for (int j = 0; j < configuration.getBoutOrderSpacing(); j++) {
            for (int k = 0; k < configuration.getBoutOrderColumns(); k++) {
                PdfPCell spacing = new PdfPCell();
                spacing.setBorder(Rectangle.NO_BORDER);
                spacing.setFixedHeight(configuration.getSquareCellSize());
                table.addCell(spacing);
            }
        }
    }
    for (int i = rows - shortComing; i < rows; i++) {
        for (int j = 0; j < configuration.getBoutOrderColumns() - 1; j++) {
            int boutNumber = j * rows + i;
            table.addCell(getBoutCell(mo, boutNumber));
        }
        PdfPCell cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        for (int j = 0; j < configuration.getBoutOrderSpacing(); j++) {
            for (int k = 0; k < configuration.getBoutOrderColumns(); k++) {
                PdfPCell spacing = new PdfPCell();
                spacing.setBorder(Rectangle.NO_BORDER);
                spacing.setFixedHeight(configuration.getSquareCellSize());
                table.addCell(spacing);
            }
        }
    }
    table.setSpacingBefore(20f);
    document.add(table);
}

From source file:be.rheynaerde.poolsheets.AbstractPoolSheet.java

License:Open Source License

protected PdfPCell getBoutCell(BoutOrder mo, int boutNumber) {
    PdfPCell cell = new PdfPCell();
    int firstPlayerOfBout = mo.getFirstPlayerOfBout(boutNumber);
    int secondPlayerOfBout = mo.getSecondPlayerOfBout(boutNumber);
    cell.addElement(getBout(Integer.toString(firstPlayerOfBout), Integer.toString(secondPlayerOfBout)));
    cell.setBorder(Rectangle.NO_BORDER);
    return cell;/*ww  w.  j a v  a 2  s  . com*/
}

From source file:be.rheynaerde.poolsheets.AbstractPoolSheet.java

License:Open Source License

protected PdfPCell getSolidCell() {
    if (configuration.getImage() == null) {
        PdfPCell solidCell = new PdfPCell();
        solidCell.setBackgroundColor(getSolidCellColor());
        solidCell.setFixedHeight(configuration.getSquareCellSize());
        return solidCell;
    } else {//from w w  w  .  j  a v  a2s . c  o m
        PdfPCell solidCell = new PdfPCell(configuration.getImage(), true);
        solidCell.setFixedHeight(configuration.getSquareCellSize());
        solidCell.setPadding(solidCell.getPaddingBottom() * 2);
        return solidCell;
    }
}

From source file:be.rheynaerde.poolsheets.AbstractPufPoolSheet.java

License:Open Source License

protected PdfPCell getEmptyCell() {
    PdfPCell emptyCell = new PdfPCell();
    emptyCell.setBorder(Rectangle.NO_BORDER);
    emptyCell.setFixedHeight(configuration.getSquareCellSize());
    return emptyCell;
}

From source file:be.rheynaerde.poolsheets.AbstractPufPoolSheet.java

License:Open Source License

protected PdfPCell getNameCell(String text) {
    PdfPCell nameCell = text == null ? new PdfPCell() : new PdfPCell(new Phrase(text));
    nameCell.setBorder(Rectangle.BOTTOM);
    nameCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    nameCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    nameCell.setFixedHeight(configuration.getSquareCellSize());
    return nameCell;
}