本文整理匯總了Java中com.itextpdf.text.pdf.PdfPTable.setLockedWidth方法的典型用法代碼示例。如果您正苦於以下問題:Java PdfPTable.setLockedWidth方法的具體用法?Java PdfPTable.setLockedWidth怎麽用?Java PdfPTable.setLockedWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.itextpdf.text.pdf.PdfPTable
的用法示例。
在下文中一共展示了PdfPTable.setLockedWidth方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onEndPage
import com.itextpdf.text.pdf.PdfPTable; //導入方法依賴的package包/類
@Override
public void onEndPage(PdfWriter writer, Document document) {
PdfPTable table = new PdfPTable(2);
table.setTotalWidth(527);
table.setWidthPercentage(100);
table.setLockedWidth(true);
table.getDefaultCell().setFixedHeight(105f);
table.getDefaultCell().setBorderWidth(0);
table.addCell("");
table.addCell(csmLogoImage);
table.writeSelectedRows(0, -1, 100, 840, writer.getDirectContent());
ColumnText.showTextAligned(writer.getDirectContent(),
Element.ALIGN_LEFT,
new Phrase(lebData.getSchuelername() + " " + lebData.getSchuljahr() + " " + lebData.getSchulhalbjahr().getId() + " Seite " + document.getPageNumber(), fusszeilenFont),
100, 75, 0);
}
示例2: generateFooter
import com.itextpdf.text.pdf.PdfPTable; //導入方法依賴的package包/類
public PdfPTable generateFooter() {
try {
BaseFont baseFont = BaseFont.createFont(/*"resources/ARIAL.TTF"*/ "c:/Windows/Fonts/arial.ttf", BaseFont.IDENTITY_H, true);
footerTable = new PdfPTable(1);
footerTable.setTotalWidth(440);
footerTable.setLockedWidth(true);
Font pageNumberFont = new Font(baseFont, 9, Font.BOLD);
Paragraph pageNumberP = new Paragraph(titleIndex+"-"+ pageNumber, pageNumberFont);
PdfPCell pageNumberCell = new PdfPCell(pageNumberP);
pageNumberCell.setBorder(0);
pageNumberCell.setPaddingTop(20);
footerTable.addCell(pageNumberCell);
} catch (Exception e) {
e.printStackTrace();
}
return footerTable;
}
示例3: createBarcodeTable
import com.itextpdf.text.pdf.PdfPTable; //導入方法依賴的package包/類
private PdfPTable createBarcodeTable(PdfContentByte cb, String caption, String detail, String code) {
// Barcode Generation
Barcode39 codeEAN = new Barcode39();
codeEAN.setCode(code);
Image imageEAN = codeEAN.createImageWithBarcode(cb, null, null);
// Table
PdfPTable table = new PdfPTable(1);
table.setSpacingBefore(10);
table.setSpacingAfter(10);
table.setTotalWidth(80);
table.setLockedWidth(true);
PdfPCell cell1 = new PdfPCell(imageEAN);
PdfPCell cell2 = new PdfPCell(new Paragraph(caption));
PdfPCell cell3 = new PdfPCell(new Paragraph(detail));
cell1.setBorder(Rectangle.NO_BORDER);
cell2.setBorder(Rectangle.NO_BORDER);
cell3.setBorder(Rectangle.NO_BORDER);
table.addCell(cell1);
table.addCell(cell2);
table.addCell(cell3);
return table;
}
示例4: createTable
import com.itextpdf.text.pdf.PdfPTable; //導入方法依賴的package包/類
public PdfPTable createTable(int colNumber) {
PdfPTable table = new PdfPTable(colNumber);
try {
table.setTotalWidth(maxWidth);
table.setLockedWidth(true);
table.setHorizontalAlignment(Element.ALIGN_CENTER);
table.getDefaultCell().setBorder(1);
} catch (Exception e) {
e.printStackTrace();
}
return table;
}
示例5: createTable
import com.itextpdf.text.pdf.PdfPTable; //導入方法依賴的package包/類
public PdfPTable createTable( float widthInPs ){
PdfPTable table = new PdfPTable(1);
table.setTotalWidth(widthInPs);
table.setLockedWidth( true );
table.setSpacingBefore(0);
table.setSpacingAfter(0);
return table;
}
示例6: createPdf
import com.itextpdf.text.pdf.PdfPTable; //導入方法依賴的package包/類
/**
* <a href="http://stackoverflow.com/questions/44005834/changing-rowspans">
* Changing rowspans
* </a>
* <p>
* The original code used by the OP. This code adds the second cell
* with rowspan 2 too early. Fixed in {@link #createPdfFixed(String)}.
* </p>
* @see #testUseRowspanLikeUser7968180()
* @see #addCellToTableCzech(PdfPTable, int, int, String, int, int, String, float)
*/
public void createPdf(String dest) throws IOException, DocumentException {
int horizontalAlignmentCenter = Element.ALIGN_CENTER;
int verticalAlignmentMiddle = Element.ALIGN_MIDDLE;
String fontTypeRegular = "c:/Windows/Fonts/arial.ttf";
float fontSizeRegular = 10f;
float[] columns = { 100, 50, 100, 50, 50, 50, 50, 50, 75, 50, 50, 50 };
int numberOfColumns = columns.length;
Document document = new Document(PageSize.A4.rotate(), 36, 36, 36, 36);
PdfWriter.getInstance(document, new FileOutputStream(dest));
document.open();
PdfPTable subTableZkouska = new PdfPTable(numberOfColumns);
subTableZkouska.setTotalWidth(columns);
subTableZkouska.setLockedWidth(true);
addCellToTableCzech(subTableZkouska, horizontalAlignmentCenter,
verticalAlignmentMiddle, "Brno �pit�lka 8 Brno H�jeck� 1068/14 CZ5159", 1,
2, fontTypeRegular, fontSizeRegular);
addCellToTableCzech(subTableZkouska, horizontalAlignmentCenter,
verticalAlignmentMiddle, "38", 1, 2, fontTypeRegular, fontSizeRegular);
for (int i = 0; i < 19; i++) {
addCellToTableCzech(subTableZkouska, horizontalAlignmentCenter,
verticalAlignmentMiddle, "38", 1, 1, fontTypeRegular,
fontSizeRegular);
}
addCellToTableCzech(subTableZkouska, horizontalAlignmentCenter,
verticalAlignmentMiddle, "38", 1, 1, fontTypeRegular, fontSizeRegular);
document.add(subTableZkouska);
document.close();
}
示例7: createPdfFixed
import com.itextpdf.text.pdf.PdfPTable; //導入方法依賴的package包/類
/**
* <a href="http://stackoverflow.com/questions/44005834/changing-rowspans">
* Changing rowspans
* </a>
* <p>
* The fixed code. This code adds the second cell with rowspan 2
* in twelfth place. Fixed of {@link #createPdf(String)}.
* </p>
* @see #testUseRowspanLikeUser7968180Fixed()
* @see #addCellToTableCzech(PdfPTable, int, int, String, int, int, String, float)
*/
public void createPdfFixed(String dest) throws IOException, DocumentException {
int horizontalAlignmentCenter = Element.ALIGN_CENTER;
int verticalAlignmentMiddle = Element.ALIGN_MIDDLE;
String fontTypeRegular = "c:/Windows/Fonts/arial.ttf";
float fontSizeRegular = 10f;
float[] columns = { 100, 50, 100, 50, 50, 50, 50, 50, 75, 50, 50, 50 };
int numberOfColumns = columns.length;
Document document = new Document(PageSize.A4.rotate(), 36, 36, 36, 36);
PdfWriter.getInstance(document, new FileOutputStream(dest));
document.open();
PdfPTable subTableZkouska = new PdfPTable(numberOfColumns);
subTableZkouska.setTotalWidth(columns);
subTableZkouska.setLockedWidth(true);
addCellToTableCzech(subTableZkouska, horizontalAlignmentCenter,
verticalAlignmentMiddle, "Brno �pit�lka 8 Brno H�jeck� 1068/14 CZ5159", 1,
2, fontTypeRegular, fontSizeRegular);
for (int i = 2; i < 12; i++) {
addCellToTableCzech(subTableZkouska, horizontalAlignmentCenter,
verticalAlignmentMiddle, "38", 1, 1, fontTypeRegular,
fontSizeRegular);
}
addCellToTableCzech(subTableZkouska, horizontalAlignmentCenter,
verticalAlignmentMiddle, "38", 1, 2, fontTypeRegular, fontSizeRegular);
for (int i = 13; i < 23; i++) {
addCellToTableCzech(subTableZkouska, horizontalAlignmentCenter,
verticalAlignmentMiddle, "38", 1, 1, fontTypeRegular,
fontSizeRegular);
}
document.add(subTableZkouska);
document.close();
}
示例8: onRender
import com.itextpdf.text.pdf.PdfPTable; //導入方法依賴的package包/類
@Override
public void onRender( PdfPCell cell ) throws PdfRenderException{
PdfPTable table = new PdfPTable( widths.length );
try{
table.setTotalWidth( getTotalWidthsAsPs() );
table.setLockedWidth( true );
table.setSpacingAfter( 0f );
for( AbstractParagraph tableCell : cells ){
PdfPCell c = new PdfPCell();
float[] padding = new float[]{0f,0f,0f,0f};
if( tableCell instanceof TableCell ){
padding = ((TableCell) tableCell).getPadding();
}
c.setBorderWidth( 0f );
c.setLeft(0);
c.setTop(0);
c.setRight( 0 );
c.setBottom( 0 );
c.setUseAscender( true );
c.setIndent(0);
c.setHorizontalAlignment( Element.ALIGN_LEFT );
c.setVerticalAlignment( Element.ALIGN_TOP );
c.setPaddingLeft( SizeFactory.millimetersToPostscriptPoints(padding[0]));
c.setPaddingBottom( SizeFactory.millimetersToPostscriptPoints(padding[3]) );
c.setPaddingRight( SizeFactory.millimetersToPostscriptPoints(padding[2]) );
c.setPaddingTop(SizeFactory.millimetersToPostscriptPoints(padding[1]));
c.setBorder( 0 );
tableCell.onRender( c );
table.addCell( c );
}
cell.addElement( table );
}catch( Exception e ){
throw new PdfRenderException(e);
}
}
示例9: getFooterTable
import com.itextpdf.text.pdf.PdfPTable; //導入方法依賴的package包/類
public static PdfPTable getFooterTable(int x, int y)
{
java.util.Date date = new java.util.Date();
SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy");
String month = sdf.format(date);
System.out.println("Month : " + month);
PdfPTable table = new PdfPTable(1);
table.setTotalWidth(120);
table.setLockedWidth(true);
table.getDefaultCell().setFixedHeight(20);
table.getDefaultCell().setBorder(Rectangle.TOP);
table.getDefaultCell().setBorder(Rectangle.LEFT);
table.getDefaultCell().setBorder(Rectangle.RIGHT);
table.getDefaultCell().setBorderColorTop(BaseColor.BLUE);
table.getDefaultCell().setBorderColorLeft(BaseColor.BLUE);
table.getDefaultCell().setBorderColorRight(BaseColor.BLUE);
table.getDefaultCell().setBorderWidthTop(1f);
table.getDefaultCell().setBorderWidthLeft(1f);
table.getDefaultCell().setBorderWidthRight(1f);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
Font font1 = new Font(FontFamily.HELVETICA, 10, Font.BOLD, BaseColor.BLUE);
table.addCell(new Phrase("CONTROLLED COPY", font1));
table.getDefaultCell().setFixedHeight(20);
table.getDefaultCell().setBorder(Rectangle.LEFT);
table.getDefaultCell().setBorder(Rectangle.RIGHT);
table.getDefaultCell().setBorderColorLeft(BaseColor.BLUE);
table.getDefaultCell().setBorderColorRight(BaseColor.BLUE);
table.getDefaultCell().setBorderWidthLeft(1f);
table.getDefaultCell().setBorderWidthRight(1f);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
Font font = new Font(FontFamily.HELVETICA, 10, Font.BOLD, BaseColor.RED);
table.addCell(new Phrase(month, font));
table.getDefaultCell().setFixedHeight(20);
table.getDefaultCell().setBorder(Rectangle.LEFT);
table.getDefaultCell().setBorder(Rectangle.RIGHT);
table.getDefaultCell().setBorder(Rectangle.BOTTOM);
table.getDefaultCell().setBorderColorLeft(BaseColor.BLUE);
table.getDefaultCell().setBorderColorRight(BaseColor.BLUE);
table.getDefaultCell().setBorderColorBottom(BaseColor.BLUE);
table.getDefaultCell().setBorderWidthLeft(1f);
table.getDefaultCell().setBorderWidthRight(1f);
table.getDefaultCell().setBorderWidthBottom(1f);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(new Phrase("BLR DESIGN DEPT.", font1));
return table;
}
示例10: PDFLabelMaker
import com.itextpdf.text.pdf.PdfPTable; //導入方法依賴的package包/類
public PDFLabelMaker(LabelPage margins, OutputStream output) throws IOException, DocumentException {
this.margins = margins;
float sides, page, h, w, labelGap;
// calculate the number of labels wide this page is
page = margins.getPageSize().getWidth();
labelGap = margins.getLabelHorizontalGap();
w = margins.getLabelWidth();
sides = margins.getPageLeftMargin() + margins.getPageRightMargin();
if(sides + w > page)
throw new IllegalArgumentException("0 labels fit across");
for(int i = 1; sides + (((float)i) * w) + (((float)(i - 1)) * labelGap) <= page; i++) {
nAcross = i;
}
// the number of labels 'tall'
page = margins.getPageSize().getHeight();
labelGap = margins.getLabelVerticalGap();
h = margins.getLabelHeight();
sides = margins.getPageTopMargin() + margins.getPageBottomMargin();
if(sides + h > page)
throw new IllegalArgumentException("0 labels fit down");
for(int i = 1; sides + (((float)i) * h) + (((float)(i - 1)) * labelGap) <= page; i++) {
nDown = i;
}
System.out.println("LABELS: across: " + nAcross + ", down: " + nDown);
document = new Document(margins.getPageSize());
PdfWriter writer = PdfWriter.getInstance(document, output);
document.addAuthor("Tellervo Label Generator");
document.addCreationDate();
document.open();
contentb = writer.getDirectContent();
// first off, pdfs are weird and go from high y coordinates to low for pages (ie, highest y = top of page)
// also, this sets the page margins
new ColumnText(contentb).setSimpleColumn(
margins.getPageLeftMargin(), // lower x margin
margins.getPageBottomMargin(), // bottom y margin
margins.getPageSize().getWidth() - (margins.getPageRightMargin() + margins.getPageLeftMargin()), // upper x margin
margins.getPageSize().getHeight() - (margins.getPageTopMargin() + margins.getPageBottomMargin()), // upper y margin
0, // no leading
Element.ALIGN_MIDDLE // align in the middle of the label
);
int realCols = nAcross + nAcross - 1; // number of labels + number of intra-label gaps
float colwidth[] = new float[realCols];
float totalWidth = 0;
for(int i = 0; i < realCols; i++) {
if((i & 1) == 1) {
// odd, so it's a margin
totalWidth += margins.getLabelHorizontalGap();
colwidth[i] = margins.getLabelHorizontalGap();
}
else {
// even, so it's an actual label
totalWidth += margins.getLabelWidth();
colwidth[i] = margins.getLabelWidth();
}
}
table = new PdfPTable(realCols);
table.setTotalWidth(totalWidth);
table.setWidths(colwidth);
table.setLockedWidth(true);
table.getDefaultCell().setPadding(0);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_MIDDLE);
table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
}