Example usage for com.itextpdf.text.pdf PdfPTable setSpacingBefore

List of usage examples for com.itextpdf.text.pdf PdfPTable setSpacingBefore

Introduction

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

Prototype

public void setSpacingBefore(final float spacing) 

Source Link

Document

Sets the spacing before this table.

Usage

From source file:controller.CreateTranscript.java

private void CreateTranscript(MyPerson p) {//,PrintWriter out){
    Document document = new Document();

    String name = p.getFName() + p.getLName();

    try {/*from   w  w  w.j  a  va 2  s  .c  om*/
        if (p.getUserType() == 6) {

            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("D:\\" + name + ".pdf"));
            document.open();

            PdfPTable table = new PdfPTable(8); // 8 columns.
            table.setWidthPercentage(100); //Width 100%
            table.setSpacingBefore(10f); //Space before table
            table.setSpacingAfter(10f); //Space after table

            //Set Column widths
            float[] columnWidths = { 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f };
            table.setWidths(columnWidths);
            PdfPCell cell1 = new PdfPCell(new Paragraph("Subject Name"));
            cell1.setBorderColor(BaseColor.BLUE);
            cell1.setPaddingLeft(10);
            cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
            PdfPCell cell2 = new PdfPCell(new Paragraph("Subject Code"));
            cell2.setBorderColor(BaseColor.BLUE);
            cell2.setPaddingLeft(10);
            cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);
            PdfPCell cell3 = new PdfPCell(new Paragraph("Written Grade"));
            cell3.setBorderColor(BaseColor.BLUE);
            cell3.setPaddingLeft(10);
            cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);
            PdfPCell cell4 = new PdfPCell(new Paragraph("Midterm Grade"));
            cell4.setBorderColor(BaseColor.BLUE);
            cell4.setPaddingLeft(10);
            cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);
            PdfPCell cell5 = new PdfPCell(new Paragraph("Final Exam Grade"));
            cell5.setBorderColor(BaseColor.BLUE);
            cell5.setPaddingLeft(10);
            cell5.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell5.setVerticalAlignment(Element.ALIGN_MIDDLE);
            PdfPCell cell6 = new PdfPCell(new Paragraph("Final Grade"));
            cell6.setBorderColor(BaseColor.BLUE);
            cell6.setPaddingLeft(10);
            cell6.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell6.setVerticalAlignment(Element.ALIGN_MIDDLE);
            PdfPCell cell7 = new PdfPCell(new Paragraph("Term"));
            cell7.setBorderColor(BaseColor.BLUE);
            cell7.setPaddingLeft(10);
            cell7.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell7.setVerticalAlignment(Element.ALIGN_MIDDLE);
            PdfPCell cell8 = new PdfPCell(new Paragraph("Registration Date"));
            cell8.setBorderColor(BaseColor.BLUE);
            cell8.setPaddingLeft(10);
            cell8.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell8.setVerticalAlignment(Element.ALIGN_MIDDLE);

            table.addCell(cell1);
            table.addCell(cell2);
            table.addCell(cell3);
            table.addCell(cell4);
            table.addCell(cell5);
            table.addCell(cell6);
            table.addCell(cell7);
            table.addCell(cell8);

            ModelOfStudent modelOfStudent = new ModelOfStudent();
            ResultSet rs = modelOfStudent.ViewMyCourses(p.getCode());

            //    if(!rs.next()){out.println("<font color='blue'>There is no Courses Untill Now ^_^ </font>");}
            while (rs.next()) {

                table.addCell(rs.getString("SubjectName"));
                table.addCell(rs.getString("ID"));
                table.addCell(rs.getString("WritenGrade"));
                table.addCell(rs.getString("MidtermGrade"));
                table.addCell(rs.getString("FinalExamGrade"));
                table.addCell(rs.getString("FinalGrade"));
                table.addCell(rs.getString("Term"));
                table.addCell(rs.getString("StudentRegisterSubjectDate"));

                /* String SubjectRegisterDate=String.valueOf(rs.getDate("SubjectRegisterDate"));
                 table.addCell(SubjectRegisterDate);
                 */
            }

            //To avoid having the cell border and the content overlap, if you are having thick cell borders
            //cell1.setUserBorderPadding(true);
            //cell2.setUserBorderPadding(true);
            //cell3.setUserBorderPadding(true);
            document.add(new Paragraph("University: " + MyPerson.ReturnUniversityName(p.getCode())));
            document.add(new Paragraph("Faculity: " + MyPerson.ReturnFaculityName(p.getCode())));
            document.add(
                    new Paragraph("Student Name: " + p.getFName() + " " + p.getMName() + " " + p.getLName()));
            document.add(new Paragraph("Level: " + MyPerson.ReturnLevelName(p.getCode())));
            document.add(new Paragraph("Department: " + MyPerson.ReturnDepartmentName(p.getCode())));

            document.add(table);
            System.out.println(
                    "<script type='text/javascript' > alert('Successfull Creating Transcript ^_^ ');history.back();</script>");

            //out.println("Successfull Creating Transcript ^_^");
            document.close();
            writer.close();
        } //end of if student
    } catch (Exception e) {
        System.out.println("<script type='text/javascript' > alert('Failed Creating Transcript ^_^ Error:"
                + e.getMessage() + "  ');history.back();</script>");

        // out.println(""+e.getMessage());
        e.printStackTrace();
    }
}

From source file:cz.zcu.kiv.eegdatabase.logic.pdf.ReservationPDF.java

License:Apache License

public static PdfPTable formatReservation(Reservation reservation) {
    int padding = 5;

    GregorianCalendar created = new GregorianCalendar();
    created.setTime(reservation.getCreationTime());
    GregorianCalendar startTime = new GregorianCalendar();
    startTime.setTime(reservation.getStartTime());
    GregorianCalendar endTime = new GregorianCalendar();
    endTime.setTime(reservation.getEndTime());

    String personName = BookingRoomUtils.formatPersonName(reservation.getPerson());

    Font title = FontFactory.getFont("Trebuchet MS", "utf-8", 15, Font.BOLD, new BaseColor(59, 70, 00));
    Font header = FontFactory.getFont(FontFactory.TIMES_BOLD, 13, Font.BOLD, BaseColor.BLACK);
    Font value = FontFactory.getFont(FontFactory.TIMES, 13);

    PdfPTable table = new PdfPTable(2);
    PdfPCell cell;/*from   ww w  .  java  2  s. co  m*/
    Phrase phrase;

    phrase = new Phrase("Reservation by " + personName);
    phrase.setFont(title);
    cell = new PdfPCell(phrase);
    cell.setColspan(2);
    cell.setBorder(0);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorderWidthTop(1);
    cell.setBorderWidthLeft(1);
    cell.setBorderWidthRight(1);
    cell.setPadding(padding);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    phrase = new Phrase("Date: ");
    phrase.setFont(header);
    cell = new PdfPCell(phrase);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorder(0);
    cell.setBorderWidthLeft(1);
    cell.setPadding(padding);
    table.addCell(cell);

    phrase = new Phrase(BookingRoomUtils.getDate(startTime));
    phrase.setFont(value);
    cell = new PdfPCell(phrase);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorder(0);
    cell.setBorderWidthRight(1);
    cell.setPadding(padding);
    table.addCell(cell);

    phrase = new Phrase("Start: ");
    phrase.setFont(header);
    cell = new PdfPCell(phrase);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorder(0);
    cell.setBorderWidthLeft(1);
    cell.setPadding(padding);
    table.addCell(cell);

    phrase = new Phrase(BookingRoomUtils.getHoursAndMinutes(startTime));
    phrase.setFont(value);
    cell = new PdfPCell(phrase);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorder(0);
    cell.setBorderWidthRight(1);
    cell.setPadding(padding);
    table.addCell(cell);

    phrase = new Phrase("End: ");
    phrase.setFont(header);
    cell = new PdfPCell(phrase);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorder(0);
    cell.setBorderWidthLeft(1);
    cell.setBorderWidthBottom(1);
    cell.setPadding(padding);
    table.addCell(cell);

    phrase = new Phrase(BookingRoomUtils.getHoursAndMinutes(endTime));
    phrase.setFont(value);
    cell = new PdfPCell(phrase);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorder(0);
    cell.setBorderWidthRight(1);
    cell.setBorderWidthBottom(1);
    cell.setPadding(padding);
    table.addCell(cell);

    table.setSpacingBefore(10);
    table.setSpacingAfter(10);

    return table;
}

From source file:dbms_prj.Display.java

public void create_pdf() throws Exception {
    Document doc = new Document();
    PdfWriter.getInstance(doc, new FileOutputStream(S1 + ".pdf"));
    Image image = Image.getInstance("src/Travel partners.png");
    image.scaleAbsolute(500f, 200f);/*from w ww .  jav a 2  s  . com*/
    Image ima = Image.getInstance("src/images.jpg");
    ima.scaleAbsolute(100f, 100f);
    ima.setAlignment(Element.ALIGN_CENTER);
    PdfPTable table = new PdfPTable(9);
    PdfPCell cell = new PdfPCell(new Paragraph("Ticket"));
    cell.setColspan(9);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setPadding(10.0f);
    cell.setBackgroundColor(new BaseColor(140, 221, 8));
    table.addCell(cell);
    table.addCell("PNR");
    table.addCell("BOOK_ID");
    table.addCell("FLIGHT_NO");
    table.addCell("NAME");
    table.addCell("SOURCE");
    table.addCell("DESTINATION");
    table.addCell("STATUS");
    table.addCell("FARE");
    table.addCell("Date");
    table.addCell(S1);
    table.addCell(S11);
    table.addCell(S4);
    table.addCell(S6 + " " + S7);
    table.addCell(S8);
    table.addCell(S9);
    table.addCell(S5);
    table.addCell(S10);
    table.addCell(S12);
    table.setSpacingBefore(30.0f); // Space Before table starts, like margin-top in CSS
    table.setSpacingAfter(30.0f);
    doc.open();
    //doc.add(new Paragraph("Hello!! Yo this is my first pdf!"));
    doc.add(image);
    doc.add(new Paragraph("Ticket created on " + new Date().toString()));
    doc.add(table);
    //doc.add(list);
    doc.add(ima);
    doc.close();
}

From source file:dbms_prj.Status.java

public void create_pdf() throws Exception {
    Document doc = new Document();
    PdfWriter.getInstance(doc, new FileOutputStream(S1 + ".pdf"));
    Image image = Image.getInstance("src/Travel partners.png");
    image.scaleAbsolute(500f, 200f);//  w w w . j a va2s .  c  o  m
    Image ima = Image.getInstance("src/images.jpg");
    ima.scaleAbsolute(100f, 100f);
    ima.setAlignment(Element.ALIGN_CENTER);
    PdfPTable table = new PdfPTable(9);
    PdfPCell cell = new PdfPCell(new Paragraph("Ticket"));
    cell.setColspan(9);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setPadding(10.0f);
    table.setTotalWidth(300.0f);

    cell.setBackgroundColor(new BaseColor(140, 221, 8));
    table.addCell(cell);
    table.addCell("PNR");
    table.addCell("BOOK_ID");
    table.addCell("FLIGHT_NO");
    table.addCell("NAME");
    table.addCell("SOURCE");
    table.addCell("DESTINATION");
    table.addCell("STATUS");
    table.addCell("FARE");
    table.addCell("Date");
    table.addCell(S1);
    table.addCell(S11);
    table.addCell(S4);
    table.addCell(S6 + S7);
    table.addCell(S8);
    table.addCell(S9);
    table.addCell(S5);
    table.addCell(S10);
    table.addCell(S2);
    table.setSpacingBefore(50.0f); // Space Before table starts, like margin-top in CSS
    table.setSpacingAfter(50.0f);
    doc.open();
    //doc.add(new Paragraph("Hello!! Yo this is my first pdf!"));
    doc.add(image);
    //doc.add(new Paragraph("Ticket created on " + new Date().toString()));
    doc.add(table);
    //doc.add(list);
    doc.add(ima);
    doc.close();
}

From source file:de.fau.osr.util.matrix.MatrixTools.java

License:Open Source License

/**
 * /**/*  w ww . j a va2 s .  co  m*/
 * saves matrix to {@code path} in pdf format
 * @param matrix matrix to save
 * @param path file where matrix will be saved
 */
public static boolean SaveMatrixToPdf(RequirementsTraceabilityMatrixByImpact matrix, File path,
        String matrixTitle) {
    Document document = new Document();
    try {
        PdfWriter.getInstance(document, new FileOutputStream(path));
        document.open();
        document.addTitle(matrixTitle);

        Paragraph headerPar = new Paragraph("Traceability Matrix");
        headerPar.add(new Paragraph(" ")); //new line
        document.add(headerPar);

        java.util.List<String> reqs = matrix.getRequirements();

        //table setup
        PdfPTable table = new PdfPTable(reqs.size() + 1); //reqs + "file name" col
        table.setHeaderRows(1);
        table.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        table.setWidthPercentage(100);
        table.setSpacingBefore(0);
        table.setSpacingAfter(0);

        //file name col width/req col width 4:1
        float[] widths = new float[reqs.size() + 1];
        widths[0] = 4;
        for (int i = 0; i < reqs.size(); i++) {
            widths[i + 1] = 1;
        }
        table.setWidths(widths);

        //header row
        //add filename col to header
        addCell(table, "File name", 10, Element.ALIGN_LEFT);
        //add req cols to header
        for (String req : reqs) {
            addCell(table, "req-" + req, 8, Element.ALIGN_CENTER);
        }
        //content, row by row:
        for (int i = 0; i < matrix.getFiles().size(); i++) {
            //filename col
            String fileName = matrix.getFiles().get(i);
            addCell(table, fileName, 5, Element.ALIGN_LEFT, 18);

            //impact value cols
            for (String req : reqs) {
                RequirementFileImpactValue value = matrix
                        .getImpactValue(new RequirementFilePair(req, fileName));
                if (value == null) {
                    value = new RequirementFileImpactValue(0);
                }
                //round
                DecimalFormat df = new DecimalFormat("#.##");
                df.setRoundingMode(RoundingMode.CEILING);
                String valString = df.format(value.getImpactPercentage());

                addCell(table, valString, 10, Element.ALIGN_CENTER);
            }
        }

        document.add(table);

    } catch (DocumentException | FileNotFoundException e) {
        e.printStackTrace();
        return false;
    } finally {
        document.close();
    }
    return true;

}

From source file:documentos.PlanillaServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*w  w w . jav  a  2s .  c  o  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, SQLException {
    response.setContentType("application/pdf");
    Connection conexion = null;
    HttpSession session = request.getSession(true);
    try {
        conexion = ds.getConnection();

        edificioDAO edifDAO = new edificioDAO();
        edifDAO.setConexion(conexion);

        usuarioDAO usuDAO = new usuarioDAO();
        usuDAO.setConexion(conexion);

        //obtener variable
        boolean error = false;
        String idString = (String) request.getParameter("id_edificio");
        int idEdificio = 0;
        try {
            idEdificio = Integer.parseInt(idString);

        } catch (Exception ex) {
            System.out.println("Error al convertir variables :" + ex);
            error = true;
        }
        //obtener datos de edificio segun el id
        edificio edif = new edificio();
        edif = edifDAO.findbyIdEdificio(idEdificio);

        DetalleEdificioDAO detEdifDAO = new DetalleEdificioDAO();
        detEdifDAO.setConexion(conexion);

        administradorDAO adminDAO = new administradorDAO();
        adminDAO.setConexion(conexion);

        //obtener admin Edificio
        administrador admin = new administrador();
        admin = adminDAO.findbyIdEdificio(idEdificio);
        //obtener datos de detalleEdif
        detalleEdificio detalleEdif = new detalleEdificio();
        detalleEdif = detEdifDAO.findbyIdEdificio(idEdificio);

        //obtener datos de usuario segun id edificio
        usuario usuario = new usuario();
        usuario = usuDAO.findbyIdUsuarios(edif.getIdUsuario());
        //guardar datos de edif en variables separadas

        String nombreVendedor = usuario.getNombre();
        String apellidoVendedor = usuario.getApellido();
        int annoNorma = edif.getAnoEdificio();
        String ubicacionMed = detalleEdif.getUbicacionMedidores();
        String ciige = detalleEdif.getCiigeAnterior();
        String testDePruebas = detalleEdif.getDespiche();
        String nombreEdif = edif.getNombreEdificio();
        String correo = admin.getEmailAdmin();
        String fonoAdmin = admin.getTelefonoAdmin();
        String fonoEdif = edif.getTelefonoEdificio();
        String rutEdif = edif.getRutEdificio();
        String dirEdif = edif.getDireccionEdificio();
        String nomAdmin = admin.getNombreAdmin();
        String rutAdmin = admin.getRutAdmin();
        int cantidadDe = edif.getCantCasas() + edif.getCantDepartamentos() + edif.getCantLocales()
                + edif.getCantLavanderias();
        int cantPisos = edif.getCantPisos();
        int idEmpresaGas = edif.getIdGas();
        //determinar el nombre de la empresa de gas segun su id
        String empresagas = "";
        if (idEmpresaGas == 1) {
            empresagas = "GASVALPO";
        }
        if (idEmpresaGas == 2) {
            empresagas = "LIPIGAS";
        }
        if (idEmpresaGas == 3) {
            empresagas = "ABASTIBLE";
        }
        if (idEmpresaGas == 4) {
            empresagas = "GASCO";
        }
        if (idEmpresaGas == 5) {
            empresagas = "OTROS";
        }
        int annoEdif = edif.getAnoEdificio();
        int potencia = edif.getPotenciaReal();
        int cantidaConductos = edif.getCantConductos();
        int cantidadCalderas = edif.getCantCalderas();

        //Crear documento
        Document document = new Document();
        Image logo = Image.getInstance(getClass().getResource("logo.png"));
        PdfWriter.getInstance(document, response.getOutputStream());
        Font fuenteNegrita = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD);
        Font fuenteNormal = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL);
        Font fuenteEPiePagina = new Font(Font.FontFamily.TIMES_ROMAN, 6, Font.BOLD);
        Font fuentePiePagina = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD);

        // step 3
        document.open();

        // step 4
        logo.setAbsolutePosition(270f, 750f);
        logo.scalePercent(65f);

        PdfPTable tablaEncabezado = new PdfPTable(2);
        PdfPTable tablaContenido = new PdfPTable(2);

        tablaEncabezado.addCell(new Paragraph("PLANILLA CIIG-e INSPECCIN PERIODICA"));
        tablaEncabezado.addCell(logo);

        tablaContenido.setSpacingBefore(15);
        tablaContenido.setSpacingAfter(20);
        tablaContenido.addCell(new Paragraph("VENDEDORA", fuenteNormal));
        tablaContenido.addCell(new Paragraph(nombreVendedor + " " + apellidoVendedor, fuenteNormal));

        tablaContenido.addCell(new Paragraph("AO DEL EDIFICIO Y NORMA APLICAR", fuenteNormal));
        tablaContenido.addCell(new Paragraph(Integer.toString(annoEdif), fuenteNormal));

        tablaContenido
                .addCell(new Paragraph("UBICACIN MEDIDORES: EN LOS PISOS, FUERA DEL EDIFICO", fuenteNormal));
        tablaContenido.addCell(new Paragraph(ubicacionMed, fuenteNormal));

        tablaContenido
                .addCell(new Paragraph("NRO CIIGE DE LA INSPECCION ANTERIOR (VER PAGINA SEC)", fuenteNormal));
        tablaContenido.addCell(new Paragraph(ciige, fuenteNormal));

        tablaContenido.addCell(new Paragraph("T DE PRUEBAS, DESPICHE  OTRO (COCINA)", fuenteNormal));
        tablaContenido.addCell(new Paragraph(testDePruebas, fuenteNormal));

        tablaContenido.addCell(new Paragraph("NOMBRE: EDIFICIO, CONDOMINIO, PROPIETARIO, ETC.", fuenteNormal));
        tablaContenido.addCell(new Paragraph(nombreEdif, fuenteNormal));

        tablaContenido.addCell(new Paragraph("CORREO ELECTRONICO", fuenteNormal));
        tablaContenido.addCell(new Paragraph(correo, fuenteNormal));

        tablaContenido.addCell(new Paragraph("FONO ADMINISTRADOR /FONO EDIFICIO", fuenteNormal));
        tablaContenido.addCell(new Paragraph("Fono Administrador :" + fonoAdmin + " Fono Edificio :" + fonoEdif,
                fuenteNormal));

        tablaContenido.addCell(new Paragraph("R.U.T EDIFICIO, CONDOMINIO, PROPIETARIOS, ETC.", fuenteNormal));
        tablaContenido.addCell(new Paragraph(rutEdif, fuenteNormal));

        tablaContenido.addCell(new Paragraph("DIRECCIN  DEL EDIFICO", fuenteNormal));
        tablaContenido.addCell(new Paragraph(dirEdif, fuenteNormal));

        tablaContenido.addCell(new Paragraph("NOMBRE ADMINISTRADOR, PROPIETARIO, ETC.", fuenteNormal));
        tablaContenido.addCell(new Paragraph(nomAdmin, fuenteNormal));

        tablaContenido.addCell(new Paragraph("RUT: ADMINISTRADOR, PROPIETARIO, ETC.", fuenteNormal));
        tablaContenido.addCell(new Paragraph(rutAdmin, fuenteNormal));

        tablaContenido.addCell(new Paragraph("CANTIDAD DE: DEPTOS, CASAS, LOCALES, ETC.", fuenteNormal));
        tablaContenido.addCell(new Paragraph(Integer.toString(cantidadDe), fuenteNormal));

        tablaContenido.addCell(new Paragraph("CANTIDAD DE PISOS INMUEBLE", fuenteNormal));
        tablaContenido.addCell(new Paragraph(Integer.toString(cantPisos), fuenteNormal));

        tablaContenido.addCell(new Paragraph("EMPRESA DISTRIBUIDORA DE GAS", fuenteNormal));
        tablaContenido.addCell(new Paragraph(empresagas, fuenteNormal));

        tablaContenido.addCell(new Paragraph("CANTIDAD DE INSTALACIONES", fuenteNormal));
        tablaContenido.addCell(new Paragraph(Integer.toString(cantidadDe), fuenteNormal));

        tablaContenido.addCell(new Paragraph("TIPO DE ARTEFACTOS INSTALADOS", fuenteNormal));
        tablaContenido.addCell(new Paragraph("", fuenteNormal));

        tablaContenido.addCell(new Paragraph("POTENCIA TOTAL INSTALADA", fuenteNormal));
        tablaContenido.addCell(new Paragraph(Integer.toString(potencia), fuenteNormal));

        tablaContenido.addCell(new Paragraph("CANTIDAD DE CONDUCTOS COLECTIVOS", fuenteNormal));
        tablaContenido.addCell(new Paragraph(Integer.toString(cantidaConductos), fuenteNormal));

        tablaContenido.addCell(new Paragraph("CANTIDAD DE CALDERAS CENTRALES", fuenteNormal));
        tablaContenido.addCell(new Paragraph(Integer.toString(cantidadCalderas), fuenteNormal));

        document.add(tablaEncabezado);
        document.add(tablaContenido);
        Paragraph textoIng = new Paragraph("IngeneriaRSLimitada", fuenteEPiePagina);
        textoIng.setAlignment(Element.ALIGN_CENTER);

        Paragraph textPie = new Paragraph(
                "Calle Montaa 754 Oficina 37-A Via Del Mar / ingenieria.sr@gmail.com - Fono 032-2697175 / 92564059",
                fuentePiePagina);
        textPie.setAlignment(Element.ALIGN_CENTER);
        document.add(textoIng);
        document.add(textPie);
        document.close();
    } catch (DocumentException de) {
        throw new IOException(de.getMessage());
    }
}

From source file:eeebees.PDFGen.java

public static void main(String[] args) {

    try {//  www .ja v a  2 s .  c o m

        OutputStream file = new FileOutputStream(new File("D:\\PDF_Java4s.pdf"));
        Document document = new Document();
        PdfWriter.getInstance(document, file);

        //Inserting Image in PDF
        //Image image = Image.getInstance ("src/pdf/java4s.png");
        //image.scaleAbsolute(120f, 60f);//image width,height    

        //Inserting Table in PDF
        PdfPTable table = new PdfPTable(3);

        PdfPCell cell = new PdfPCell(new Paragraph("Java4s.com"));

        cell.setColspan(3);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setPadding(10.0f);
        cell.setBackgroundColor(new BaseColor(140, 221, 8));

        table.addCell(cell);

        table.addCell("Name");
        table.addCell("Address");
        table.addCell("Country");
        table.addCell("Java4s");
        table.addCell("NC");
        table.addCell("United States");
        table.setSpacingBefore(30.0f); // Space Before table starts, like margin-top in CSS
        table.setSpacingAfter(30.0f); // Space After table starts, like margin-Bottom in CSS                                          

        //Inserting List in PDF
        List list = new List(true, 30);
        list.add(new ListItem("Java4s"));
        list.add(new ListItem("Php4s"));
        list.add(new ListItem("Some Thing..."));

        //Text formating in PDF
        Chunk chunk = new Chunk("Welecome To Java4s Programming Blog...");
        chunk.setUnderline(+1f, -2f);//1st co-ordinate is for line width,2nd is space between
        Chunk chunk1 = new Chunk("Php4s.com");
        chunk1.setUnderline(+4f, -8f);
        chunk1.setBackground(new BaseColor(17, 46, 193));

        //Now Insert Every Thing Into PDF Document
        document.open();//PDF document opened........                   

        //document.add(image);

        document.add(Chunk.NEWLINE); //Something like in HTML :-)

        document.add(new Paragraph("Dear Java4s.com"));
        document.add(new Paragraph("Document Generated On - " + new Date().toString()));

        document.add(table);

        document.add(chunk);
        document.add(chunk1);

        document.add(Chunk.NEWLINE); //Something like in HTML :-)                                

        document.newPage(); //Opened new page
        document.add(list); //In the new page we are going to add list

        document.close();

        file.close();

        System.out.println("Pdf created successfully..");

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

From source file:es.sm2.openppm.front.utils.DocumentUtils.java

License:Open Source License

/**
 * Create PDF for Control Change//from   w  w  w.  j a v  a 2s  .com
 * @param idioma
 * @param project
 * @param change
 * @param preparedBy
 * @return
 * @throws DocumentException
 * @throws LogicException
 */
public static byte[] toPdf(ResourceBundle idioma, Project project, Changecontrol change, Employee preparedBy,
        final Image headerImg, final Image footerImg) throws DocumentException, LogicException {

    if (change == null) {
        throw new DocumentException("No change control found.");
    }

    if (preparedBy == null || preparedBy.getContact() == null) {
        throw new UserSendingException();
    }

    Document document = new Document(PageSize.A4);
    document.setMargins(70F, 70F, 38F, 38F); // Total Height: 842pt, Total Width: 595pt
    byte[] file = null;

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    @SuppressWarnings("unused")
    PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream);

    document.open();

    Font fontHeader = new Font(FontFamily.TIMES_ROMAN, 9, Font.BOLD);
    Font fontCell = new Font(FontFamily.TIMES_ROMAN, 9);
    Font tituloFont = new Font(FontFamily.TIMES_ROMAN, 16, Font.BOLD);

    document.add(new Paragraph(" ", tituloFont));
    document.add(new Paragraph(" ", tituloFont));
    document.add(new Paragraph(" ", fontHeader));
    Paragraph title = new Paragraph(idioma.getString("change_request").toUpperCase(), tituloFont);
    title.setAlignment(Paragraph.ALIGN_CENTER);
    document.add(title);

    // Header Table
    // Project info
    PdfPTable tableHeader = new PdfPTable(3);
    tableHeader.setWidthPercentage(100);
    tableHeader.setSpacingBefore(10);
    tableHeader.setSpacingAfter(15);

    int[] colWidth = new int[3];
    colWidth[0] = 40;
    colWidth[1] = 30;
    colWidth[2] = 30;
    tableHeader.setWidths(colWidth);

    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.project_name"), fontHeader, 1F, 0F, 0F, 1F));
    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.prepared_by"), fontHeader, 1F, 0F, 0F, 1F));
    tableHeader.addCell(prepareHeaderCell(idioma.getString("change_request.date"), fontHeader, 1F, 1F, 0F, 1F));

    tableHeader.addCell(prepareCell(project.getProjectName() + " / " + project.getAccountingCode(), fontCell,
            0F, 0F, 0F, 1F));
    tableHeader.addCell(prepareCell(preparedBy.getContact().getFullName(), fontCell, 0F, 0F, 0F, 1F));
    tableHeader.addCell(prepareCell(DateUtil.format(idioma, new Date()), fontCell, 0F, 1F, 0F, 1F));

    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.customer"), fontHeader, 1F, 0F, 0F, 1F));
    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.contact_name"), fontHeader, 1F, 0F, 0F, 1F));
    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.customer_type"), fontHeader, 1F, 1F, 0F, 1F));

    tableHeader.addCell(prepareCell(project.getCustomer() != null ? project.getCustomer().getName() : "",
            fontCell, 0F, 0F, 0F, 1F));
    tableHeader.addCell(prepareCell((project.getCustomer() != null ? project.getCustomer().getName() : "-"),
            fontCell, 0F, 0F, 0F, 1F));

    Customertype cusType = (project.getCustomer() != null ? project.getCustomer().getCustomertype() : null);
    tableHeader.addCell(prepareCell(cusType == null ? "" : cusType.getName(), fontCell, 0F, 1F, 0F, 1F));

    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.business_manager"), fontHeader, 1F, 0F, 0F, 1F));
    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.project_manager"), fontHeader, 1F, 0F, 0F, 1F));
    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.originator"), fontHeader, 1F, 1F, 0F, 1F));

    Employee bm = project.getEmployeeByFunctionalManager();
    Employee pm = project.getEmployeeByProjectManager();

    tableHeader.addCell(prepareCell(bm == null ? "" : bm.getContact().getFullName(), fontCell, 0F, 0F, 1F, 1F));
    tableHeader.addCell(prepareCell(pm == null ? "" : pm.getContact().getFullName(), fontCell, 0F, 0F, 1F, 1F));
    tableHeader.addCell(prepareCell(change.getOriginator(), fontCell, 0F, 1F, 1F, 1F));

    document.add(tableHeader);

    // Change Information
    document.add(new Paragraph(idioma.getString("change_information")));

    PdfPTable tableInfo = new PdfPTable(1);
    tableInfo.setWidthPercentage(100);
    tableInfo.setSpacingBefore(10);
    tableInfo.setSpacingAfter(15);

    tableInfo.addCell(prepareHeaderCell(idioma.getString("change.change_type"), fontHeader, 1F, 1F, 0F, 1F));
    tableInfo.addCell(prepareCell(change.getChangetype().getDescription(), fontCell, 0F, 1F, 0F, 1F));

    String priorityDesc = "";
    if (change.getPriority().equals('H'))
        priorityDesc = idioma.getString("change.priority.high");
    if (change.getPriority().equals('N'))
        priorityDesc = idioma.getString("change.priority.normal");
    if (change.getPriority().equals('L'))
        priorityDesc = idioma.getString("change.priority.low");

    tableInfo.addCell(prepareHeaderCell(idioma.getString("change.priority"), fontHeader, 1F, 1F, 0F, 1F));
    tableInfo.addCell(prepareCell(priorityDesc, fontCell, 0F, 1F, 0F, 1F));

    tableInfo.addCell(prepareHeaderCell(idioma.getString("change.desc"), fontHeader, 1F, 1F, 0F, 1F));
    tableInfo.addCell(prepareCell(change.getDescription(), fontCell, 0F, 1F, 0F, 1F));

    tableInfo.addCell(
            prepareHeaderCell(idioma.getString("change.recommended_solution"), fontHeader, 1F, 1F, 0F, 1F));
    tableInfo.addCell(prepareCell(change.getRecommendedSolution(), fontCell, 0F, 1F, 1F, 1F));

    PdfPTable tableSubInfo = new PdfPTable(3);
    tableSubInfo.setWidthPercentage(100);

    //TODO MIGRACION
    tableSubInfo.addCell(prepareSubCell(idioma.getString("change.wbs_node"), fontHeader));
    tableSubInfo.addCell(prepareSubCell(idioma.getString("change.estimated_effort"), fontHeader));
    tableSubInfo.addCell(prepareSubCell(idioma.getString("change.estimated_cost"), fontHeader));

    tableSubInfo.addCell(
            prepareSubCell((change.getWbsnode() != null ? change.getWbsnode().getName() : ""), fontCell));
    tableSubInfo.addCell(prepareSubCell(
            (change.getEstimatedEffort() != null ? String.valueOf(change.getEstimatedEffort()) : ""),
            fontCell));
    tableSubInfo.addCell(prepareSubCell(
            (change.getEstimatedCost() != null ? ValidateUtil.toCurrency(change.getEstimatedCost()) : ""),
            fontCell));

    PdfPCell subTable = new PdfPCell(tableSubInfo);
    subTable.setBorderWidth(1F);

    tableInfo.addCell(subTable);

    tableInfo.addCell(prepareHeaderCell(idioma.getString("change.impact_desc"), fontHeader, 1F, 1F, 0F, 1F));
    tableInfo.addCell(prepareCell(change.getImpactDescription(), fontCell, 0F, 1F, 1F, 1F));

    document.add(tableInfo);

    document.add(new Paragraph(idioma.getString("change.resolution")));

    PdfPTable tableResolution = new PdfPTable(1);
    tableResolution.setWidthPercentage(100);
    tableResolution.setSpacingBefore(10);
    tableResolution.setSpacingAfter(15);

    tableResolution
            .addCell(prepareHeaderCell(idioma.getString("change.resolution"), fontHeader, 1F, 1F, 0F, 1F));
    tableResolution.addCell(
            prepareCell((change.getResolution() != null && change.getResolution() ? idioma.getString("yes")
                    : idioma.getString("no")), fontCell, 0F, 1F, 0F, 1F));

    tableResolution
            .addCell(prepareHeaderCell(idioma.getString("change.resolution_date"), fontHeader, 1F, 1F, 0F, 1F));
    tableResolution.addCell(
            prepareCell(DateUtil.format(idioma, change.getResolutionDate()), fontCell, 0F, 1F, 0F, 1F));

    tableResolution.addCell(
            prepareHeaderCell(idioma.getString("change.resolution_reason"), fontHeader, 1F, 1F, 0F, 1F));
    tableResolution.addCell(prepareCell(change.getResolutionReason(), fontCell, 0F, 1F, 1F, 1F));

    document.add(tableResolution);

    document.close();

    try {

        PdfReader reader = new PdfReader(outputStream.toByteArray());
        PdfStamper stamper = new PdfStamper(reader, outputStream);

        int numPag = reader.getNumberOfPages();

        for (int i = 1; i <= reader.getNumberOfPages(); i++) {
            setHeaderFooter(i, numPag, headerImg, footerImg, reader, stamper, idioma);
        }

        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    file = outputStream.toByteArray();

    return file;
}

From source file:fenix.planner.pdf.PDFGenerator.java

License:Open Source License

private void createAndAddEventTable() throws DocumentException {
    PdfPTable table = new PdfPTable(new float[] { 1, 7, 1.2f });
    table.setWidthPercentage(100f);/*  w w w  . ja v  a2  s.c  o m*/
    table.getDefaultCell().setUseAscender(true);
    table.getDefaultCell().setUseDescender(true);
    table.setSpacingBefore(20);
    table.setSpacingAfter(20);

    // Header row
    table.getDefaultCell().setBorderWidthLeft(0);
    table.getDefaultCell().setBorderWidthTop(0);
    table.getDefaultCell().setBorderWidthRight(0);
    table.getDefaultCell().setPadding(5);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    table.addCell(new Phrase("Datum", headerFont));
    table.addCell(new Phrase("mne", headerFont));
    table.addCell(new Phrase("Ansvarig", headerFont));
    table.setHeaderRows(1);
    table.getDefaultCell().setBackgroundColor(null);

    // Events
    for (Event event : program.getSortedCopyOfEvents()) {
        if (event.getDate().getMonthOfYear() % 2 == 0) {
            table.getDefaultCell().setBackgroundColor(new BaseColor(0xdd, 0xdd, 0xdd));
        } else {
            table.getDefaultCell().setBackgroundColor(null);
        }

        if (!event.getType().getBackgroundColor().equals(Color.WHITE)) {
            table.getDefaultCell()
                    .setBackgroundColor(awtColorToBaseColor(event.getType().getBackgroundColor()));
        }

        final BaseColor textColor = awtColorToBaseColor(event.getType().getForegroundColor());

        PdfPCell dateCell = new PdfPCell(table.getDefaultCell());
        dateCell.addElement(
                new Phrase(event.getDate().toString("dd.MM", locale), changeColor(subjectFont, textColor)));
        table.addCell(dateCell);

        PdfPCell subjectCell = new PdfPCell(table.getDefaultCell());
        subjectCell.addElement(new Phrase(event.getSubject(), changeColor(subjectFont, textColor)));
        if (event.getDescription().length() > 0) {
            subjectCell.addElement(new Phrase(event.getDescription(), changeColor(descriptionFont, textColor)));
        }
        if (event.getOrganizer() == null) {
            subjectCell.setColspan(2);
        }
        table.addCell(subjectCell);

        if (event.getOrganizer() != null) {
            PdfPCell organizerCell = new PdfPCell(table.getDefaultCell());
            organizerCell.addElement(
                    new Phrase(event.getOrganizer().getInitials(), changeColor(subjectFont, textColor)));
            table.addCell(organizerCell);
        }
    }

    document.add(table);
}

From source file:fenix.planner.pdf.PDFGenerator.java

License:Open Source License

private void createAndAddOrganizerTable() throws DocumentException {
    PdfPTable table = new PdfPTable(new float[] { 1, 3, 4, 2 });
    table.setSpacingBefore(20);

    table.setWidthPercentage(100f);/* www  .j  a  v  a  2  s  .c o  m*/
    table.getDefaultCell().setUseAscender(true);
    table.getDefaultCell().setUseDescender(true);

    // Header row
    table.getDefaultCell().setBorder(0);
    table.getDefaultCell().setPadding(5);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    table.getDefaultCell().setBackgroundColor(null);

    for (Organizer organizer : program.getSortedCopyOfOrganizers()) {
        table.addCell(new Phrase(organizer.getInitials(), organizerFont));
        table.addCell(new Phrase(organizer.getFullName(), organizerFont));
        table.addCell(new Phrase(organizer.getEmail(), organizerFont));
        table.addCell(new Phrase(organizer.getPhoneNumber(), organizerFont));
    }

    document.add(table);
}