2016-08-18 7 views
0

私は自分のPDFフォームにテーブルを持っていますが、PdfpCelleventヘルパーを使ってテキストフィールドを行に挿入しましたが、テキストフィールドに値を入力できます。セルフィールド。制限長PdfPCellEvent

どのようにして、pdfPcellevent内の可視領域の長さを制限することができますか?

static class MyCellField implements PdfPCellEvent{ 
    public String fieldname; 
    public MyCellField(String fieldname){ 
    this.fieldname= fieldname; 
    } 
    @Override 

    public void cellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases) { 
    final PdfWriter writer = canvases[0].getPdfWriter(); 
    final TextField textField = new TextField(writer, rectangle, fieldname); 
    try { 
     final PdfFormField field = textField.getTextField(); 
     writer.addAnnotation(field); 
    } catch (final IOException | DocumentException ioe) { 
     throw new ExceptionConverter(ioe); 
    } 
} 
} 

    private static PdfPCell createPdfCell(String phrase, String eventValue){ 
     PdfPCell pdfCell = new PdfPCell(); 
     pdfCell.addElement(new Phrase(phrase, FontFactory.getFont(FontFactory.TIMES, 11))); 
     pdfCell.setVerticalAlignment(Element.ALIGN_MIDDLE); 
     pdfCell.setBorderColor(BaseColor.BLACK); 
     pdfCell.setPadding(2); 
     pdfCell.getFixedHeight(); 
     pdfCell.setCellEvent(new MyCellField(eventValue)); 
     pdfCell.setRowspan(3); 
     return pdfCell; 
} 

現在何を表示下図:

enter image description here

+0

あなたのコードと期待される動作を教えてください –

+0

'ColumnText'を作成する代わりに' ColumnText.showTextAligned() 'を使用し、カラムサイズを設定し、内容を追加し、' go() 'メソッドを使用しています。私はアレクセイに同意する。あなたがコードを表示しないと、もっと精巧な答えを期待するべきではありません。 –

+0

今はっきりしています。単一行のフィールドがあり、それを複数行のフィールドにしたいとします。それは簡単です。 –

答えて

0

あなたはあなたがこれをしたいと言う:

enter image description here

と以下の一つは、私が期待するものである

enter image description here

つまり、複数行のテキストフィールドが必要です。

あなたはこの取得:

enter image description here

これらは、単一行のフィールドであり、あなたがこのようなあなたのフィールドを作成するのでそれは、普通です:

TextField textField = new TextField(writer, rectangle, fieldname); 
PdfFormField field = textField.getTextField(); 

あなたはこのようなあなたのフィールドを作成する必要があります代わりに:

TextField textField = new TextField(writer, rectangle, fieldname); 
textField.setOptions(TextField.MULTILINE); 
PdfFormField field = textField.getTextField(); 

オプションTextField.MULTILINEは、1行のテキストフィールドを複数行テキストフィールドに変更します。

さらにmulti line fieldの例については、official documentationを参照してください。

+0

ありがとう、それは働いた! @ブルノ・ロワジエ –