Hello,

I am creating a PdfPTable that has two columns only. The column on the left is 
simply a label i.e. read-only text. The right column is a TextField that is 
editable but populated with default text. The code for achieving this in 
included below.

The behavior of the TextField inside the PdfPCell is two either grow or shrink 
to fit the horizontal space of the column. However, I would prefer the behavior 
to be a fixed font size e.g. 10 and grow in multi-line or multi-row instead of 
adjusting the text size. Can that be done? How? I have the iText in Action book 
available but can't find the answer.

Thanks in advance,
Best regards,
Giovanni

Document document = new Document(PageSize.A4);
document.newPage();
PdfWriter writer = PdfWriter.getInstance(document, new 
FileOutputStream("letter.pdf"));
document.open();
appendContent(writer);
document.close();

private static void appendContent(PdfWriter writer) throws Exception {          
    // prepare values
    Map<String, String> values = new HashMap<String, String>();     
    values.put("ph0013", "XXXXXXXXXXXXX AG");
    values.put("ph0006", "Kontokorrent in GBP Nr. XXXX-XXXXXX-XX Salärkonto");
    values.put("ph0007", "IBAN-Nr. CHXX XXXX XXXX XXXX XXXX X");
    values.put("ph0008", "Derzeit 1.000% im Jahr abzüglich 35% 
Verrechnungssteuer");
    values.put("ph0009", "4835");
    values.put("ph0010", "CRESCHZZ80A");
    values.put("ph0011", "Porti und Spesen werden direkt dem Konto belastet");
    values.put("ph0012", "vierteljährlich");
    values.put("ph0005", "Ohne Ihren Gegenbericht gilt für dieses Konto die " +
        "gleiche Verfügungsberechtigung wie für alle bestehenden Konten.");
    values.put("ph0014", "Im übrigen gelten die 'Allgemeinen 
Geschäftsbedingungen' " +
          "unserer Bank.'");

    // prepare names
    Map<String, String> names = new HashMap<String, String>();      
    names.put("ph0013", "Kunde");
    names.put("ph0006", "Kontoart");
    names.put("ph0007", "");
    names.put("ph0008", "Zinsvergütung");
    names.put("ph0009", "Clearingnummer");
    names.put("ph0010", "Swiftadresse");
    names.put("ph0011", "Porti/ Spesen");
    names.put("ph0012", "Kontoabschluss");
    names.put("ph0005", "Verfügungsberechtigung");
    names.put("ph0014", "Übrige Bestimmungen");         

    // define row order
    List<String> rowOrder = new ArrayList<String>(names.keySet());        
    Collections.sort(rowOrder);

    int columnsCount = 2;
    PdfPTable table = new PdfPTable(columnsCount);
    table.setWidths(new float[] { 100.f, 350.f});
    for (String rowKey : rowOrder) {
        String name = names.get(rowKey);
          String value = values.get(rowKey);
                        
          PdfPCell leftColumn = new PdfPCell(new Paragraph(new Phrase(name, 
CREDIT_SUISSE_TYPE_LIGHT)));
          leftColumn.setBorder(PdfPCell.NO_BORDER);
          leftColumn.setPaddingBottom(8.f);
          table.addCell(leftColumn);

          Rectangle rectangle = new Rectangle(0,0,200,20);
          rectangle.setBorder(0);
          TextField field = new TextField(writer, rectangle, value);
               
          field.setBorderStyle((int)TextField.BORDER_WIDTH_MEDIUM);
          field.setText(value);
          field.setFont(CREDIT_SUISSE_TYPE_LIGHT.getBaseFont());
          field.setAlignment(Element.ALIGN_LEFT);
                   
          PdfPCell rightColumn = new PdfPCell();
          FieldPositioningEvents events = new FieldPositioningEvents(writer, 
field.getTextField());
          rightColumn.setCellEvent(events);
          rightColumn.setBorder(PdfPCell.NO_BORDER);
          rightColumn.setPaddingBottom(8.f);
          rightColumn.setMinimumHeight(20.f); 
          table.addCell(rightColumn);
    }        
        
    float xOffset = 70;
    float yOffset = 450;
    PdfContentByte content = writer.getDirectContent();
    table.setTotalWidth(500);
    table.writeSelectedRows(0, -1, xOffset, yOffset, content);        
}

==============================================================================
Please access the attached hyperlink for an important electronic communications 
disclaimer:

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
============================================================================== 

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to