Example usage for com.lowagie.text.pdf PdfPTable setHorizontalAlignment

List of usage examples for com.lowagie.text.pdf PdfPTable setHorizontalAlignment

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPTable setHorizontalAlignment.

Prototype

public void setHorizontalAlignment(int horizontalAlignment) 

Source Link

Document

Sets the horizontal alignment of the table relative to the page.

Usage

From source file:Cotizacion.ExportarPDF.java

private static void acomodarDatosEspecificaciones(Paragraph datosNormal) throws BadElementException {
    Connection conexion = null;// w  w  w .  j a va  2 s.  c  om
    try {
        Class.forName("org.gjt.mm.mysql.Driver");
        conexion = (Connection) DriverManager.getConnection(url, login, password);
        stm = (Statement) conexion.createStatement();
        ResultSet rs = stm.executeQuery("select max(numero) as numero from todolonas.cotizacion;");

        while (rs.next()) {
            idCotiza = rs.getInt("numero");
        }

        conexion.close();
    } catch (Exception e) {
        System.out.println("error: " + e);
    }
    try {
        Class.forName("org.gjt.mm.mysql.Driver");
        conexion = (Connection) DriverManager.getConnection(url, login, password);

        stm = (Statement) conexion.createStatement();
        ResultSet rs = stm.executeQuery(
                "SELECT especificacionTrabajo FROM todolonas.cotizacion where numero = '" + idCotiza + "';");
        while (rs.next()) {
            especificacionTrabajo = rs.getString("especificacionTrabajo");
        }
        conexion.close();
    } catch (Exception e) {
        System.out.println("error: " + e);
    }
    if (especificacionTrabajo.equals("NA")) {
        System.out.println("no hay especificacion trabajo");
    } else {
        PdfPTable table2 = new PdfPTable(2);
        table2.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
        table2.addCell("Especificacin Trabajo");
        table2.addCell(especificacionTrabajo);
        table2.setWidthPercentage(70);
        table2.setHorizontalAlignment(Element.ALIGN_LEFT);
        agregarLineasEnBlanco(datosNormal, 1);
        datosNormal.add(table2);
    }
    try {
        Class.forName("org.gjt.mm.mysql.Driver");
        conexion = (Connection) DriverManager.getConnection(url, login, password);

        stm = (Statement) conexion.createStatement();

        //            System.out.println("nombre++++---->      "+nombreCliente);
        ResultSet rs = stm.executeQuery(
                "SELECT especificacionDiseno FROM todolonas.cotizacion where numero = '" + idCotiza + "';");
        while (rs.next()) {
            especificacionDiseno = rs.getString("especificacionDiseno");
        }
        conexion.close();
    } catch (Exception e) {
        System.out.println("error: " + e);
    }
    if (especificacionDiseno.equals("NA")) {
        System.out.println("no hay especificacion trabajo");
    } else {
        PdfPTable table2 = new PdfPTable(2);
        table2.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
        table2.addCell("Especificacin Diseo");
        table2.addCell(especificacionDiseno);
        table2.setWidthPercentage(70);
        table2.setHorizontalAlignment(Element.ALIGN_LEFT);
        agregarLineasEnBlanco(datosNormal, 1);
        datosNormal.add(table2);
    }
}

From source file:Cotizacion.ExportarPDF.java

private static void acomodarDatosPreciosTotales(Paragraph datosDerecha2) throws BadElementException {
    subtotal = PanelCotizacion.cajaSubtotal.getText();
    iva = PanelCotizacion.cajaIVA.getText();
    descuento = PanelCotizacion.cajaDescuento.getText();
    total = PanelCotizacion.cajaTotal.getText();

    PdfPTable table2 = new PdfPTable(2);
    table2.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
    table2.addCell("Subtotal");
    table2.addCell("$  " + subtotal);
    table2.addCell("IVA");
    table2.addCell(iva);// w  w  w .  java  2s  .co  m
    table2.addCell("Descuento");
    table2.addCell(descuento);
    table2.addCell("Total");
    table2.addCell("$  " + total);
    table2.setWidthPercentage(30);
    table2.setHorizontalAlignment(350);
    table2.setHorizontalAlignment(Element.ALIGN_RIGHT);
    agregarLineasEnBlanco(datosDerecha2, 1);
    datosDerecha2.add(table2);
}

From source file:de.jdufner.sudoku.generator.pdf.PdfPrinterImpl.java

License:Open Source License

private PdfPTable writePdfMetaTable(List<SudokuData> sudokus) throws DocumentException {
    // Tabelle fr Formatierung von 2 Sudokus nebeneinander
    PdfPTable metaTable = new PdfPTable(2);
    metaTable.getDefaultCell().setBorder(0);
    metaTable.getDefaultCell().setPadding(5);
    metaTable.setWidthPercentage(100);//from w w  w  .  j  av a  2s  .c  o m
    metaTable.setHorizontalAlignment(Element.ALIGN_CENTER);

    int cells = 0;
    for (SudokuData sudoku : sudokus) {
        metaTable.addCell(writePdfTable(sudoku));
        cells++;
    }
    final int rest = cells % 2;
    for (int i = 0; i < rest; i++) {
        metaTable.addCell("");
    }

    metaTable.setComplete(true);
    return metaTable;
}

From source file:domain.reports.menu.PDFReportMenu.java

License:LGPL

/**
 * Return a report section formatted as a table
 * @param data/*from w w w .ja v a  2 s .  c o  m*/
 * @return
 */
PdfPTable getGroupDetail(Recordset master, Recordset detail) throws Throwable {

    //cols
    PdfPTable datatable = new PdfPTable(2);

    //header
    datatable.getDefaultCell().setPadding(1);
    int headerwidths[] = { 50, 50 }; // percentage
    datatable.setWidths(headerwidths);
    datatable.setWidthPercentage(70); // percentage
    datatable.setHorizontalAlignment(Element.ALIGN_CENTER);
    datatable.getDefaultCell().setBorderWidth(1);
    datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell c = null;
    String v = "";

    //encabezados de columnas
    c = new PdfPCell(new Phrase("ITEMS DEL MEN", tblHeaderFont));
    c.setGrayFill(0.95f);
    c.setColspan(2);
    c.setHorizontalAlignment(Element.ALIGN_CENTER);
    datatable.addCell(c);

    c = new PdfPCell(new Phrase("Item del men", tblHeaderFont));
    c.setGrayFill(0.95f);
    c.setHorizontalAlignment(Element.ALIGN_CENTER);
    datatable.addCell(c);

    c = new PdfPCell(new Phrase("Servicio", tblHeaderFont));
    c.setGrayFill(0.95f);
    c.setHorizontalAlignment(Element.ALIGN_CENTER);
    datatable.addCell(c);

    while (detail.next()) {
        v = detail.getString("description");
        c = new PdfPCell(new Phrase(v, tblBodyFont));
        c.setHorizontalAlignment(Element.ALIGN_LEFT);
        datatable.addCell(c);

        v = detail.getString("path");
        c = new PdfPCell(new Phrase(v, tblBodyFont));
        c.setHorizontalAlignment(Element.ALIGN_LEFT);
        datatable.addCell(c);
    }

    datatable.setSpacingBefore(20);
    return datatable;

}

From source file:domain.reports.role.PDFReportRole.java

License:LGPL

/**
 * Return a report section formatted as a table
 * @param data/*  w w  w  .  j a va2 s  .c  o  m*/
 * @return
 */
PdfPTable getGroupDetail(Recordset master, Recordset detail) throws Throwable {

    //cols
    PdfPTable datatable = new PdfPTable(4);

    //header
    datatable.getDefaultCell().setPadding(1);
    int headerwidths[] = { 20, 20, 20, 20 }; // percentage
    datatable.setWidths(headerwidths);
    datatable.setWidthPercentage(100); // percentage
    datatable.setHorizontalAlignment(Element.ALIGN_CENTER);
    datatable.getDefaultCell().setBorderWidth(1);
    datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell c = null;
    String v = "";

    //encabezados de columnas
    c = new PdfPCell(new Phrase("USUARIOS DEL ROL", tblHeaderFont));
    c.setGrayFill(0.95f);
    c.setColspan(4);
    c.setHorizontalAlignment(Element.ALIGN_CENTER);
    datatable.addCell(c);

    c = new PdfPCell(new Phrase("Login de Usuario", tblHeaderFont));
    c.setGrayFill(0.95f);
    c.setHorizontalAlignment(Element.ALIGN_CENTER);
    datatable.addCell(c);

    c = new PdfPCell(new Phrase("Apellido", tblHeaderFont));
    c.setGrayFill(0.95f);
    c.setHorizontalAlignment(Element.ALIGN_CENTER);
    datatable.addCell(c);

    c = new PdfPCell(new Phrase("Nombre", tblHeaderFont));
    c.setGrayFill(0.95f);
    c.setHorizontalAlignment(Element.ALIGN_CENTER);
    datatable.addCell(c);

    c = new PdfPCell(new Phrase("Email", tblHeaderFont));
    c.setGrayFill(0.95f);
    c.setHorizontalAlignment(Element.ALIGN_CENTER);
    datatable.addCell(c);

    while (detail.next()) {
        v = detail.getString("userlogin");
        c = new PdfPCell(new Phrase(v, tblBodyFont));
        c.setHorizontalAlignment(Element.ALIGN_CENTER);
        datatable.addCell(c);

        v = detail.getString("lname");
        c = new PdfPCell(new Phrase(v, tblBodyFont));
        c.setHorizontalAlignment(Element.ALIGN_CENTER);
        datatable.addCell(c);

        v = detail.getString("fname");
        c = new PdfPCell(new Phrase(v, tblBodyFont));
        c.setHorizontalAlignment(Element.ALIGN_CENTER);
        datatable.addCell(c);

        v = detail.getString("email");
        c = new PdfPCell(new Phrase(v, tblBodyFont));
        c.setHorizontalAlignment(Element.ALIGN_CENTER);
        datatable.addCell(c);
    }

    datatable.setSpacingBefore(20);
    return datatable;

}

From source file:fr.opensagres.xdocreport.itext.extension.ExtendedPdfPTable.java

License:Open Source License

private PdfPTable createTable(PdfPCell cell) {
    PdfPTable table = new PdfPTable(1);
    table.setSpacingBefore(this.spacingBefore());
    table.setSpacingAfter(this.spacingAfter());
    table.setHorizontalAlignment(this.getHorizontalAlignment());
    table.setTotalWidth(cell.getPaddingLeft() + this.getTotalWidth() + cell.getPaddingRight());
    table.setLockedWidth(true);//from   w  ww.  j ava2s . co m
    table.setSplitLate(false);
    table.addCell(cell);
    return table;
}

From source file:ilarkesto.integration.itext.Table.java

License:Open Source License

@Override
public Element getITextElement() {
    float[] cellWidths = getCellWidths();
    PdfPTable t = cellWidths == null ? new PdfPTable(getColumnCount()) : new PdfPTable(cellWidths);

    t.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);

    Float width = getWidth();/* www. j a v a 2 s  .c o m*/
    if (width != null)
        t.setWidthPercentage(width);

    for (Cell cell : cells) {
        t.addCell((PdfPCell) cell.getITextElement());
    }

    return t;
}

From source file:jdbreport.model.io.pdf.itext2.PdfWriter.java

License:Apache License

private PdfPTable createPdfTable(int columnCount, float[] widths, Rectangle pageSize) throws DocumentException {
    PdfPTable table;
    table = new PdfPTable(columnCount);
    table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    table.setTotalWidth(widths);/*from  www . j ava  2s .  com*/
    float widthPercentage = table.getTotalWidth() / (pageSize.getRight() - pageSize.getLeft()) * 100f;
    table.setWidthPercentage(widthPercentage);
    return table;
}

From source file:lmcpointofsalessystem.PDFCustomers.java

public PDFCustomers(String tblName) throws IOException {
    try {/*w  w w.  j a  v  a  2 s. co  m*/
        LMCPointofSalesSystem connect = new LMCPointofSalesSystem();
        con = connect.con;
        st = connect.s;
        Document document = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);

        PdfWriter.getInstance(document, new FileOutputStream(tblName + ".pdf"));
        document.open();
        Image image = Image.getInstance("src/lmcpointofsalessystem/Assets/header3.png");
        document.add(image);
        document.setMarginMirroring(true);

        PdfPTable newheaderTable;
        newheaderTable = getDatas(tblName);
        newheaderTable.setHorizontalAlignment(Element.ALIGN_CENTER);
        document.add(newheaderTable);
        document.close();

    } catch (FileNotFoundException ex) {
        Logger.getLogger(PDFCustomers.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(PDFCustomers.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:lmcpointofsalessystem.PDFCustomersEmployee.java

public PDFCustomersEmployee(String tblName) throws IOException {
    try {// w  w w.j  a  va  2 s . c  o m
        LMCPointofSalesSystem connect = new LMCPointofSalesSystem();
        con = connect.con;
        st = connect.s;
        Document document = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);

        PdfWriter.getInstance(document, new FileOutputStream(tblName + ".pdf"));
        document.open();
        Image image = Image.getInstance("src/lmcpointofsalessystem/Assets/header3.png");
        document.add(image);
        document.setMarginMirroring(true);

        PdfPTable newheaderTable;
        newheaderTable = getDatas(tblName);
        newheaderTable.setHorizontalAlignment(Element.ALIGN_CENTER);
        document.add(newheaderTable);
        document.close();

    } catch (FileNotFoundException ex) {
        Logger.getLogger(PDFCustomersEmployee.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(PDFCustomersEmployee.class.getName()).log(Level.SEVERE, null, ex);
    }
}