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

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

Introduction

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

Prototype

public void setWidthPercentage(float widthPercentage) 

Source Link

Document

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

Usage

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   w ww.j  a v a2  s. c  om*/
    float widthPercentage = table.getTotalWidth() / (pageSize.getRight() - pageSize.getLeft()) * 100f;
    table.setWidthPercentage(widthPercentage);
    return table;
}

From source file:jm.web.Addons.java

License:GNU General Public License

public static PdfPTable setCabeceraTabla(java.util.List titulo, float[] anchos, float ancho) {
    PdfPTable encabezado = new PdfPTable(anchos);
    encabezado.setWidthPercentage(ancho);
    encabezado.setSpacingBefore(5f);//from  w  w  w  . j a v  a 2 s.c  o  m
    java.util.Iterator it = titulo.iterator();
    while (it.hasNext()) {
        encabezado.addCell(Addons.setCeldaPDF((String) it.next(), Font.HELVETICA, 8, Font.BOLD,
                Element.ALIGN_CENTER, 1, Color.cyan)); /*  Color.CYAN  */
    }
    return encabezado;
}

From source file:lmcpointofsalessystem.PDFCustomers.java

public PdfPTable getDatas(String tblName) {
    PdfPTable headerTable = new PdfPTable(1);
    String newT = tblName.toString();
    try {/*from   w w  w.j  a v  a  2  s  .c  o m*/
        rs = s.executeQuery(
                "select C.CustomerID, C.FirstName, C.LastName, C.Address, C.ContactNumber from Customers C"); //alias lang ung "E"
        String columnExe = "";
        columnExe = "CustomerID,FirstName,LastName,Address,ContactNumber";//pdf column names
        String[] colH = columnExe.split(",");
        int colL = 0;
        colL = columnExe.split(",").length;
        headerTable = new PdfPTable(colL);

        for (int x = 0; x < colL; x++) {
            if (colH[x].toString().equals("C.CustomerID")) {
                colH[x] = "OrderNo1";
            } else if (colH[x].toString().equals("C.FirstName")) {
                colH[x] = "O.CustNo";
            } else if (colH[x].toString().equals("C.LastName")) {
                colH[x] = "OrderDate";
            } else if (colH[x].toString().equals("C.Address")) {
                colH[x] = "ItemDesc";
            } else if (colH[x].toString().equals("C.ContactNumber")) {
                colH[x] = "Unit";
            }

            PdfPCell newHeader = new PdfPCell();
            newHeader.addElement(new Paragraph(colH[x]));
            headerTable.addCell(newHeader);
        }

        //System.out.println(""+columnExe);
        rs = st.executeQuery("Select " + columnExe + " from Customers C");
        int colNums = colH.length;
        int colCount = 0;
        while (rs.next() == true) {
            for (int x = 1; x <= colL; x++) {
                colCount += 1;

                PdfPCell newCell = new PdfPCell();
                newCell.addElement(new Paragraph(rs.getString(x)));
                headerTable.setWidthPercentage(90);
                headerTable.addCell(newCell);
            }
        }

        float[] widths2 = new float[colNums];

        for (int i = 0; i < colNums; i++) {
            widths2[i] = 150;
        }
        try {
            headerTable.setWidths(widths2);
        } catch (DocumentException ex) {
            Logger.getLogger(PDFCustomers.class.getName()).log(Level.SEVERE, null, ex);
        }
    } catch (SQLException ex) {
        Logger.getLogger(PDFCustomers.class.getName()).log(Level.SEVERE, null, ex);
    }

    return headerTable;
}

From source file:lmcpointofsalessystem.PDFCustomersEmployee.java

public PdfPTable getDatas(String tblName) {
    PdfPTable headerTable = new PdfPTable(1);
    String newT = tblName.toString();
    try {//from  w w w  .ja v a  2  s.  c om
        rs = s.executeQuery(
                "select C.CustomerID, C.FirstName, C.LastName, C.Address, C.ContactNumber from Customers C"); //alias lang ung "E"
        String columnExe = "";
        columnExe = "CustomerID,FirstName,LastName,Address,ContactNumber";//pdf column names
        String[] colH = columnExe.split(",");
        int colL = 0;
        colL = columnExe.split(",").length;
        headerTable = new PdfPTable(colL);

        for (int x = 0; x < colL; x++) {
            if (colH[x].toString().equals("C.CustomerID")) {
                colH[x] = "OrderNo1";
            } else if (colH[x].toString().equals("C.FirstName")) {
                colH[x] = "O.CustNo";
            } else if (colH[x].toString().equals("C.LastName")) {
                colH[x] = "OrderDate";
            } else if (colH[x].toString().equals("C.Address")) {
                colH[x] = "ItemDesc";
            } else if (colH[x].toString().equals("C.ContactNumber")) {
                colH[x] = "Unit";
            }

            PdfPCell newHeader = new PdfPCell();
            newHeader.addElement(new Paragraph(colH[x]));
            headerTable.addCell(newHeader);
        }

        //System.out.println(""+columnExe);
        rs = st.executeQuery("Select " + columnExe + " from Customers C");
        int colNums = colH.length;
        int colCount = 0;
        while (rs.next() == true) {
            for (int x = 1; x <= colL; x++) {
                colCount += 1;

                PdfPCell newCell = new PdfPCell();
                newCell.addElement(new Paragraph(rs.getString(x)));
                headerTable.setWidthPercentage(90);
                headerTable.addCell(newCell);
            }
        }

        float[] widths2 = new float[colNums];

        for (int i = 0; i < colNums; i++) {
            widths2[i] = 150;
        }
        try {
            headerTable.setWidths(widths2);
        } catch (DocumentException ex) {
            Logger.getLogger(PDFCustomersEmployee.class.getName()).log(Level.SEVERE, null, ex);
        }
    } catch (SQLException ex) {
        Logger.getLogger(PDFCustomersEmployee.class.getName()).log(Level.SEVERE, null, ex);
    }

    return headerTable;
}

From source file:lmcpointofsalessystem.PDFOrders.java

public PdfPTable getDatas(String tblName) {
    ;/* w  w w  . j av  a2 s . com*/
    PdfPTable headerTable = new PdfPTable(1);
    String newT = tblName.toString();
    String col1 = co.tblOrder.getColumnName(0);
    String col2 = co.tblOrder.getColumnName(1);
    int nrow = co.tblModel.getRowCount();
    int ncol = co.tblModel.getColumnCount();
    Object[][] tabledata = new Object[nrow][ncol];
    for (int i = 0; i < nrow; i++) {
        for (int j = 0; j < ncol; j++) {
            tabledata[i][j] = co.tblModel.getValueAt(i, j);
        }
    }
    String columnExe = "";
    columnExe = "empID,Fname,Lname,Username,Password,Address,Contact,Type";
    String[] colH = columnExe.split(",");
    int colL = 0;
    colL = columnExe.split(",").length;
    headerTable = new PdfPTable(colL);
    for (int x = 0; x < colL; x++) {
        if (colH[x].toString().equals(col1)) {
            colH[x] = "OrderNo1";
        } else if (colH[x].toString().equals(col2)) {
            colH[x] = "O.CustNo";
        }

        PdfPCell newHeader = new PdfPCell();
        newHeader.addElement(new Paragraph(colH[x]));
        headerTable.addCell(newHeader);
    }
    int colNums = colH.length;
    int colCount = 0;
    for (int x = 1; x <= colL; x++) {
        colCount += 1;

        PdfPCell newCell = new PdfPCell();
        newCell.addElement(new Paragraph((x)));
        headerTable.setWidthPercentage(90);
        headerTable.addCell(newCell);
    }
    float[] widths2 = new float[colNums];
    for (int i = 0; i < colNums; i++) {
        widths2[i] = 150;
    }
    try {
        headerTable.setWidths(widths2);
    } catch (DocumentException ex) {
        Logger.getLogger(PDFEmployees.class.getName()).log(Level.SEVERE, null, ex);
    }

    return headerTable;
}

From source file:lt.bsprendimai.ddesk.pdf.PDFTicket.java

License:Apache License

private void writeClientInfo(Document doc) throws Exception {
    PdfPTable tb = new PdfPTable(2);
    tb.setWidthPercentage(100.0f);
    tb.setSpacingAfter(20.0f);//from   ww w. ja v a2s. c o  m

    PdfPCell cl = new PdfPCell(
            new Phrase(this.client.getName() + "\n" + this.client.getAdress(), new Font(baseArial, 10)));
    tb.addCell(cl);

    cl = new PdfPCell(new Phrase(this.we.getName() + "\n" + this.we.getAdress(), new Font(baseArial, 10)));
    tb.addCell(cl);

    doc.add(tb);

}

From source file:lt.bsprendimai.ddesk.pdf.PDFTicket.java

License:Apache License

private void writeTicketInfo(Document doc) throws Exception {
    Paragraph pg = new Paragraph("#" + tt.getUniqueId(), new Font(baseArial, 12, Font.BOLD));
    doc.add(pg);/*from ww  w  .ja  va 2s  .c  om*/

    PdfPTable tb = new PdfPTable(1);
    tb.setWidthPercentage(100.0f);
    tb.setSpacingBefore(5.0f);
    tb.setSpacingAfter(5.0f);

    PdfPCell cl = new PdfPCell(new Phrase(tt.getName(), new Font(baseArial, 10, Font.BOLD)));

    tb.addCell(cl);

    if (clientPerson != null) {
        cl = new PdfPCell(new Phrase(
                "Prane: " + clientPerson.getName() + " (Telefono Nr: " + clientPerson.getPhoneNo() + ")",
                new Font(baseArial, 10)));
        tb.addCell(cl);
    }

    cl = new PdfPCell(new Phrase("Uduoties informacija: ", new Font(baseArial, 10)));
    tb.addCell(cl);

    cl = new PdfPCell(new Phrase(tt.getDescription(), new Font(baseArial, 10)));

    tb.addCell(cl);

    doc.add(tb);
}

From source file:lt.bsprendimai.ddesk.pdf.PDFTicket.java

License:Apache License

private void writeWorkerInfo(Document doc) throws Exception {

    PdfPTable tb = new PdfPTable(2);
    tb.setWidthPercentage(100.0f);
    tb.setSpacingBefore(8.0f);//  w w w.  j  a va2s.  co  m
    tb.setSpacingAfter(8.0f);

    PdfPCell cl;

    cl = new PdfPCell(new Phrase("Atsakingas asmuo: " + me.getName(), new Font(baseArial, 10)));
    cl.setColspan(2);
    tb.addCell(cl);

    cl = new PdfPCell(new Phrase("vykdymo data: " + timeFormat(tt.getDateClosed()), new Font(baseArial, 10)));
    tb.addCell(cl);

    if (tt.getWorktime() != null) {
        cl = new PdfPCell(new Phrase("Darbo valandos:" + tt.getWorktime(), new Font(baseArial, 10)));
        tb.addCell(cl);
    } else {
        cl = new PdfPCell(new Phrase("Darbo valandos: ", new Font(baseArial, 10)));
        tb.addCell(cl);
    }

    doc.add(tb);

    tb = new PdfPTable(2);

    tb.setWidthPercentage(100.0f);
    tb.setSpacingBefore(50.0f);

    cl = new PdfPCell(new Phrase("Kliento paraas\n\n\n\n", new Font(baseArial, 10)));
    cl.setBorder(0);
    tb.addCell(cl);

    cl = new PdfPCell(new Phrase("Uduot atliks darbuotojas\n\n\n\n", new Font(baseArial, 10)));
    cl.setBorder(0);
    tb.addCell(cl);
    doc.add(tb);

}

From source file:lt.bsprendimai.ddesk.pdf.PDFTicket.java

License:Apache License

private void writeJobInfo(Document doc) throws Exception {

    Paragraph pg = new Paragraph("\nUDUOTIES ATLIKIMO INFORMACIJA", new Font(baseArial, 10, Font.BOLD));
    doc.add(pg);//from ww w.  j  a v a2  s.  c om

    PdfPTable tb = new PdfPTable(3);
    tb.setWidthPercentage(100.0f);
    tb.setSpacingBefore(5.0f);
    tb.setSpacingAfter(12.0f);
    tb.setWidths(new float[] { 6.0f, 84.0f, 10.0f });

    PdfPCell cl;

    doc.add(new Phrase("\nAtlikti darbai", new Font(baseArial, 12, Font.BOLD)));

    cl = new PdfPCell(new Phrase("Eil.nr", new Font(baseArial, 10, Font.BOLD)));
    tb.addCell(cl);
    cl = new PdfPCell(new Phrase("Uduoties pavadinimas", new Font(baseArial, 10, Font.BOLD)));
    tb.addCell(cl);
    cl = new PdfPCell(new Phrase("Valandos", new Font(baseArial, 10, Font.BOLD)));
    tb.addCell(cl);

    doc.add(tb);

}

From source file:mitm.common.pdf.MessagePDFBuilder.java

License:Open Source License

private void addReplyLink(Document document, String replyURL) throws DocumentException {
    PdfPTable replyTable = new PdfPTable(1);
    replyTable.setWidthPercentage(100f);

    replyTable.setSplitLate(false);/*  w ww  . j  a v a  2  s . c  o  m*/

    replyTable.setSpacingBefore(5f);
    replyTable.setHorizontalAlignment(Element.ALIGN_LEFT);

    Font linkFont = new Font();

    linkFont.setStyle(Font.BOLD);
    linkFont.setColor(0, 0, 255);
    linkFont.setSize(headerFontSize);

    Chunk anchor = new Chunk("Reply", linkFont);

    anchor.setAnchor(replyURL);

    Phrase phrase = new Phrase();

    phrase.add(anchor);

    PdfPCell cell = new PdfPCell(phrase);
    cell.setBorder(Rectangle.NO_BORDER);

    replyTable.addCell(cell);

    document.add(replyTable);
}