Java 横向页面上的iText文本字段-输入文本未旋转

Java 横向页面上的iText文本字段-输入文本未旋转,java,pdf-generation,itext,textfield,pdf-form,Java,Pdf Generation,Itext,Textfield,Pdf Form,我正在使用iText生成一个PDF,并希望包含一个iText表单和文本字段,以便用户可以以电子方式填写PDF表单,而不是打印出来 我在这里遵循了以下示例: 在这里: 到目前为止,我的横向PDF上有一个文本字段,我可以单击并输入文本 我有两个问题: 文本字段对齐。要单击文本字段,我必须将鼠标放在我添加文本字段的单元格右侧。如何将文本字段与单元格对齐 输入文本旋转。一旦我输入了文本,它就会旋转显示,并与页面的其余部分成90度角。如何设置此显示文本的旋转 输入文本的旋转是最让我烦恼的事情。我试着在单元

我正在使用iText生成一个PDF,并希望包含一个iText表单和文本字段,以便用户可以以电子方式填写PDF表单,而不是打印出来

我在这里遵循了以下示例:

在这里:

到目前为止,我的横向PDF上有一个文本字段,我可以单击并输入文本

我有两个问题:

  • 文本字段对齐。要单击文本字段,我必须将鼠标放在我添加文本字段的单元格右侧。如何将文本字段与单元格对齐
  • 输入文本旋转。一旦我输入了文本,它就会旋转显示,并与页面的其余部分成90度角。如何设置此显示文本的旋转
  • 输入文本的旋转是最让我烦恼的事情。我试着在单元格和文本字段上设置旋转,但似乎没有效果

    有什么建议吗

    谢谢

    这是我的密码:

        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);
        }
    } 
    

    我做了更多的测试,看起来Ubuntu PDF浏览器(Document Viewer)没有正确呈现PDF,因为在Windows Adobe PDF Viewer中查看同一个文件时,表单看起来很好


    我会做更多的测试并报告。

    我做了更多的测试,看起来Ubuntu PDF浏览器(Document Viewer)没有正确呈现PDF,因为在Windows Adobe PDF Viewer中查看相同的文件,表单看起来很好

    我会做更多的测试并报告