cl.a2r.wsmicampov2.pdf.CellHelper.java Source code

Java tutorial

Introduction

Here is the source code for cl.a2r.wsmicampov2.pdf.CellHelper.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cl.a2r.wsmicampov2.pdf;

import com.itextpdf.io.font.FontConstants;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.layout.border.Border;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Text;
import com.itextpdf.layout.property.TextAlignment;

/**
 *
 * @author Elaine
 */
public class CellHelper {

    public static Cell getCellObservaciones(String text, TextAlignment alignment) {
        Cell cell = new Cell().add(new Paragraph(text));
        cell.setPadding(0);
        cell.setTextAlignment(alignment);
        cell.setHeight(130);

        return cell;
    }

    public static Cell getCellFirma(String text, TextAlignment alignment) {
        Cell cell = new Cell().add(new Paragraph(text));
        cell.setPadding(0);
        cell.setTextAlignment(alignment);
        cell.setHeight(100);
        cell.setBorder(Border.NO_BORDER);
        cell.setBold();

        ILineDash solid = new Solid();
        cell.setNextRenderer(new CustomBorder3Renderer(cell, new ILineDash[] { solid, null, null, null }));

        return cell;
    }

    public static Cell getCell(String text, TextAlignment alignment) {
        Cell cell = new Cell().add(new Paragraph(text));
        cell.setPadding(0);
        cell.setTextAlignment(alignment);
        cell.setBorder(Border.NO_BORDER);
        return cell;
    }

    public static Cell getCell(String text1, String text2, TextAlignment alignment) {

        try {
            PdfFont bold = PdfFontFactory.createFont(FontConstants.HELVETICA_BOLD);
            Text tx1 = new Text(text1).setFont(bold);

            Text tx2 = new Text(text2);
            Paragraph p = new Paragraph().add(tx1).add(tx2);

            Cell cell = new Cell().add(p);

            cell.setPadding(0);
            cell.setTextAlignment(alignment);
            cell.setBorder(Border.NO_BORDER);
            return cell;
        } catch (Exception ex) {

        }
        return null;

    }

    public static Cell getCellDiios(String text, TextAlignment alignment) {
        Cell cell = new Cell().add(new Paragraph(text));
        cell.setPadding(0);
        cell.setTextAlignment(alignment);
        cell.setHeight(20);
        cell.setBorder(Border.NO_BORDER);

        return cell;
    }

    public static Paragraph getBoldParagraph(String text1, String text2) {
        try {

            PdfFont bold = PdfFontFactory.createFont(FontConstants.HELVETICA_BOLD);
            Text tx1 = new Text(text1).setFont(bold);

            Text tx2 = new Text(text2);
            Paragraph p = new Paragraph().add(tx1).add(tx2);
            return p;

        } catch (Exception ex) {

        }
        return new Paragraph();
    }

}