本文整理汇总了Java中com.lowagie.text.pdf.PdfPTable.setLockedWidth方法的典型用法代码示例。如果您正苦于以下问题:Java PdfPTable.setLockedWidth方法的具体用法?Java PdfPTable.setLockedWidth怎么用?Java PdfPTable.setLockedWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lowagie.text.pdf.PdfPTable
的用法示例。
在下文中一共展示了PdfPTable.setLockedWidth方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildTable
import com.lowagie.text.pdf.PdfPTable; //导入方法依赖的package包/类
public PdfPTable buildTable() {
if (rows.isEmpty())
return new PdfPTable(1);
int ncol = 0;
ArrayList c0 = (ArrayList)rows.get(0);
for (int k = 0; k < c0.size(); ++k) {
ncol += ((PdfPCell)c0.get(k)).getColspan();
}
PdfPTable table = new PdfPTable(ncol);
String width = (String)props.get("width");
if (width == null)
table.setWidthPercentage(100);
else {
if (width.endsWith("%"))
table.setWidthPercentage(Float.parseFloat(width.substring(0, width.length() - 1)));
else {
table.setTotalWidth(Float.parseFloat(width));
table.setLockedWidth(true);
}
}
for (int row = 0; row < rows.size(); ++row) {
ArrayList col = (ArrayList)rows.get(row);
for (int k = 0; k < col.size(); ++k) {
table.addCell((PdfPCell)col.get(k));
}
}
return table;
}
示例2: main
import com.lowagie.text.pdf.PdfPTable; //导入方法依赖的package包/类
/**
* Width manipulations of cells.
*
*/
@Test
public void main() throws Exception {
// step1
Document document = new Document(PageSize.A4, 36, 36, 36, 36);
// step2
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("CellWidths.pdf"));
// step3
document.open();
// step4
float[] widths = { 0.1f, 0.1f, 0.05f, 0.75f };
PdfPTable table = new PdfPTable(widths);
table.addCell("10%");
table.addCell("10%");
table.addCell("5%");
table.addCell("75%");
table.addCell("aa");
table.addCell("aa");
table.addCell("a");
table.addCell("aaaaaaaaaaaaaaa");
table.addCell("bb");
table.addCell("bb");
table.addCell("b");
table.addCell("bbbbbbbbbbbbbbb");
table.addCell("cc");
table.addCell("cc");
table.addCell("c");
table.addCell("ccccccccccccccc");
document.add(table);
document.add(new Paragraph("We change the percentages:\n\n"));
widths[0] = 20f;
widths[1] = 20f;
widths[2] = 10f;
widths[3] = 50f;
table.setWidths(widths);
document.add(table);
widths[0] = 40f;
widths[1] = 40f;
widths[2] = 20f;
widths[3] = 300f;
Rectangle r = new Rectangle(PageSize.A4.getRight(72), PageSize.A4.getTop(72));
table.setWidthPercentage(widths, r);
document.add(new Paragraph("We change the percentage using absolute widths:\n\n"));
document.add(table);
document.add(new Paragraph("We use a locked width:\n\n"));
table.setTotalWidth(300);
table.setLockedWidth(true);
document.add(table);
// step5
document.close();
}
示例3: getProgramStageMainTable
import com.lowagie.text.pdf.PdfPTable; //导入方法依赖的package包/类
private PdfPTable getProgramStageMainTable()
{
PdfPTable mainTable = new PdfPTable( 1 ); // Code 1
mainTable.setTotalWidth( 800f );
mainTable.setLockedWidth( true );
mainTable.setHorizontalAlignment( Element.ALIGN_LEFT );
return mainTable;
}
示例4: main
import com.lowagie.text.pdf.PdfPTable; //导入方法依赖的package包/类
/**
* Width manipulations of cells.
*
* @param args
* no arguments needed
*/
public static void main(String[] args) {
System.out.println("Width");
// step1
Document document = new Document(PageSize.A4, 36, 36, 36, 36);
try {
// step2
PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "CellWidths.pdf"));
// step3
document.open();
// step4
float[] widths = { 0.1f, 0.1f, 0.05f, 0.75f };
PdfPTable table = new PdfPTable(widths);
table.addCell("10%");
table.addCell("10%");
table.addCell("5%");
table.addCell("75%");
table.addCell("aa");
table.addCell("aa");
table.addCell("a");
table.addCell("aaaaaaaaaaaaaaa");
table.addCell("bb");
table.addCell("bb");
table.addCell("b");
table.addCell("bbbbbbbbbbbbbbb");
table.addCell("cc");
table.addCell("cc");
table.addCell("c");
table.addCell("ccccccccccccccc");
document.add(table);
document.add(new Paragraph("We change the percentages:\n\n"));
widths[0] = 20f;
widths[1] = 20f;
widths[2] = 10f;
widths[3] = 50f;
table.setWidths(widths);
document.add(table);
widths[0] = 40f;
widths[1] = 40f;
widths[2] = 20f;
widths[3] = 300f;
Rectangle r = new Rectangle(PageSize.A4.getRight(72), PageSize.A4.getTop(72));
table.setWidthPercentage(widths, r);
document.add(new Paragraph("We change the percentage using absolute widths:\n\n"));
document.add(table);
document.add(new Paragraph("We use a locked width:\n\n"));
table.setTotalWidth(300);
table.setLockedWidth(true);
document.add(table);
} catch (Exception de) {
de.printStackTrace();
}
// step5
document.close();
}
示例5: 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;
}