私は iText を使用して PDF を生成しています。ユーザーが PDF フォームを印刷するのではなく電子的に入力できるように、iText フォームと TextFields を含めたいと考えていました。
ここの例に従いました:http://itextpdf.com/examples/iia.php?id=161
そしてここ:http://itextpdf.com/examples/iia.php?id=162
これまでのところ、Landscape PDF に TextField があり、クリックしてテキストを入力できます。
2 つの問題があります。
- TextField の配置。テキスト フィールドをクリックするには、TextField も追加したセルの右側にマウスを配置する必要があります。TextField をセルに揃えるにはどうすればよいですか?
- 文字の回転を入力しました。テキストを入力すると、ページの残りの部分に対して 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);
}
}