Java/PDF RTF/Table Split — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 05:59, 1 июня 2010
Split Rows Demo
import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
public class SplitRowsPDF {
public static void main(String[] args) {
Document document1 = new Document(PageSize.A4.rotate(), 10, 10, 10, 10);
try {
PdfWriter.getInstance(document1, new FileOutputStream("SplitRowsPDF.pdf"));
document1.open();
String text = "Text Text Text Text Text Text Text Text Text";
PdfPTable table = new PdfPTable(2);
PdfPCell largeCell;
Phrase phrase;
for (int i = 0; i < 10; i++) {
phrase = new Phrase(text);
for (int j = 0; j < i; j++) {
phrase.add(new Phrase(text));
}
if (i == 7)
phrase = new Phrase(text);
table.addCell(String.valueOf(i));
largeCell = new PdfPCell(phrase);
table.addCell(largeCell);
}
document1.add(table);
table.setSplitLate(true);
} catch (Exception de) {
de.printStackTrace();
}
document1.close();
}
}
Split Table Demo
import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
public class SplitTablePDF {
public static void main(String[] args) {
Document document = new Document(PageSize.A4, 10, 10, 10, 10);
try {
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("SplitTablePDF.pdf"));
document.open();
PdfContentByte cb = writer.getDirectContent();
PdfPTable table = new PdfPTable(10);
for (int i = 1; i <= 100; ++i) {
table.addCell(Integer.toString(i));
}
table.setTotalWidth(800);
table.writeSelectedRows(0, 5, 0, -1, 50, 650, cb);
document.newPage();
table.writeSelectedRows(5, -1, 0, -1, 50, 650, cb);
} catch (Exception de) {
de.printStackTrace();
}
document.close();
}
}