Example usage for com.itextpdf.text BaseColor BLACK

List of usage examples for com.itextpdf.text BaseColor BLACK

Introduction

In this page you can find the example usage for com.itextpdf.text BaseColor BLACK.

Prototype

BaseColor BLACK

To view the source code for com.itextpdf.text BaseColor BLACK.

Click Source Link

Usage

From source file:org.javad.stamp.pdf.SetTenant.java

License:Apache License

void drawBorder(PdfContentByte content, OutputBounds rect) {
    content.setColorStroke(BaseColor.BLACK);
    content.setLineWidth(0.8f);
    content.rectangle(rect.x, rect.y, rect.width, rect.height);
    content.stroke();
}

From source file:org.javad.stamp.pdf.StampBox.java

License:Apache License

/**
 * Will draw a black frame shape for a given stamp box. The current
 * supported shapes include//from   ww w. j  a  v a 2  s. c  om
 * <ul><li>rectangle</li>
 * <li>triangle</li>
 * <li>diamond</li>
 * </ul>
 *
 * @param content
 * @param rect
 */
void drawShape(PdfContentByte content, OutputBounds rect) {

    content.setColorFill(BaseColor.WHITE);
    drawPath(content, rect);
    content.fill();
    if (isBorder()) {
        content.setColorStroke(BaseColor.BLACK);
        content.setLineWidth(0.8f);
        drawPath(content, rect);
        content.stroke();
    }
    content.setColorFill(BaseColor.BLACK);
}

From source file:org.javad.stamp.pdf.StampRow.java

License:Apache License

@Override
public OutputBounds generate(PdfContentByte content) {
    if (isSkipped()) {
        return new OutputBounds(getX(), getY(), 0, 0);
    }//from w w  w .jav  a  2s.com
    float maxWidth = 0;
    float top = getY();
    if (getDescription() != null && !getDescription().isEmpty()) {
        content.setColorStroke(BaseColor.BLACK);
        Font descFont = FontRegistry.getInstance().getFont(PdfFontDefinition.RowDescription);
        content.setFontAndSize(descFont.getBaseFont(), descFont.getSize());
        top -= descFont.getCalculatedSize();
        int count = 0;
        int tc = getDescription().split("\n").length;
        for (String desc : getDescription().split("\n")) {
            maxWidth = Math.max(maxWidth, (int) descFont.getBaseFont().getWidthPoint(desc, descFont.getSize()));
            PdfUtil.renderConstrainedText(content, desc, descFont, getX(), top, (int) (maxWidth * 1.10));
            count++;
            top -= descFont.getCalculatedSize() + ((count < tc) ? 2 : 4);

        }
    }
    float totalWidth = 0;
    int maxHeight = 0;
    int count = 0;
    for (int i = 0; i < stampContents.size(); i++) {
        if (stampContents.get(i).isSkipped()) {
            continue;
        }

        totalWidth += stampContents.get(i).getWidth() + stampContents.get(i).getPadding();
        if (count > 0) {
            totalWidth += padding;
        }
        count++;
        maxHeight = Math.max(maxHeight, stampContents.get(i).getHeight());
    }
    totalWidth = PdfUtil.convertFromMillimeters(totalWidth);
    float start_x = getX() - (totalWidth / 2.0f);
    float cur_x = start_x;
    float totalHeight = getY() - top;
    float deltaHeight = totalHeight;
    count = 0;
    for (IStampContent s : stampContents) {
        if (s.isSkipped()) {
            continue;
        }
        if (count > 0) {
            cur_x += PdfUtil.convertFromMillimeters(padding);
        }
        s.setX(cur_x);
        int delta_y = getVerticalAlignmentOffset(s, maxHeight);
        s.setY(top - PdfUtil.convertFromMillimeters(delta_y));
        OutputBounds r = s.generate(content);
        totalHeight = Math.max(r.height + deltaHeight, totalHeight);
        cur_x += r.width;
        count++;
    }
    maxWidth = (int) Math.max(maxWidth, totalWidth);
    return new OutputBounds(start_x, getY(), maxWidth, totalHeight);
}

From source file:org.javad.stamp.pdf.StampSet.java

License:Apache License

@Override
public OutputBounds generate(PdfContentByte content) {
    if (isSkipped()) {
        return new OutputBounds(getX(), getY(), 0, 0);
    }/* w ww .j  a v  a 2s  . c  o  m*/
    float maxWidth = 0;
    content.setColorStroke(BaseColor.BLACK);

    float top = getY();
    if (getIssue() != null && !getIssue().isEmpty()) {
        top -= PdfUtil.convertFromMillimeters(5.0f);
        Font f = FontRegistry.getInstance().getFont(PdfFontDefinition.SetIssue);
        content.setFontAndSize(f.getBaseFont(), f.getSize());
        String is = getIssue().replace("\\n", "\n");
        StringTokenizer tokenizer = new StringTokenizer(is, "\n", true);
        while (tokenizer.hasMoreTokens()) {
            is = tokenizer.nextToken();
            maxWidth = Math.max(maxWidth, content.getEffectiveStringWidth(is, false));
            if (is.equals("\n")) {
                top -= f.getCalculatedSize() + 2;
            } else {
                PdfUtil.renderConstrainedText(content, is, f, getX(), top, (int) maxWidth);
                if (tokenizer.hasMoreTokens()) {
                    top -= f.getCalculatedSize() + 2;
                }
            }

        }
        top -= PdfUtil.convertFromMillimeters(3.0f);
    }
    if (getDescription() != null && !getDescription().isEmpty()) {
        Font descFont = FontRegistry.getInstance().getFont(PdfFontDefinition.SetDescription);
        content.setFontAndSize(descFont.getBaseFont(), descFont.getSize());
        top -= descFont.getCalculatedSize();
        int count = 0;
        int tc = getDescription().split("\n").length;
        for (String desc : getDescription().split("\n")) {
            maxWidth = Math.max(maxWidth, content.getEffectiveStringWidth(desc, false));
            PdfUtil.renderConstrainedText(content, desc, descFont, getX(), top, (int) maxWidth);
            count++;
            if (count < tc) {
                top -= descFont.getCalculatedSize() + 2;
            }

        }
    }
    if (getDescriptionSecondary() != null && !getDescriptionSecondary().isEmpty()) {
        Font secFont = FontRegistry.getInstance().getFont(PdfFontDefinition.SetDescriptionSecondary);
        content.setFontAndSize(secFont.getBaseFont(), secFont.getSize());
        top -= secFont.getCalculatedSize() + PdfUtil.convertFromMillimeters(3.0f);
        int count = 0;
        int tc = getDescriptionSecondary().split("\n").length;
        for (String desc : getDescriptionSecondary().split("\n")) {
            maxWidth = Math.max(maxWidth, content.getEffectiveStringWidth(desc, false));
            PdfUtil.renderConstrainedText(content, desc, secFont, getX(), top, (int) maxWidth);
            count++;
            if (count < tc) {
                top -= secFont.getCalculatedSize() + 2;
            }

        }
    }

    if (!rows.isEmpty()) {
        top -= ((top != getY()) ? PdfUtil.convertFromMillimeters(3.0f) : 0);
        int count = 0;
        for (int i = 0; i < rows.size(); i++) {
            ISetContent row = rows.get(i);
            if (row.isSkipped()) {
                continue;
            }
            top -= ((count > 0) ? (PdfUtil.convertFromMillimeters(verticalPadding)) : 0.0f);
            row.setX(getX());
            row.setY(top);
            OutputBounds bounds = row.generate(content);
            count++;
            top -= bounds.height;
            maxWidth = Math.max(maxWidth, bounds.width);
        }
    }
    if (getComment() != null && !getComment().isEmpty()) {

        top -= PdfUtil.convertFromMillimeters((int) (0.75 * verticalPadding));
        Font cFont = FontRegistry.getInstance().getFont(PdfFontDefinition.SetComment);
        content.setFontAndSize(cFont.getBaseFont(), cFont.getSize());
        for (String s : getComment().split("\n")) {
            top -= cFont.getCalculatedSize();
            maxWidth = Math.max(maxWidth, content.getEffectiveStringWidth(s, false));
            PdfUtil.renderConstrainedText(content, s, cFont, getX(), top, (int) maxWidth);
        }

    }

    OutputBounds rect = new OutputBounds(getX() - maxWidth / 2, getY(), maxWidth, getY() - top);
    return rect;
}

From source file:Output.QuotePDf.java

private PdfPTable carrierComments(Boolean includeCarrierComments, String carrierComments) {
    PdfPTable table = new PdfPTable(1);
    table.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.setWidthPercentage(100f);//from w  ww.  j  ava  2 s .  c o  m
    table.setSpacingAfter(10f);
    if (includeCarrierComments) {
        cell = new PdfPCell(new Phrase("Carrier Comments", tableHeadingFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setPaddingBottom(10f);
        cell.setBackgroundColor(BaseColor.BLACK);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(carrierComments, textFont));
        cell.setPadding(5f);
        table.addCell(cell);
    }
    return table;
}

From source file:Output.QuotePDf.java

private PdfPTable packingListTable(JTable packingListTable) throws DocumentException {
    PdfPTable table = new PdfPTable(11);
    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    table.setWidthPercentage(100f);//from w ww.jav a 2s  .c  o m
    table.setWidths(new int[] { 5, 2, 2, 2, 2, 3, 2, 2, 2, 3, 3 });
    table.setSpacingAfter(10f);

    cell = new PdfPCell(new Phrase("Packing List", tableHeadingFont));
    cell.setBackgroundColor(BaseColor.BLACK);
    cell.setColspan(11);
    cell.setPaddingBottom(5);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("Commodity", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("Qty", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("L(cm)", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("W(cm)", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("H(cm)", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("Kgs", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("L(in)", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("W(in)", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("H(in)", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("M3", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("Lbs", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    for (int row = 0; row < packingListTable.getRowCount(); row++) {
        for (int col = 0; col < 11; col++) {
            String packingListData = String.valueOf(packingListTable.getValueAt(row, col));
            if (packingListData.equals("null")) {
                packingListData = " ";
                cell = new PdfPCell(new Phrase(packingListData, textFont));
                table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(packingListData, textFont));
                table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                table.addCell(cell);
            }
        }
    }

    return table;
}

From source file:Output.QuotePDf.java

private PdfPTable sailingScheduleTable(JTable sailingScheduleTable, Boolean includeSailngSchedule)
        throws DocumentException {
    PdfPTable table = new PdfPTable(4);
    table.setWidthPercentage(100f);/*  ww  w. j  av a  2s.co m*/
    table.setHorizontalAlignment(Element.ALIGN_CENTER);

    if (includeSailngSchedule) {
        cell = new PdfPCell(new Phrase("Sailing Schedule", tableHeadingFont));
        cell.setPaddingBottom(5);
        cell.setBackgroundColor(BaseColor.BLACK);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(4);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("Vessel/Voyage", rowLabelFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Sail Date", rowLabelFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Transit Time", rowLabelFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Transshipment", rowLabelFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);

        for (int r = 0; r < sailingScheduleTable.getRowCount(); r++) {
            for (int c = 0; c < 4; c++) {
                Object sailingScheduleData = sailingScheduleTable.getValueAt(r, c);
                if (sailingScheduleData == null) {
                    sailingScheduleData = " ";
                    cell = new PdfPCell(new Phrase(String.valueOf(sailingScheduleData), textFont));
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    table.addCell(cell);
                } else {
                    cell = new PdfPCell(new Phrase(String.valueOf(sailingScheduleData), textFont));
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    table.addCell(cell);
                }
            }
        }
    }

    return table;
}

From source file:pdf.PDFDesign.java

public PDFDesign(String s, String c, String sn, Map<String, String> fontMap) {
    size = s;/* ww  w .  j a v  a 2  s .c o  m*/
    titleLineFixedHeight = 15.0f;
    priceFontInc = 0;
    textFontInc = 0;
    styleName = sn;
    fontPaths = new FontPaths(fontMap);
    nColumns = 6;
    switch (c) {
    case "black":
        color = BaseColor.BLACK;
        break;
    case "gray":
        color = BaseColor.DARK_GRAY;
        break;
    case "red":
        color = BaseColor.RED.darker();
        break;
    case "green":
        color = BaseColor.GREEN.darker().darker().darker();
        break;
    case "blue":
        color = BaseColor.BLUE.darker().darker().darker();
        break;
    default:
        this.color = BaseColor.BLACK;
    }
    switch (size) {
    case "3x5":
        cellHeight = 83.8f;
        break;
    case "3.5x5":
        cellHeight = 97.8f;
        break;
    case "3.5x6":
        priceFontInc = 8;
        cellHeight = 97.8f;
        nColumns = 5;
        break;
    case "3.5x7":
        cellHeight = 97.8f;
        nColumns = 4;
        break;
    case "4x6":
        titleLineFixedHeight = 26.0f;
        priceFontInc = 8;
        cellHeight = 117.0f;
        nColumns = 5;
        break;
    case "4x7":
        titleLineFixedHeight = 26.0f;
        priceFontInc = 8;
        cellHeight = 117.0f;
        nColumns = 4;
        break;
    case "5x6":
        titleLineFixedHeight = 30.0f;
        priceFontInc = 13;
        textFontInc = 2;
        cellHeight = 145.0f;
        nColumns = 5;
        break;
    case "5x7":
        titleLineFixedHeight = 30.0f;
        priceFontInc = 18;
        textFontInc = 3;
        cellHeight = 145.0f;
        nColumns = 4;
        break;
    case "6x7":
        titleLineFixedHeight = 34.0f;
        priceFontInc = 26;
        textFontInc = 5;
        cellHeight = 175.0f;
        nColumns = 4;
        break;
    }
    try {
        int normal = Font.NORMAL;
        int bold = Font.BOLD;

        droidsans = BaseFont.createFont(fontPaths.getPath("droidsans"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        BaseFont impact = BaseFont.createFont(fontPaths.getPath("impact"), BaseFont.IDENTITY_H,
                BaseFont.EMBEDDED);

        switch (styleName) {
        case "style1":
            BaseFont courier = BaseFont.createFont(fontPaths.getPath("courier"), BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED);
            initValues(42f, new Font(courier, 12 + textFontInc, normal, color),
                    new Font(courier, 9 + textFontInc, normal, color),
                    new Font(impact, 43 + priceFontInc + textFontInc, normal, color),
                    new Font(courier, 20 + textFontInc, normal, color),
                    new Font(courier, 8 + textFontInc, normal, color));
            break;
        case "style2":
            BaseFont digital7 = BaseFont.createFont(fontPaths.getPath("digital7"), BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED);
            initValues(42f, new Font(droidsans, 10 + textFontInc, normal, color),
                    new Font(droidsans, 7 + textFontInc, normal, color),
                    new Font(digital7, 55 + priceFontInc + textFontInc, normal, color),
                    new Font(digital7, 30, normal, color), new Font(droidsans, 7 + textFontInc, normal, color));
            break;
        case "style3":
            BaseFont modern = BaseFont.createFont(fontPaths.getPath("modern"), BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED);
            initValues(40f, new Font(droidsans, 10 + textFontInc, normal, color),
                    new Font(droidsans, 7 + textFontInc, normal, color),
                    new Font(modern, 55 + priceFontInc + textFontInc, normal, color),
                    new Font(modern, 30, normal, color), new Font(droidsans, 7 + textFontInc, normal, color));
            break;
        case "style4":
            BaseFont gothic = BaseFont.createFont(fontPaths.getPath("gothic"), BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED);
            initValues(40f, new Font(droidsans, 10 + textFontInc, normal, color),
                    new Font(droidsans, 7 + textFontInc, normal, color),
                    new Font(gothic, 48 + priceFontInc + textFontInc, bold, color),
                    new Font(gothic, 30, bold, color), new Font(droidsans, 7 + textFontInc, normal, color));
            break;
        case "style5":
            BaseFont bookman = BaseFont.createFont(fontPaths.getPath("bookman"), BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED);
            initValues(35f, new Font(droidsans, 10 + textFontInc, normal, color),
                    new Font(droidsans, 7 + textFontInc, normal, color),
                    new Font(bookman, 45 + priceFontInc + textFontInc, bold, color),
                    new Font(bookman, 25, normal, color), new Font(droidsans, 7 + textFontInc, normal, color));
            break;

        case "style6":
            initValues(45f, new Font(droidsans, 10 + textFontInc, normal, color),
                    new Font(droidsans, 7 + textFontInc, normal, color),
                    new Font(impact, 45 + priceFontInc + textFontInc, normal, color),
                    new Font(droidsans, 20 + textFontInc, normal, color),
                    new Font(droidsans, 7 + textFontInc, normal, color));
            break;

        default:
            System.out.println("[*] Unknown Style");
            break;
        }

    } catch (DocumentException | IOException ex) {
        System.out.println("[E] " + ex.getMessage());
    }
}

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//from  w w  w  .ja  v  a 2  s . c o 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:pdfreporter.PDFGenTable.java

public static void pdfgentable() {
    Document document = new Document();
    try {/* www  .j av  a 2  s .  c  o  m*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("AddTableExample.pdf"));
        document.open();

        PdfPTable table = new PdfPTable(4); // 3 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 };
        table.setWidths(columnWidths);

        PdfPCell cell1 = new PdfPCell(new Paragraph("Nemam Pojma"));
        cell1.setBorderColor(BaseColor.BLACK);
        cell1.setPaddingLeft(10);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cell2 = new PdfPCell(new Paragraph("Nemam pojma 2"));
        cell2.setBorderColor(BaseColor.BLACK);
        cell2.setPaddingLeft(10);
        cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cell3 = new PdfPCell(new Paragraph("Nemam pojma 3"));
        cell3.setBorderColor(BaseColor.BLACK);
        cell3.setPaddingLeft(10);
        cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cell4 = new PdfPCell(new Paragraph("Nemam pojma 4"));
        cell4.setBorderColor(BaseColor.BLACK);
        cell4.setPaddingLeft(10);
        cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);

        //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);
        table.addCell(cell1);
        table.addCell(cell2);
        table.addCell(cell3);
        table.addCell(cell4);

        document.add(table);

        document.close();
        writer.close();
    } catch (FileNotFoundException | DocumentException e) {
    }
}