Java Code Examples for com.itextpdf.text.pdf.PdfPTable#setLockedWidth()
The following examples show how to use
com.itextpdf.text.pdf.PdfPTable#setLockedWidth() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DynamicFooter.java From testarea-itext5 with GNU Affero General Public License v3.0 | 11 votes |
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; }
Example 2
Source File: UseRowspan.java From testarea-itext5 with GNU Affero General Public License v3.0 | 5 votes |
/** * <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(); }
Example 3
Source File: UseRowspan.java From testarea-itext5 with GNU Affero General Public License v3.0 | 5 votes |
/** * <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(); }
Example 4
Source File: AddField.java From testarea-itext5 with GNU Affero General Public License v3.0 | 4 votes |
/** * <a href="http://stackoverflow.com/questions/35630320/itext-java-android-adding-fields-to-existing-pdf"> * iText - Java Android - Adding fields to existing pdf * </a> * <p> * There actually are two issues in the OP's code: * </p> * <ol> * <li>he creates the fields with empty names * <li>he doesn't set border colors for his fields * </ol> * <p> * These issues are fixed in {@link #testAddLikePasquierCorentin()}, * {@link CheckboxCellEvent}, and {@link MyCellField} below. * </p> */ @Test public void testAddLikePasquierCorentin() throws IOException, DocumentException { File myFile = new File(RESULT_FOLDER, "preface-withField.pdf"); try ( InputStream resource = getClass().getResourceAsStream("/mkl/testarea/itext5/extract/preface.pdf"); OutputStream output = new FileOutputStream(myFile) ) { PdfReader pdfReader = new PdfReader(resource); pdfStamper = new PdfStamper(pdfReader, output); PdfContentByte canvas1; PdfContentByte canvas2; canvas1 = pdfStamper.getOverContent(1); canvas2 = pdfStamper.getOverContent(2); PdfPCell cellFillFieldPage1 = new PdfPCell(); // change: Use a non-empty name cellFillFieldPage1.setCellEvent(new MyCellField("A", 1)); cellFillFieldPage1.setFixedHeight(15); cellFillFieldPage1.setBorder(Rectangle.NO_BORDER); cellFillFieldPage1.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cellCheckBoxPage2 = new PdfPCell(); // change: Use a non-empty name different from the one above cellCheckBoxPage2.setCellEvent(new CheckboxCellEvent("B", false, 2)); cellCheckBoxPage2.setBorder(Rectangle.NO_BORDER); // ************** PAGE 1 ************** // // SET TABLE PdfPTable tableSection1Page1 = new PdfPTable(1); tableSection1Page1.setTotalWidth(136); tableSection1Page1.setWidthPercentage(100.0f); tableSection1Page1.setLockedWidth(true); // ADD CELLS TO TABLE tableSection1Page1.addCell(cellFillFieldPage1); // PRINT TABLES tableSection1Page1.writeSelectedRows(0, -1, 165, 530, canvas1); // ************ PAGE 2 ************ // // SET TABLES PdfPTable tableSection1Page2 = new PdfPTable(1); tableSection1Page2.setTotalWidth(10); tableSection1Page2.setWidthPercentage(100.0f); tableSection1Page2.setLockedWidth(true); // ADD CELLS TO TABLE tableSection1Page2.addCell(cellCheckBoxPage2); // PRINT TABLES tableSection1Page2.writeSelectedRows(0, -1, 182, 536, canvas2); // I tried this, but it didn't change anything pdfStamper.setFormFlattening(false); pdfStamper.close(); pdfReader.close(); } }
Example 5
Source File: FindFreeSpace.java From testarea-itext5 with GNU Affero General Public License v3.0 | 4 votes |
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; }