本文整理汇总了Java中com.lowagie.text.pdf.PdfPTable.setHeaderRows方法的典型用法代码示例。如果您正苦于以下问题:Java PdfPTable.setHeaderRows方法的具体用法?Java PdfPTable.setHeaderRows怎么用?Java PdfPTable.setHeaderRows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lowagie.text.pdf.PdfPTable
的用法示例。
在下文中一共展示了PdfPTable.setHeaderRows方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.lowagie.text.pdf.PdfPTable; //导入方法依赖的package包/类
/**
* General example using cell events.
*
*/
@Test
public void main() throws Exception {
// step1
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
// step2
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("CellEvents.pdf"));
// step3
document.open();
// step4
CellEventsTest event = new CellEventsTest();
Image im = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
im.setRotationDegrees(30);
PdfPTable table = new PdfPTable(4);
table.addCell("text 1");
PdfPCell cell = new PdfPCell(im, true);
cell.setCellEvent(event);
table.addCell(cell);
table.addCell("text 3");
im.setRotationDegrees(0);
table.addCell(im);
table.setTotalWidth(300);
PdfContentByte cb = writer.getDirectContent();
table.writeSelectedRows(0, -1, 50, 600, cb);
table.setHeaderRows(3);
document.add(table);
// step5
document.close();
}
示例2: toPdfInternal
import com.lowagie.text.pdf.PdfPTable; //导入方法依赖的package包/类
private static void toPdfInternal( Grid grid, Document document, float spacing )
{
if ( grid == null || grid.getVisibleWidth() == 0 )
{
return;
}
PdfPTable table = new PdfPTable( grid.getVisibleWidth() );
table.setHeaderRows( 1 );
table.setWidthPercentage( 100F );
table.setKeepTogether( false );
table.setSpacingAfter( spacing );
table.addCell( resetPaddings( getTitleCell( grid.getTitle(), grid.getVisibleWidth() ), 0, 30, 0, 0 ) );
if ( StringUtils.isNotEmpty( grid.getSubtitle() ) )
{
table.addCell( getSubtitleCell( grid.getSubtitle(), grid.getVisibleWidth() ) );
table.addCell( getEmptyCell( grid.getVisibleWidth(), 30 ) );
}
for ( GridHeader header : grid.getVisibleHeaders() )
{
table.addCell( getItalicCell( header.getName() ) );
}
table.addCell( getEmptyCell( grid.getVisibleWidth(), 10 ) );
for ( List<Object> row : grid.getVisibleRows() )
{
for ( Object col : row )
{
table.addCell( getTextCell( col ) );
}
}
addTableToDocument( document, table );
}
示例3: writeHeader
import com.lowagie.text.pdf.PdfPTable; //导入方法依赖的package包/类
private void writeHeader() throws DocumentException {
final List<String> headers = new ArrayList<String>();
headers.add("Beans");
headers.addAll(calledBeans);
final int[] relativeWidths = new int[headers.size()];
Arrays.fill(relativeWidths, 0, headers.size(), 1);
relativeWidths[0] = 4;
final PdfPTable table = new PdfPTable(headers.size());
table.setWidthPercentage(100);
table.setWidths(relativeWidths);
table.setHeaderRows(1);
final PdfPCell defaultCell = table.getDefaultCell();
defaultCell.setGrayFill(0.9f);
defaultCell.setHorizontalAlignment(Element.ALIGN_CENTER);
defaultCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
defaultCell.setPaddingLeft(0);
defaultCell.setPaddingRight(0);
for (final String header : headers) {
table.addCell(new Phrase(header, boldCellFont));
// pas la première entête de colonne
defaultCell.setRotation(90);
}
defaultCell.setRotation(0);
defaultCell.setPaddingLeft(2);
defaultCell.setPaddingRight(2);
currentTable = table;
}
示例4: toPdfInternal
import com.lowagie.text.pdf.PdfPTable; //导入方法依赖的package包/类
private static void toPdfInternal( Grid grid, Document document, float spacing )
{
if ( grid == null || grid.getVisibleWidth() == 0 )
{
return;
}
PdfPTable table = new PdfPTable( grid.getVisibleWidth() );
table.setHeaderRows( 1 );
table.setWidthPercentage( 100F );
table.setKeepTogether( false );
table.setSpacingAfter( spacing );
table.addCell( resetPaddings( getTitleCell( grid.getTitle(), grid.getVisibleWidth() ), 0, 30, 0, 0 ) );
if ( StringUtils.isNotEmpty( grid.getSubtitle() ) )
{
table.addCell( getSubtitleCell( grid.getSubtitle(), grid.getVisibleWidth() ) );
table.addCell( getEmptyCell( grid.getVisibleWidth(), 30 ) );
}
for ( GridHeader header : grid.getVisibleHeaders() )
{
table.addCell( getItalicCell( header.getName() ) );
}
table.addCell( getEmptyCell( grid.getVisibleWidth(), 10 ) );
for ( List<Object> row : grid.getVisibleRows() )
{
for ( Object col : row )
{
table.addCell( getTextCell( col ) );
}
}
addTableToDocument( document, table );
}
示例5: printHeader
import com.lowagie.text.pdf.PdfPTable; //导入方法依赖的package包/类
@Override
public void printHeader(String... fields) {
iTable = new PdfPTable(fields.length - iHiddenColumns.size());
iMaxWidth = new float[fields.length];
iTable.setHeaderRows(1);
iTable.setWidthPercentage(100);
for (int idx = 0; idx < fields.length; idx++) {
if (iHiddenColumns.contains(idx)) continue;
String f = fields[idx];
PdfPCell cell = new PdfPCell();
cell.setBorder(Rectangle.BOTTOM);
cell.setVerticalAlignment(Element.ALIGN_TOP);
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
Font font = PdfFont.getFont(true);
Paragraph ch = new Paragraph(f, font);
ch.setLeading(0f, 1f);
cell.addElement(ch);
iTable.addCell(cell);
float width = 0;
if (f.indexOf('\n')>=0) {
for (StringTokenizer s = new StringTokenizer(f,"\n"); s.hasMoreTokens();)
width = Math.max(width,font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize()));
} else
width = Math.max(width,font.getBaseFont().getWidthPoint(f, font.getSize()));
iMaxWidth[idx] = width;
}
}
示例6: main
import com.lowagie.text.pdf.PdfPTable; //导入方法依赖的package包/类
/**
* General example using cell events.
*
* @param args
* no arguments needed
*/
public static void main(String[] args) {
System.out.println("CellEvents");
// step1
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
try {
// step2
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "CellEvents.pdf"));
// step3
document.open();
// step4
CellEvents event = new CellEvents();
//Can't use filename => use byte[] instead
// Image img = Image.getInstance("otsoe.jpg");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Bitmap bitmap = BitmapFactory.decodeResource(PdfTestRunner.getActivity().getResources(), R.drawable.otsoe);
bitmap.compress(Bitmap.CompressFormat.JPEG /* FileType */,
100 /* Ratio */, stream);
Image im = Image.getInstance(stream.toByteArray());
im.setRotationDegrees(30);
PdfPTable table = new PdfPTable(4);
table.addCell("text 1");
PdfPCell cell = new PdfPCell(im, true);
cell.setCellEvent(event);
table.addCell(cell);
table.addCell("text 3");
im.setRotationDegrees(0);
table.addCell(im);
table.setTotalWidth(300);
PdfContentByte cb = writer.getDirectContent();
table.writeSelectedRows(0, -1, 50, 600, cb);
table.setHeaderRows(3);
document.add(table);
} catch (Exception de) {
de.printStackTrace();
}
// step5
document.close();
}
示例7: createTableOfDistributionItems
import com.lowagie.text.pdf.PdfPTable; //导入方法依赖的package包/类
/**
* Create table with distribution items.
*
* @param paragraph
* @param distributionItems
*/
private void createTableOfDistributionItems(Paragraph paragraph, List<DistributionItem> distributionItems)
{
PdfPTable table = new PdfPTable(3);
table.setHorizontalAlignment(Element.ALIGN_LEFT);
table.setWidthPercentage(50f);
PdfPCell c1 = new PdfPCell(new Phrase("Name", tableFontBold));
table.addCell(c1);
c1 = new PdfPCell(new Phrase("Abteilung", tableFontBold));
table.addCell(c1);
c1 = new PdfPCell(new Phrase("Phone", tableFontBold));
table.addCell(c1);
table.setHeaderRows(1);
for (DistributionItem distributionItem : distributionItems)
{
table.addCell(new PdfPCell(new Phrase(distributionItem.getName(), tableFont)));
table.addCell(new PdfPCell(new Phrase(distributionItem.getDepartment(), tableFont)));
table.addCell(new PdfPCell(new Phrase(distributionItem.getPhone(), tableFont)));
}
paragraph.add(table);
}
示例8: main
import com.lowagie.text.pdf.PdfPTable; //导入方法依赖的package包/类
/**
* Big PdfPTable with document.add().
*
*/
@Test
public void main() throws Exception {
// step1
Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10);
// step2
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("AddBigTable.pdf"));
// step3
document.open();
// step4
String[] bogusData = { "M0065920", "SL", "FR86000P", "PCGOLD", "119000", "96 06", "2001-08-13", "4350",
"6011648299", "FLFLMTGP", "153", "119000.00" };
int NumColumns = 12;
PdfPTable datatable = new PdfPTable(NumColumns);
int headerwidths[] = { 9, 4, 8, 10, 8, 11, 9, 7, 9, 10, 4, 10 }; // percentage
datatable.setWidths(headerwidths);
datatable.setWidthPercentage(100); // percentage
datatable.getDefaultCell().setPadding(3);
datatable.getDefaultCell().setBorderWidth(2);
datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
datatable.addCell("Clock #");
datatable.addCell("Trans Type");
datatable.addCell("Cusip");
datatable.addCell("Long Name");
datatable.addCell("Quantity");
datatable.addCell("Fraction Price");
datatable.addCell("Settle Date");
datatable.addCell("Portfolio");
datatable.addCell("ADP Number");
datatable.addCell("Account ID");
datatable.addCell("Reg Rep ID");
datatable.addCell("Amt To Go ");
datatable.setHeaderRows(1); // this is the end of the table header
datatable.getDefaultCell().setBorderWidth(1);
for (int i = 1; i < 750; i++) {
if (i % 2 == 1) {
datatable.getDefaultCell().setGrayFill(0.9f);
}
for (int x = 0; x < NumColumns; x++) {
datatable.addCell(bogusData[x]);
}
if (i % 2 == 1) {
datatable.getDefaultCell().setGrayFill(1);
}
}
document.add(datatable);
// step5
document.close();
}
示例9: main
import com.lowagie.text.pdf.PdfPTable; //导入方法依赖的package包/类
/**
* Break a large table up into several smaller tables for memory management
* purposes.
*
* @param args
* the number of rows for each table fragment.
*/
public static void main(String[] args) {
System.out.println("FragmentTable");
int fragmentsize = Integer.parseInt(args[0]);
// step1
Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10);
try {
// step2
PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "FragmentTable.pdf"));
// step3
document.open();
// step4
Font font = FontFactory.getFont("Helvetica", 8, Font.BOLD, Color.BLACK);
PdfPTable table = new PdfPTable(2);
table.setWidthPercentage(100f);
PdfPCell h1 = new PdfPCell(new Paragraph("Header 1", font));
PdfPCell h2 = new PdfPCell(new Paragraph("Header 2", font));
table.setHeaderRows(1);
table.addCell(h1);
table.addCell(h2);
PdfPCell cell;
for (int row = 1; row <= 2000; row++) {
if (row % fragmentsize == fragmentsize - 1) {
document.add(table);
table.deleteBodyRows();
table.setSkipFirstHeader(true);
}
cell = new PdfPCell(new Paragraph(String.valueOf(row), font));
table.addCell(cell);
cell = new PdfPCell(
new Paragraph(
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nulla mauris nibh, ultricies nec, adipiscing eget.",
font));
table.addCell(cell);
}
document.add(table);
} catch (Exception de) {
de.printStackTrace();
}
// step5
document.close();
}
示例10: main
import com.lowagie.text.pdf.PdfPTable; //导入方法依赖的package包/类
/**
* Big PdfPTable with document.add().
*
* @param args
* no arguments needed
*/
public static void main(String[] args) {
System.out.println("document.add(BigTable)");
// step1
Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10);
try {
// step2
PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "AddBigTable.pdf"));
// step3
document.open();
// step4
String[] bogusData = { "M0065920", "SL", "FR86000P", "PCGOLD", "119000", "96 06", "2001-08-13", "4350",
"6011648299", "FLFLMTGP", "153", "119000.00" };
int NumColumns = 12;
PdfPTable datatable = new PdfPTable(NumColumns);
int headerwidths[] = { 9, 4, 8, 10, 8, 11, 9, 7, 9, 10, 4, 10 }; // percentage
datatable.setWidths(headerwidths);
datatable.setWidthPercentage(100); // percentage
datatable.getDefaultCell().setPadding(3);
datatable.getDefaultCell().setBorderWidth(2);
datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
datatable.addCell("Clock #");
datatable.addCell("Trans Type");
datatable.addCell("Cusip");
datatable.addCell("Long Name");
datatable.addCell("Quantity");
datatable.addCell("Fraction Price");
datatable.addCell("Settle Date");
datatable.addCell("Portfolio");
datatable.addCell("ADP Number");
datatable.addCell("Account ID");
datatable.addCell("Reg Rep ID");
datatable.addCell("Amt To Go ");
datatable.setHeaderRows(1); // this is the end of the table header
datatable.getDefaultCell().setBorderWidth(1);
for (int i = 1; i < 750; i++) {
if (i % 2 == 1) {
datatable.getDefaultCell().setGrayFill(0.9f);
}
for (int x = 0; x < NumColumns; x++) {
datatable.addCell(bogusData[x]);
}
if (i % 2 == 1) {
datatable.getDefaultCell().setGrayFill(1);
}
}
document.add(datatable);
} catch (Exception de) {
de.printStackTrace();
}
// step5
document.close();
}
示例11: createPdfPTable
import com.lowagie.text.pdf.PdfPTable; //导入方法依赖的package包/类
/**
* Create a PdfPTable based on this Table object.
* @return a PdfPTable object
* @throws BadElementException
*/
public PdfPTable createPdfPTable() throws BadElementException {
if (!convert2pdfptable) {
throw new BadElementException("No error, just an old style table");
}
setAutoFillEmptyCells(true);
complete();
PdfPTable pdfptable = new PdfPTable(widths);
pdfptable.setComplete(complete);
if (isNotAddedYet())
pdfptable.setSkipFirstHeader(true);
SimpleTable t_evt = new SimpleTable();
t_evt.cloneNonPositionParameters(this);
t_evt.setCellspacing(cellspacing);
pdfptable.setTableEvent(t_evt);
pdfptable.setHeaderRows(lastHeaderRow + 1);
pdfptable.setSplitLate(cellsFitPage);
pdfptable.setKeepTogether(tableFitsPage);
if (!Float.isNaN(offset)) {
pdfptable.setSpacingBefore(offset);
}
pdfptable.setHorizontalAlignment(alignment);
if (locked) {
pdfptable.setTotalWidth(width);
pdfptable.setLockedWidth(true);
}
else {
pdfptable.setWidthPercentage(width);
}
Row row;
for (Iterator iterator = iterator(); iterator.hasNext(); ) {
row = (Row) iterator.next();
Element cell;
PdfPCell pcell;
for (int i = 0; i < row.getColumns(); i++) {
if ((cell = (Element)row.getCell(i)) != null) {
if (cell instanceof Table) {
pcell = new PdfPCell(((Table)cell).createPdfPTable());
}
else if (cell instanceof Cell) {
pcell = ((Cell)cell).createPdfPCell();
pcell.setPadding(cellpadding + cellspacing / 2f);
SimpleCell c_evt = new SimpleCell(SimpleCell.CELL);
c_evt.cloneNonPositionParameters((Cell)cell);
c_evt.setSpacing(cellspacing * 2f);
pcell.setCellEvent(c_evt);
}
else {
pcell = new PdfPCell();
}
pdfptable.addCell(pcell);
}
}
}
return pdfptable;
}
示例12: createPdfPTable
import com.lowagie.text.pdf.PdfPTable; //导入方法依赖的package包/类
/**
* Create a PdfPTable based on this Table object.
* @return a PdfPTable object
* @throws BadElementException
*/
public PdfPTable createPdfPTable() throws BadElementException {
if (!convert2pdfptable) {
throw new BadElementException("No error, just an old style table");
}
setAutoFillEmptyCells(true);
complete();
PdfPTable pdfptable = new PdfPTable(widths);
pdfptable.setTableEvent(new BorderEvent(this));
pdfptable.setHeaderRows(lastHeaderRow + 1);
pdfptable.setSplitLate(cellsFitPage);
if (!Float.isNaN(offset)) {
pdfptable.setSpacingBefore(offset);
}
pdfptable.setHorizontalAlignment(alignment);
if (absWidth.length() > 0) {
try {
pdfptable.setTotalWidth(Float.parseFloat(absWidth));
}
catch(Exception e1) {
try {
pdfptable.setTotalWidth((float)Integer.parseInt(absWidth));
}
catch(Exception e2) {
pdfptable.setWidthPercentage(widthPercentage);
}
}
}
else {
pdfptable.setWidthPercentage(widthPercentage);
}
Row row;
for (Iterator iterator = iterator(); iterator.hasNext(); ) {
row = (Row) iterator.next();
Element cell;
PdfPCell pcell;
for (int i = 0; i < row.columns(); i++) {
if ((cell = (Element)row.getCell(i)) != null) {
if (cell instanceof Table) {
pcell = new PdfPCell(((Table)cell).createPdfPTable());
}
else if (cell instanceof Cell) {
pcell = ((Cell)cell).createPdfPCell();
pcell.setPadding(cellpadding);
}
else {
pcell = new PdfPCell();
}
pdfptable.addCell(pcell);
}
}
}
return pdfptable;
}