import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.GrayColor;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPCellEvent;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
class RoundRectangle implements PdfPCellEvent {
public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) {
PdfContentByte cb = canvas[PdfPTable.LINECANVAS];
cb.setColorStroke(new GrayColor(0.8f));
cb.roundRectangle(rect.left() + 4, rect.bottom(), rect.width() - 8, rect.height() - 4, 4);
cb.stroke();
}
}
public class MainClass {
public static void main(String[] args) throws Exception {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
document.open();
RoundRectangle border = new RoundRectangle();
PdfPTable table = new PdfPTable(6);
PdfPCell cell;
for (int i = 1; i <= 30; i++) {
cell = new PdfPCell(new Phrase("day " + i));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBorder(Rectangle.NO_BORDER);
cell.setPadding(4);
cell.setCellEvent(border);
table.addCell(cell);
}
document.add(table);
document.close();
}
}
|