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

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

Introduction

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

Prototype

public void setFixedHeight(float fixedHeight) 

Source Link

Document

Set a fixed height for the cell.

Usage

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 av a2s  .c  o m

    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//from w ww .  j  a va  2s .  com
    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);
        }//  w ww .  jav  a2  s  . c o  m
        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.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;/*  w  w  w .j a v  a2  s . c om*/
    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 PdfPTable getBout(String player1, String player2) {
    PdfPTable table = new PdfPTable(2);
    table.setTotalWidth(configuration.getSquareCellSize() * 2);
    PdfPCell player1Name = new PdfPCell(new Phrase(player1));
    player1Name.setBorder(Rectangle.BOTTOM);
    player1Name.setHorizontalAlignment(Element.ALIGN_CENTER);
    player1Name.setFixedHeight(configuration.getSquareCellSize());
    PdfPCell player2Name = new PdfPCell(new Phrase(player2));
    player2Name.setBorder(Rectangle.BOTTOM);
    player2Name.setHorizontalAlignment(Element.ALIGN_CENTER);
    player2Name.setFixedHeight(configuration.getSquareCellSize());
    PdfPCell player1Score = new PdfPCell(new Phrase(" "));
    player1Score.setBorder(Rectangle.RIGHT);
    player1Score.setFixedHeight(configuration.getSquareCellSize());
    PdfPCell player2Score = new PdfPCell(new Phrase(" "));
    player2Score.setBorder(Rectangle.LEFT);
    player2Score.setFixedHeight(configuration.getSquareCellSize());
    table.addCell(player1Name);//w w  w. j a va  2s.  com
    table.addCell(player2Name);
    table.addCell(player1Score);
    table.addCell(player2Score);
    table.setSpacingBefore(10);
    return table;
}

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

License:Open Source License

protected PdfPCell getHeaderCell(String text) {
    PdfPCell headerCell = new PdfPCell(new Phrase(text, configuration.getHeaderFont()));
    headerCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    headerCell.setFixedHeight(configuration.getSquareCellSize());
    return headerCell;
}

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 ww. j av  a 2s  . c om
        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

@Override
protected void buildTable(Document document) throws DocumentException {
    //large table to take care of the layout
    PdfPTable largeTable = new PdfPTable(3);
    largeTable.setWidths(new int[] { 19, 1, 20 });
    final float largeTableHeight = configuration.getSquareCellSize() * (getNumberOfRows() + 1);
    PdfPCell cell1 = getEmptyCell();
    cell1.setFixedHeight(largeTableHeight);
    cell1.addElement(getNameTable());//  w w  w  . j a  v a 2  s  .  com
    largeTable.addCell(cell1);
    PdfPCell cellSpacer = getEmptyCell();
    cellSpacer.setFixedHeight(largeTableHeight);
    largeTable.addCell(cellSpacer);
    PdfPCell cell2 = getEmptyCell();
    cell2.setFixedHeight(largeTableHeight);
    cell2.addElement(getScoreTable());
    largeTable.addCell(cell2);
    document.add(largeTable);
}

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;
}