2012-07-12 107 views
1

我使用iText生成PDF並希望包含iText Form和TextField,以便用戶可以以電子方式填寫PDF表單,而不是將其打印出來。橫向頁面上的iText TextField - 輸入文本不旋轉

我已經按照這裏的例子:http://itextpdf.com/examples/iia.php?id=161

這裏:http://itextpdf.com/examples/iia.php?id=162

到目前爲止,我有我的風景PDF一個TextField,我可以點擊和輸入文字。

我有兩個問題:

  1. 文本字段對齊。要點擊文本字段,我必須將鼠標放在我添加TextField的單元格的右側。我怎樣才能將TextField與單元格對齊?
  2. 已輸入文字旋轉。一旦我輸入了文字,它就會以旋轉的方式顯示,並以90度的角度顯示在頁面的其餘部分。我怎樣才能設置這個顯示文字的旋轉?

輸入文字的旋轉是最讓我失望的東西。我試過設置單元格和TextField上的旋轉,但似乎沒有效果。

有什麼建議嗎?

感謝

這裏是我的代碼:

int rotation = document.getPageSize().getRotation(); 

    PdfFormField pdfForm = PdfFormField.createEmpty(docWriter); 
    coverSheetPdfForm.setFieldName("Form"); 
    coverSheetPdfForm.setRotate(rotation); 

    ... 

    cell = new PdfPCell(borderedTable("Cell Title:", tblHeadingFont, "", borderColor)); 
    cell.setColspan(1); 
    cell.setPadding(5f); 
    cell.setBorderWidth(0f); 
    cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); 
    cell.setMinimumHeight(100f); 

    TextField textField = new TextField(docWriter, new Rectangle(50, 50,rotation), "cell_text_field"); 
    textField.setFontSize(12); 
    textField.setRotation(rotation); 
    textField.setVisibility(TextField.VISIBLE); 
    textField.setBorderColor(borderColor); 
    textField.setBorderWidth(BORDER_WIDTH); 

    cell.setCellEvent(new ChildFieldEvent(pdfForm, textField.getTextField(), 1, rotation)); 

    ..... 

    docWriter.addAnnotation(pdfForm); 

而且,我已經從示例頁面借用ChildFieldEvent代碼,並增加了旋轉的額外的參數:

/** 
* Creates a ChildFieldEvent. 
* @param parent the parent field 
* @param kid the child field 
* @param padding a padding 
* @param rotation 
*/ 
public ChildFieldEvent(PdfFormField parent, PdfFormField kid, float padding, int rotation) { 
    this.parent = parent; 
    this.kid = kid; 
    this.padding = padding; 
    this.rotation = rotation; 
} 

/** 
* Add the child field to the parent, and sets the coordinates of the child field. 
* @param cell 
* @param rect 
* @param cb 
* @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, 
*  com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[]) 
*/ 
@Override 
public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] cb) { 
    try { 
     parent.addKid(kid); 
     kid.setWidget(new Rectangle(rect.getLeft(padding), rect.getBottom(padding), 
       rect.getRight(padding), rect.getTop(padding),rotation), 
       PdfAnnotation.HIGHLIGHT_INVERT); 
    } catch (Exception e) { 
     throw new ExceptionConverter(e); 
    } 
} 

回答

1

我已經做了一些更多的測試,看起來像Ubuntu PDF fiewer(文檔查看器)不能正確地呈現PDF,因爲在Windows Adob​​e PDF Viewer中查看同一個文件,窗體外觀很好。

我會做更多的測試並回報。