2016-08-18 3 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'를 만들고, 열 크기를 설정하고, 내용을 추가하고'go()'메서드를 사용하는 대신'ColumnText.showTextAligned()'를 사용하고있을 것입니다. 나는 Alexey와 동의한다. 코드를 보여주지 않으면 더 정교한 답을 기대해서는 안됩니다. –

+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는 한 줄 텍스트 입력란을 여러 줄 텍스트 입력란으로 변경합니다.

multi line field 예의 경우 official documentation을 참조하십시오.

+0

감사합니다. @ 브루노 로지기 –