2016-08-18 68 views
0

我有一个表在我的PDF表格,我已经使用PdfpCellevent帮手插入行文本字段,但是我能值输入到文本字段,它只是流过中的不可见部分细胞领域。极限长度PdfPCellEvent

如何限制在iText的一个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

和下面的一个是我所期望的:

enter image description here

+0

请向我们展示您的代码和预期行为 –

+0

您可能正在使用'ColumnText.showTextAligned()'而不是创建'ColumnText',设置列大小,添加内容并使用'go()'方法。我同意阿列克谢。如果你不显示任何代码,你不应该期待更详细的答案。 –

+0

现在很明显。你有一个单行字段,你希望它是一个多行字段。这很容易。 –

回答

0

你说你要这样:

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会将您的单行文本字段更改为多行文本字段。

official documentation一些更multi line field例子。

+0

谢谢你,它工作! @BrunoLowagie –