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

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

Introduction

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

Prototype

public void setWidthPercentage(final float widthPercentage) 

Source Link

Document

Sets the width percentage that the table will occupy in the page.

Usage

From source file:edu.uc.modulocontable.general.GenerarKardexPDF.java

private void comprobarLIFO() throws DocumentException {

    PdfPTable tablePanelInicial = new PdfPTable(1);
    tablePanelInicial.setWidthPercentage(100);
    tablePanelInicial.getDefaultCell().setBorder(0);
    tablePanelInicial.setHorizontalAlignment(2);

    PdfPCell cell = new PdfPCell(new Paragraph("Comprobacin", FontFactory.getFont("arial", 10, Font.BOLD)));
    cell.setHorizontalAlignment(2);/*from  ww  w  .j  a v  a2s.  c  om*/
    cell.setBorder(0);
    tablePanelInicial.addCell(cell);

    documento.add(espacioBlanco.getElemento());
    documento.add(espacioBlanco.getElemento());

    documento.add(tablePanelInicial);

    documento.add(espacioBlanco.getElemento());
    tablaVertical.limpiar();
    int[] alineamientos = { 0, 2 };
    int[] tamanos = { 20, 17 };
    Vector datos = new Vector();
    Vector<String> titulos = new Vector<String>();
    datos.add(0);
    titulos.add("Inv. inicial");
    datos.add(getCantidadEntrada());
    titulos.add("(+) U. entrada");
    datos.add(getCantidadSalida());
    titulos.add("(-) U. salida");
    datos.add(getSaldoCantidad());
    titulos.add("(=) Stock");

    String[] anArray = new String[titulos.size()];
    tablaVertical.setTitulos(titulos.toArray(anArray));
    tablaVertical.setContenidos(datos.toArray());
    tablaVertical.setAlineamientos(alineamientos);
    tablaVertical.llenarTabla(true);
    tablaVertical.setPosicion(2);
    tablaVertical.setAnchoTabla(42);
    tablaVertical.setTamanos(tamanos);

    documento.add(tablaVertical.getTabla());
}

From source file:edu.uc.modulocontable.general.GenerarLibroDiarioPDF.java

private void cabecera() throws DocumentException {
    Archivo a = new Archivo();
    Empresa empresa = a.obtieneContenidoArchivo().get(0);

    PdfPTable tablePanelInicial = new PdfPTable(2);
    tablePanelInicial.setWidthPercentage(100);
    tablePanelInicial.getDefaultCell().setBorder(0);

    PdfPTable tablePanelIzquierdo = new PdfPTable(1);
    tablePanelIzquierdo.setWidthPercentage(50);
    tablePanelIzquierdo.getDefaultCell().setBorder(0);

    PdfPTable tablePanelDerecho = new PdfPTable(1);
    tablePanelDerecho.setWidthPercentage(100);
    tablePanelDerecho.getDefaultCell().setBorder(0);

    titulo1.setTexto(empresa.getNombre());
    tablePanelIzquierdo.addCell(titulo1.getElemento());

    imagen.setDir("/Users/cuent/Downloads/abc-logo.jpg");
    tablePanelIzquierdo.addCell(imagen.getImage());

    tablePanelInicial.addCell(tablePanelIzquierdo);

    tablePanelDerecho.addCell(espacioBlanco.getElemento());

    titulo2.setTexto("Libro Diario");
    titulo2.getElementoRojo();/*www.j  a va  2  s . com*/
    tablePanelDerecho.addCell(titulo2.getElemento());

    tablePanelDerecho.addCell(espacioBlanco.getElemento());

    tablaVertical.limpiar();
    int[] alineamientos = { 0, 0, 0, 0 };
    Object[] datos = { empresa.getRuc(), empresa.getDireccion(), empresa.getTelefono(), "2005", "1" };
    tablaVertical.setTitulos("RUC:", "Direccin:", "Tlefono:", "Periodo", "# Diario");
    tablaVertical.setContenidos(datos);
    tablaVertical.setAlineamientos(alineamientos);
    tablaVertical.llenarTabla(false);
    tablaVertical.setPosicion(0);
    tablaVertical.setAnchoTabla(65);
    tablePanelDerecho.addCell(tablaVertical.getTabla());

    tablePanelDerecho.addCell(espacioBlanco.getElemento());

    tablePanelInicial.addCell(tablePanelDerecho);
    documento.add(tablePanelInicial);
}

From source file:edu.uc.modulocontable.general.pdf.Cabezera.java

public void addHeaderTable(Document document) throws DocumentException {
    PdfPTable tablePanelInicial = new PdfPTable(2);
    tablePanelInicial.setWidthPercentage(100);

    PdfPTable tablePanelIzquierdo = new PdfPTable(1);
    tablePanelIzquierdo.setWidthPercentage(100);
    tablePanelIzquierdo.getDefaultCell().setBorder(0);

    PdfPTable tablePanelDerecho = new PdfPTable(1);
    tablePanelDerecho.setWidthPercentage(100);
    tablePanelDerecho.getDefaultCell().setBorder(0);

    titulo2.getElementoNegro();/*from   w ww.jav a  2s. com*/
    titulo3.getElementoNegro();

    imagen.setDir("C:\\Users\\Juan Pablo\\Pictures\\emp.png");
    tablePanelIzquierdo.addCell(imagen.getImage());

    titulo2.getElementoVerde();
    titulo2.setTexto("Empresa ABC");

    tablePanelIzquierdo.addCell(titulo2.getElemento(2));

    titulo1.setTexto("RUC: " + "01059512710001");
    tablePanelDerecho.addCell(titulo1.getElemento());

    tablePanelDerecho.addCell(espacioBlanco.getElemento());

    titulo2.setTexto("FACTURA");
    titulo2.getElementoRojo();
    tablePanelDerecho.addCell(titulo2.getElemento());

    titulo2.setTexto("No.: " + cabezeraFactura.getEstablecimiento() + "-" + cabezeraFactura.getPtoEmision()
            + "-" + cabezeraFactura.getNumeroFactura());
    titulo2.getElementoRojo();
    tablePanelDerecho.addCell(titulo2.getElemento());

    tablePanelDerecho.addCell(espacioBlanco.getElemento());

    tablaVertical.limpiar(1);
    int[] tamanos2 = { 50 };
    int[] alineamientos = { 0, 0 };
    tablaVertical.setTamanos(tamanos2);
    tablaVertical.setTitulos("Nmero de Autorizacin:");
    Object[] datos10 = { cabezeraFactura.getAutorizacionSri() };
    tablaVertical.setContenidos(datos10);
    tablaVertical.setAlineamientos(alineamientos);
    tablaVertical.llenarTabla(false);
    tablaVertical.setPosicion(0);
    tablaVertical.setAnchoTabla(65);
    tablePanelDerecho.addCell(tablaVertical.getTabla());

    tablaVertical.limpiar();
    Object[] datos3 = { cabezeraFactura.getFecha().toString() };
    tablaVertical.setTitulos("Fecha y Hora de Autorizacin: ");
    tablaVertical.setContenidos(datos3);
    tablaVertical.llenarTabla(false);
    tablaVertical.setPosicion(0);
    tablaVertical.setAnchoTabla(65);
    tablePanelDerecho.addCell(tablaVertical.getTabla());

    document.add(tablePanelInicial);
    document.add(espacioBlanco.getElemento());

}

From source file:edu.uc.modulocontable.transaccion.GenerarComprobacion.java

private void cabecera() throws DocumentException {
    Archivo a = new Archivo();
    Empresa empresa = a.obtieneContenidoArchivo().get(0);

    PdfPTable tablePanelInicial = new PdfPTable(2);
    tablePanelInicial.setWidthPercentage(100);
    tablePanelInicial.getDefaultCell().setBorder(0);

    PdfPTable tablePanelIzquierdo = new PdfPTable(1);
    tablePanelIzquierdo.setWidthPercentage(50);
    tablePanelIzquierdo.getDefaultCell().setBorder(0);

    PdfPTable tablePanelDerecho = new PdfPTable(1);
    tablePanelDerecho.setWidthPercentage(100);
    tablePanelDerecho.getDefaultCell().setBorder(0);

    titulo1.setTexto(empresa.getNombre());
    tablePanelIzquierdo.addCell(titulo1.getElemento());

    imagen.setDir("/Users/cuent/Downloads/abc-log.jpg");
    tablePanelIzquierdo.addCell(imagen.getImage());

    tablePanelInicial.addCell(tablePanelIzquierdo);

    tablePanelDerecho.addCell(espacioBlanco.getElemento());

    titulo2.setTexto("BALANCE DE COMPROBACIN");
    titulo2.getElementoRojo();/*from   ww  w  . ja v  a 2s .c  om*/
    tablePanelDerecho.addCell(titulo2.getElemento());

    tablePanelDerecho.addCell(espacioBlanco.getElemento());

    tablePanelDerecho.addCell(espacioBlanco.getElemento());

    tablePanelInicial.addCell(tablePanelDerecho);
    documento.add(tablePanelInicial);
}

From source file:edu.uc.modulocontable.transaccion.GenerarComprobacion.java

private void cabeceraTabla() throws DocumentException {
    PdfPTable tablePanelInicial = new PdfPTable(5);
    tablePanelInicial.setWidthPercentage(100);
    tablePanelInicial.setWidths(new int[] { 10, 5, 5, 5, 5 });
    tablePanelInicial.getDefaultCell().setBorder(5);
    tablePanelInicial.setHorizontalAlignment(2);

    PdfPCell cell = new PdfPCell(new Paragraph("", FontFactory.getFont("arial", 10, Font.BOLD)));
    cell.setHorizontalAlignment(1);//from   w  w  w . j  av  a 2s .co m
    cell.setBorder(0);
    tablePanelInicial.addCell(cell);

    cell = new PdfPCell(new Paragraph("Suma", FontFactory.getFont("arial", 10, Font.BOLD)));
    cell.setHorizontalAlignment(1);
    tablePanelInicial.addCell(cell);

    cell = new PdfPCell(new Paragraph("Saldos", FontFactory.getFont("arial", 10, Font.BOLD)));
    cell.setHorizontalAlignment(1);
    tablePanelInicial.addCell(cell);

    documento.add(tablePanelInicial);
}

From source file:edu.uc.modulocontable.transaccion.GenerarGeneral.java

private void cabecera() throws DocumentException {
    Archivo a = new Archivo();
    Empresa empresa = a.obtieneContenidoArchivo().get(0);

    PdfPTable tablePanelInicial = new PdfPTable(2);
    tablePanelInicial.setWidthPercentage(100);
    tablePanelInicial.getDefaultCell().setBorder(0);

    PdfPTable tablePanelIzquierdo = new PdfPTable(1);
    tablePanelIzquierdo.setWidthPercentage(50);
    tablePanelIzquierdo.getDefaultCell().setBorder(0);

    PdfPTable tablePanelDerecho = new PdfPTable(1);
    tablePanelDerecho.setWidthPercentage(100);
    tablePanelDerecho.getDefaultCell().setBorder(0);

    titulo1.setTexto(empresa.getNombre());
    tablePanelIzquierdo.addCell(titulo1.getElemento());

    imagen.setDir("/Users/cuent/Downloads/abc-log.jpg");
    tablePanelIzquierdo.addCell(imagen.getImage());

    tablePanelInicial.addCell(tablePanelIzquierdo);

    tablePanelDerecho.addCell(espacioBlanco.getElemento());

    titulo2.setTexto("BALANCE GENERAL");
    titulo2.getElementoRojo();//  w  ww  . ja v  a  2  s . c om
    tablePanelDerecho.addCell(titulo2.getElemento());

    tablePanelDerecho.addCell(espacioBlanco.getElemento());

    tablePanelDerecho.addCell(espacioBlanco.getElemento());

    tablePanelInicial.addCell(tablePanelDerecho);
    documento.add(tablePanelInicial);
}

From source file:edu.uc.modulocontable.transaccion.GenerarLibroDiario.java

private void cabecera() throws DocumentException {
    Archivo a = new Archivo();
    Empresa empresa = a.obtieneContenidoArchivo().get(0);

    PdfPTable tablePanelInicial = new PdfPTable(2);
    tablePanelInicial.setWidthPercentage(100);
    tablePanelInicial.getDefaultCell().setBorder(0);

    PdfPTable tablePanelIzquierdo = new PdfPTable(1);
    tablePanelIzquierdo.setWidthPercentage(50);
    tablePanelIzquierdo.getDefaultCell().setBorder(0);

    PdfPTable tablePanelDerecho = new PdfPTable(1);
    tablePanelDerecho.setWidthPercentage(100);
    tablePanelDerecho.getDefaultCell().setBorder(0);

    titulo1.setTexto(empresa.getNombre());
    tablePanelIzquierdo.addCell(titulo1.getElemento());

    imagen.setDir("/Users/cuent/Downloads/abc-log.jpg");
    tablePanelIzquierdo.addCell(imagen.getImage());

    tablePanelInicial.addCell(tablePanelIzquierdo);

    tablePanelDerecho.addCell(espacioBlanco.getElemento());

    titulo2.setTexto("LIBRO DIARIO");
    titulo2.getElementoRojo();/*from ww w  . jav a2  s .  co  m*/
    tablePanelDerecho.addCell(titulo2.getElemento());

    tablePanelDerecho.addCell(espacioBlanco.getElemento());

    tablePanelDerecho.addCell(espacioBlanco.getElemento());

    tablePanelInicial.addCell(tablePanelDerecho);
    documento.add(tablePanelInicial);
}

From source file:edu.uc.modulocontable.transaccion.GenerarLibroMayor.java

private void cabecera() throws DocumentException {
    Archivo a = new Archivo();
    Empresa empresa = a.obtieneContenidoArchivo().get(0);

    PdfPTable tablePanelInicial = new PdfPTable(2);
    tablePanelInicial.setWidthPercentage(100);
    tablePanelInicial.getDefaultCell().setBorder(0);

    PdfPTable tablePanelIzquierdo = new PdfPTable(1);
    tablePanelIzquierdo.setWidthPercentage(50);
    tablePanelIzquierdo.getDefaultCell().setBorder(0);

    PdfPTable tablePanelDerecho = new PdfPTable(1);
    tablePanelDerecho.setWidthPercentage(100);
    tablePanelDerecho.getDefaultCell().setBorder(0);

    titulo1.setTexto(empresa.getNombre());
    tablePanelIzquierdo.addCell(titulo1.getElemento());

    imagen.setDir("/Users/cuent/Downloads/abc-log.jpg");
    tablePanelIzquierdo.addCell(imagen.getImage());

    tablePanelInicial.addCell(tablePanelIzquierdo);

    tablePanelDerecho.addCell(espacioBlanco.getElemento());

    titulo2.setTexto("LIBRO MAYOR");
    titulo2.getElementoRojo();//from w  w  w  . j  a v  a2s.  co m
    tablePanelDerecho.addCell(titulo2.getElemento());

    tablePanelDerecho.addCell(espacioBlanco.getElemento());

    tablePanelDerecho.addCell(espacioBlanco.getElemento());

    tablePanelInicial.addCell(tablePanelDerecho);
    documento.add(tablePanelInicial);
}

From source file:edu.uc.modulocontable.transaccion.GenerarResultados.java

private void cabecera() throws DocumentException {
    Archivo a = new Archivo();
    Empresa empresa = a.obtieneContenidoArchivo().get(0);

    PdfPTable tablePanelInicial = new PdfPTable(2);
    tablePanelInicial.setWidthPercentage(100);
    tablePanelInicial.getDefaultCell().setBorder(0);

    PdfPTable tablePanelIzquierdo = new PdfPTable(1);
    tablePanelIzquierdo.setWidthPercentage(50);
    tablePanelIzquierdo.getDefaultCell().setBorder(0);

    PdfPTable tablePanelDerecho = new PdfPTable(1);
    tablePanelDerecho.setWidthPercentage(100);
    tablePanelDerecho.getDefaultCell().setBorder(0);

    titulo1.setTexto(empresa.getNombre());
    tablePanelIzquierdo.addCell(titulo1.getElemento());

    imagen.setDir("/Users/cuent/Downloads/abc-log.jpg");
    tablePanelIzquierdo.addCell(imagen.getImage());

    tablePanelInicial.addCell(tablePanelIzquierdo);

    tablePanelDerecho.addCell(espacioBlanco.getElemento());

    titulo2.setTexto("ESTADO DE RESULTADOS");
    titulo2.getElementoRojo();//from  w ww .ja  va  2  s. co  m
    tablePanelDerecho.addCell(titulo2.getElemento());

    tablePanelDerecho.addCell(espacioBlanco.getElemento());

    tablePanelDerecho.addCell(espacioBlanco.getElemento());

    tablePanelInicial.addCell(tablePanelDerecho);
    documento.add(tablePanelInicial);
}

From source file:employee.payroll.system.MainMenu.java

private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
    JFileChooser dialog = new JFileChooser();
    dialog.setSelectedFile(new File("Employees Report.pdf"));
    int dialogResult = dialog.showSaveDialog(null);
    if (dialogResult == JFileChooser.APPROVE_OPTION) {
        String filePath = dialog.getSelectedFile().getPath();

        try {//w  w  w .j a  v a2 s  .c  o m
            // TODO add your handling code here:

            String sql = "select * from Staff_information";

            pst = conn.prepareStatement(sql);
            rs = pst.executeQuery();

            Document myDocument = new Document();
            PdfWriter myWriter = PdfWriter.getInstance(myDocument, new FileOutputStream(filePath));
            PdfPTable table = new PdfPTable(13);
            myDocument.open();

            float[] columnWidths = new float[] { 3, 8, 7, 5, 5, 9, 8, 9, 6, 6, 6, 8, 8 };
            table.setWidths(columnWidths);

            table.setWidthPercentage(100); //set table width to 100%

            myDocument.add(new Paragraph("Employees List",
                    FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD)));
            myDocument.add(new Paragraph(new Date().toString()));
            myDocument.add(new Paragraph(
                    "-------------------------------------------------------------------------------------------"));
            table.addCell(new PdfPCell(
                    new Paragraph("ID", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("First Name", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Surname", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(new Paragraph("Date of Birth",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Email", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Telephone", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Address", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Department", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Gender", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Salary", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Status", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Date Hired", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Job Title", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));

            while (rs.next()) {

                table.addCell(new PdfPCell(new Paragraph(rs.getString(1),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(2),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(3),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(4),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(5),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(6),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(7),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(8),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(10),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(11),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(16),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(17),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(18),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));

            }

            myDocument.add(table);
            myDocument.add(new Paragraph(
                    "--------------------------------------------------------------------------------------------"));
            myDocument.close();
            JOptionPane.showMessageDialog(null, "Report was successfully generated");

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);

        } finally {

            try {
                rs.close();
                pst.close();

            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);

            }
        }
    }

}