Example usage for com.itextpdf.text.pdf PdfPCell setPadding

List of usage examples for com.itextpdf.text.pdf PdfPCell setPadding

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPCell setPadding.

Prototype

public void setPadding(float padding) 

Source Link

Document

Sets the padding of the contents in the cell (space between content and border).

Usage

From source file:org.sakaiproject.attendance.export.PDFEventExporterImpl.java

License:Educational Community License

private PdfPTable attendanceSheetTable() {

    List<AttendanceStatus> activeStatuses = attendanceLogic.getActiveStatusesForSite(event.getAttendanceSite());
    int colSpan = activeStatuses.size() - 1;

    if (colSpan <= 0) {
        colSpan = 1;//from   w  w w  .ja  v  a 2 s  . c  o m
    }

    PdfPTable table = new PdfPTable(colSpan * 2);
    table.setWidthPercentage(100);
    table.setSpacingBefore(12);

    PdfPCell nameHeader = new PdfPCell(new Paragraph("Student Name", tableHeader));
    nameHeader.setPadding(10);
    nameHeader.setColspan(colSpan);
    table.addCell(nameHeader);

    int numStatusHeaders = 0;
    for (AttendanceStatus status : activeStatuses) {
        if (status.getStatus() != Status.UNKNOWN) {
            Paragraph statusHeaderParagraph = new Paragraph(getStatusString(status.getStatus(), colSpan),
                    tableHeader);
            statusHeaderParagraph.setAlignment(Element.ALIGN_CENTER);
            PdfPCell statusHeader = new PdfPCell(statusHeaderParagraph);
            statusHeader.setPadding(10);
            table.addCell(statusHeader);
            numStatusHeaders++;
        }
    }
    if (numStatusHeaders == 0) {
        Paragraph statusHeaderParagraph = new Paragraph("Status", tableHeader);
        statusHeaderParagraph.setAlignment(Element.ALIGN_CENTER);
        PdfPCell statusHeader = new PdfPCell(statusHeaderParagraph);
        statusHeader.setPadding(10);
        table.addCell(statusHeader);
    }

    Collections.sort(users, new SortNameUserComparator());

    for (User user : users) {

        PdfPCell userCell = new PdfPCell(
                new Paragraph(user.getSortName() + " (" + user.getDisplayId() + ")", body));
        userCell.setPadding(10);
        userCell.setColspan(colSpan);

        table.addCell(userCell);

        for (int i = 0; i < colSpan; i++) {
            // Add blank cell
            table.addCell(new PdfPCell(new Paragraph()));
        }

    }

    return table;
}

From source file:PDF.PDFTrackGenerator.java

License:Open Source License

/**
 * Metda generateTrackPDFA4 sli na samotn vygenerovanie PDF dokumentu trasy na formt A4.
 * @param lineWeight - hrbka ?iary trasy na mape
 * @param color - farba ?iary trasy na mape
 * @param width - rka mapy/*  w w w. j  a  v  a2  s .  co  m*/
 * @param height - vka mapy
 * @param scale - klovacia kontanta mapy (n x rozlenie mapy)
 * @param startDate - dtum a ?as prvho bodu trasy
 * @param endDate - dtum a ?as poslednho bodu trasy
 * @param activity - aktivita trasy
 * @param user - pouvate (majite) trasy
 */
public void generateTrackPDFA4(int lineWeight, String color, int width, int height, int scale, String startDate,
        String endDate, String activity, String user) {
    try {
        Document doc = new Document();
        PdfWriter.getInstance(doc, new FileOutputStream(path + fileName + ".pdf"));
        doc.open();

        Font nadpisFont = new Font(Font.FontFamily.HELVETICA, 25, Font.BOLD);

        Font detailyFont = new Font(Font.FontFamily.HELVETICA, 9, Font.NORMAL);

        Paragraph nadpisPar = new Paragraph();

        nadpisPar.setAlignment(Element.ALIGN_CENTER);

        Phrase nadpis = new Phrase(fileName, nadpisFont);

        nadpisPar.add(nadpis);

        nadpisPar.add("");

        doc.add(nadpisPar);
        doc.add(Chunk.NEWLINE);

        PdfPTable tabulka = new PdfPTable(2);
        tabulka.setWidthPercentage(100);
        float[] columnWidth = { 6f, 4f };
        tabulka.setWidths(columnWidth);

        StaticMapResolver res = new StaticMapResolver(loader);

        String mapUrl = res.getStaticMapTrackURLWithMultimedia(lineWeight, color, width, height, scale);

        Image img = Image.getInstance(new URL(mapUrl));
        //img.scalePercent(50);
        PdfPCell riadokSObr = new PdfPCell(img, true);
        riadokSObr.setBorder(Rectangle.NO_BORDER);
        riadokSObr.setPaddingBottom(10f);
        PdfPCell riadokSText = new PdfPCell(new Phrase("Description: " + loader.getTrackDescription()
                + "\n\n\nTrack activity: " + activity.substring(4) + "\n\n\nStart place: "
                + loader.getStartAddress() + "\n\n\nEnd Place: " + loader.getEndAddress()
                + "\n\n\nTrack length: " + loader.getLength() + " km\n\n\nMin elevation: "
                + loader.getMinElevation() + " m\n\n\nMax elevation: " + loader.getMaxElevation()
                + " m\n\n\nHeight difference: " + loader.getHeightDiff() + " m\n\n\nStart: " + startDate
                + "\n\n\nEnd: " + endDate + "\n\n\nDuration: " + loader.getDuration(), detailyFont));
        riadokSText.setBorder(Rectangle.NO_BORDER);
        riadokSText.setPaddingLeft(20f);
        riadokSText.setPaddingTop(5f);
        riadokSText.setPaddingBottom(10f);
        tabulka.addCell(riadokSObr);
        tabulka.addCell(riadokSText);

        doc.add(tabulka);
        //doc.add(new Phrase("\n", detailyFont));

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

        ArrayList<String> goodFiles = new ArrayList<String>();
        for (int i = 0; i < loader.getMultimediaFiles().size(); i++) {
            if (!loader.getMultimediaFiles().get(i).getPath().startsWith("YTB")) {
                String extension = loader.getMultimediaFiles().get(i).getPath().substring(
                        loader.getMultimediaFiles().get(i).getPath().lastIndexOf("."),
                        loader.getMultimediaFiles().get(i).getPath().length());
                String newPath = loader.getMultimediaFiles().get(i).getPath().substring(0,
                        loader.getMultimediaFiles().get(i).getPath().lastIndexOf(".")) + "_THUMB" + extension;
                goodFiles.add(newPath);
            }
        }

        if (!goodFiles.isEmpty()) {
            int freeCount = 9;
            if (goodFiles.size() <= 9) {
                for (int i = 0; i < goodFiles.size(); i++) {
                    Image tempImg = Image.getInstance(goodFiles.get(i));
                    tempImg.scalePercent(10f);
                    PdfPCell tempCell = new PdfPCell(tempImg, true);
                    tempCell.setPadding(3f);
                    //tempCell.setPaddingTop(5f);
                    tempCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                    tempCell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tempCell.setFixedHeight(130f);
                    tempCell.setBackgroundColor(BaseColor.BLACK);
                    tempCell.setBorderColor(BaseColor.WHITE);
                    tempCell.setBorderWidth(4f);
                    //tempCell.setBorder(Rectangle.NO_BORDER);
                    obrTabulka.addCell(tempCell);
                }
                for (int i = 0; i < 9 - goodFiles.size(); i++) {
                    PdfPCell tempCell = new PdfPCell();
                    tempCell.setBorder(Rectangle.NO_BORDER);
                    obrTabulka.addCell(tempCell);
                }
            } else if (goodFiles.size() <= 18) {
                for (int i = 0; i < 9; i++) {
                    Image tempImg = Image.getInstance(goodFiles.get(i));
                    tempImg.scalePercent(10f);
                    PdfPCell tempCell = new PdfPCell(tempImg, true);
                    tempCell.setPadding(3f);
                    //tempCell.setPaddingTop(5f);
                    tempCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                    tempCell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tempCell.setFixedHeight(130f);
                    tempCell.setBackgroundColor(BaseColor.BLACK);
                    tempCell.setBorderColor(BaseColor.WHITE);
                    tempCell.setBorderWidth(4f);
                    //tempCell.setBorder(Rectangle.NO_BORDER);
                    obrTabulka.addCell(tempCell);
                }
            } else {
                for (int i = 0; i < (goodFiles.size() % 9); i++) {
                    goodFiles.remove(goodFiles.size() - 1 - i);
                }

                int counting = (goodFiles.size() / 9);

                for (int i = 0; i < goodFiles.size(); i = i + counting) {
                    Image tempImg = Image.getInstance(goodFiles.get(i));
                    tempImg.scalePercent(10f);
                    PdfPCell tempCell = new PdfPCell(tempImg, true);
                    tempCell.setPadding(3f);
                    //tempCell.setPaddingTop(5f);
                    tempCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                    tempCell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tempCell.setFixedHeight(130f);
                    tempCell.setBackgroundColor(BaseColor.BLACK);
                    tempCell.setBorderColor(BaseColor.WHITE);
                    tempCell.setBorderWidth(4f);
                    //tempCell.setBorder(Rectangle.NO_BORDER);
                    obrTabulka.addCell(tempCell);
                    freeCount--;
                }
                for (int i = 0; i < freeCount; i++) {
                    PdfPCell tempCell = new PdfPCell();
                    tempCell.setBorder(Rectangle.NO_BORDER);
                    obrTabulka.addCell(tempCell);
                }
            }
        }

        doc.add(obrTabulka);

        Font lastFont = new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC);
        Phrase lastText = new Phrase("This PDF document was generated by gTrax app for user " + user, lastFont);
        doc.add(lastText);

        doc.close();
    } catch (Exception ex) {
        FileLogger.getInstance()
                .createNewLog("ERROR: Cannot CREATE PDF for track " + fileName + " for user " + user + " !!!");
        System.out.println("pruser");
    }

}

From source file:pipe.PdfMaker.java

/**
 * Builds and returns the main table.//from   w w  w .  j ava  2  s. c  o  m
 * 
 * @return
 */
Element mainElement(ArrayList values) throws BadElementException {

    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100f);
    table.getDefaultCell().setBorderWidth(0.5f);

    Element element;
    PdfPCell cell;
    element = this.firstElement((String) values.get(0));
    cell = this.createCell(1, 1);
    cell.setBorder(15);
    cell.setPadding(2f);
    cell.addElement(element);
    table.addCell(cell);
    String dirString = "pictures" + File.separator + (String) values.get(0) + "_" + (String) values.get(1) + "_"
            + (String) values.get(2) + File.separator + "01.jpg";
    element = this.fourthLogoElement(dirString);
    // You need to pass the image to the constructor.
    // If you add the image, it will be stretched to fill the cell.
    cell = new PdfPCell((Image) element);
    cell.setPadding(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_CENTER);
    cell.setBorderWidth(0.3f);
    cell.setRowspan(4);
    table.addCell(cell);

    element = this.thirdElement((String) values.get(1), (String) values.get(2));
    cell = this.createCell(1, 1);
    cell.addElement(element);
    table.addCell(cell);

    element = this.fifthElement((String) values.get(3), (String) values.get(4), (String) values.get(5));
    cell = this.createCell(1, 1);
    cell.addElement(element);
    table.addCell(cell);

    element = this.sixthElement((String) values.get(6), (String) values.get(7));
    cell = this.createCell(1, 1);
    cell.addElement(element);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    element = this.seventhElement((String) values.get(8), (String) values.get(9));
    cell = this.createCell(1, 1);
    cell.addElement(element);
    table.addCell(cell);

    element = this.eightthElement((String) values.get(10), (String) values.get(11));
    cell = this.createCell(2, 1);
    cell.setBorderWidth(0.3f);
    cell.addElement(element);
    table.addCell(cell);

    element = this.ninethElement((String) values.get(12), (String) values.get(13), (String) values.get(14));
    cell = this.createCell(1, 1);
    cell.setBorderWidth(0.3f);
    cell.addElement(element);
    table.addCell(cell);

    element = this.tenthElement((String) values.get(15), (String) values.get(16), (String) values.get(17));
    cell = this.createCell(1, 1);
    cell.setBorderWidth(0.3f);
    cell.addElement(element);
    table.addCell(cell);

    element = this.eleventhElement((String) values.get(18), (String) values.get(19), (String) values.get(20));
    cell = this.createCell(1, 1);
    cell.setBorderWidth(0.3f);
    cell.addElement(element);
    table.addCell(cell);

    element = this.twelvethElement((String) values.get(21), (String) values.get(22), (String) values.get(23));
    cell = this.createCell(1, 1);
    cell.setBorderWidth(0.3f);
    cell.addElement(element);
    table.addCell(cell);

    element = this.thirteenthElement((String) values.get(24), (String) values.get(25));
    cell = this.createCell(1, 1);
    cell.setBorderWidth(0.3f);
    cell.addElement(element);
    table.addCell(cell);

    element = this.fourteenthElement((String) values.get(26), (String) values.get(27));
    cell = this.createCell(1, 1);
    cell.setBorderWidth(0.3f);
    cell.addElement(element);
    table.addCell(cell);

    element = this.fifteenthElement((String) values.get(28));
    cell = this.createCell(2, 1);
    cell.setBorderWidth(0.3f);
    cell.addElement(element);
    table.addCell(cell);

    return table;
}

From source file:pipe.PdfMaker.java

/**
 * Creates new cells/* w ww. jav  a 2  s .  co m*/
 * 
 * @param colspan
 * @param rowspan
 * @return
 */
private PdfPCell createCell(int colspan, int rowspan) {
    PdfPCell cell = new PdfPCell();
    cell.setPadding(0);
    cell.setBorderWidth(0.3f);
    cell.setColspan(colspan);
    cell.setRowspan(rowspan);
    return cell;
}

From source file:pipe.PdfMaker.java

private Element thirdElement(String hersteller, String modell) {
    float leading = 9f;
    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100f);/*from  ww  w  . ja v a2 s .  c  o  m*/
    PdfPCell cell;

    cell = new PdfPCell(new Paragraph("Hersteller", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph("Modell", arialSmall));
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    cell.setGrayFill(0.85f);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    cell.setFixedHeight(30f);
    Paragraph herstellerInfo = new Paragraph(hersteller, courier);
    herstellerInfo.setLeading(leading);
    cell.addElement(herstellerInfo);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    cell.setFixedHeight(30f);
    Paragraph modellInfo = new Paragraph(modell, courier);
    modellInfo.setLeading(leading);
    cell.addElement(modellInfo);
    table.addCell(cell);

    return table;
}

From source file:pipe.PdfMaker.java

private Element fifthElement(String land, String edition, String jahr) {
    float leading = 9f;
    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(100f);//from w  ww .j a va2  s .  co  m
    PdfPCell cell;
    //Hier die Header zuerst
    cell = new PdfPCell(new Paragraph("Land", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph("Edition", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph("Jahr", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    //Ab hier die Werte
    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    Paragraph herkunftInfo = new Paragraph(land, courier);
    herkunftInfo.setLeading(leading);
    cell.addElement(herkunftInfo);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    Paragraph editionInfo = new Paragraph(edition, courier);
    editionInfo.setLeading(leading);
    cell.addElement(editionInfo);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorderWidth(0.3f);
    cell.setFixedHeight(30f);
    Paragraph yearInfo = new Paragraph(jahr, courier);
    yearInfo.setLeading(leading);
    cell.addElement(yearInfo);
    table.addCell(cell);

    return table;
}

From source file:pipe.PdfMaker.java

private Element sixthElement(String grundform, String mundstck) {
    float leading = 9f;
    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100f);//from ww  w . jav  a  2 s  . c  om
    PdfPCell cell;

    cell = new PdfPCell(new Paragraph("Grundform", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph("Mundstck", arialSmall));
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    cell.setGrayFill(0.85f);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    cell.setFixedHeight(30f);
    Paragraph herstellerInfo = new Paragraph(grundform, courier);
    herstellerInfo.setLeading(leading);
    cell.addElement(herstellerInfo);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    cell.setFixedHeight(30f);
    Paragraph modellInfo = new Paragraph(mundstck, courier);
    modellInfo.setLeading(leading);
    cell.addElement(modellInfo);
    table.addCell(cell);

    return table;
}

From source file:pipe.PdfMaker.java

private Element seventhElement(String kopfmat, String mundmat) {
    float leading = 9f;
    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100f);/*from   ww  w.j a v a  2s  .co  m*/
    PdfPCell cell;

    cell = new PdfPCell(new Paragraph("Kopfmaterial", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph("Material Mundstck", arialSmall));
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    cell.setGrayFill(0.85f);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    cell.setFixedHeight(30f);
    Paragraph mundMatInfo = new Paragraph(kopfmat, courier);
    mundMatInfo.setLeading(leading);
    cell.addElement(mundMatInfo);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    cell.setFixedHeight(30f);
    Paragraph modellInfo = new Paragraph(mundmat, courier);
    modellInfo.setLeading(leading);
    cell.addElement(modellInfo);
    table.addCell(cell);

    return table;
}

From source file:pipe.PdfMaker.java

private Element eightthElement(String applikation, String tabak) {
    float leading = 9f;
    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100f);/* ww  w  .j  a  va  2 s  . c  o  m*/
    PdfPCell cell;

    cell = new PdfPCell(new Paragraph("Applikation", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph("Eingerauchter Tabak", arialSmall));
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    cell.setGrayFill(0.85f);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    cell.setFixedHeight(30f);
    Paragraph mundMatInfo = new Paragraph(applikation, courier);
    mundMatInfo.setLeading(leading);
    cell.addElement(mundMatInfo);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    cell.setFixedHeight(30f);
    Paragraph modellInfo = new Paragraph(tabak, courier);
    modellInfo.setLeading(leading);
    cell.addElement(modellInfo);
    table.addCell(cell);

    return table;
}

From source file:pipe.PdfMaker.java

private Element ninethElement(String kaufpreis, String gekauft_bei, String datum) {
    float leading = 9f;
    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(100f);/*from w  w w  . j a  v a 2  s. c o m*/
    PdfPCell cell;
    //Hier die Header zuerst
    cell = new PdfPCell(new Paragraph("Einstandspreis", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph("Gekauft bei / von", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph("Kaufdatum", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    //Ab hier die Werte
    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    Paragraph herkunftInfo = new Paragraph(kaufpreis, courier);
    herkunftInfo.setLeading(leading);
    cell.addElement(herkunftInfo);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    Paragraph editionInfo = new Paragraph(gekauft_bei, courier);
    editionInfo.setLeading(leading);
    cell.addElement(editionInfo);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorderWidth(0.3f);
    cell.setFixedHeight(30f);
    Paragraph yearInfo = new Paragraph(datum, courier);
    yearInfo.setLeading(leading);
    cell.addElement(yearInfo);
    table.addCell(cell);

    return table;
}