【问题标题】:PDF itext form.setField How does text display center vertically?PDF itext form.setField 文本如何垂直居中显示?
【发布时间】:2020-01-29 10:08:31
【问题描述】:

我用adobeDC制作了一个PDF模板,我在模板中添加了表单字段,现在我想让表单中的文本垂直居中,但是setFieldProperty()方法不能垂直居中文本,现在我想要com.itextpdf。 text.但是这一段可能需要绝对定位,但是不知道有多少文字内容,想知道有没有简单的方法,请帮帮我

导出的PDF主要用于打印

jar 版本:itextpdf-5.5.0.jar

form.setField(name, top+map.get(name));

【问题讨论】:

    标签: itext


    【解决方案1】:
    int pageNo = form.getFieldPositions(name).get(0).page;
    Rectangle signRect = form.getFieldPositions(name).get(0).position;
    float x = signRect.getLeft();
    float y = signRect.getBottom();
    PdfContentByte under = ps.getOverContent(pageNo);
    ColumnText column = new ColumnText(under);
    PdfPTable table = new PdfPTable(1);
    PdfPCell pdfCell = new PdfPCell();
    pdfCell.setMinimumHeight(40);
    pdfCell.disableBorderSide(15);
    pdfCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    Font font2 = new Font(bfChinese, 7,Font.NORMAL);
    Paragraph paragraph = new Paragraph(map.get(name),font2);
    pdfCell.setPhrase(paragraph);
    table.addCell(pdfCell);
    column.addElement(table);column.setSimpleColumn(signRect.getLeft()-25,signRect.getBottom(),signRect.getRight()+25,signRect.getTop());
    column.go();
    

    【讨论】:

    • 请注意,您的代码确实不再填写表单域,而是在表单域下方的静态内容中绘制某些内容或更准确地说是在表单字段的第一个小部件下。如果之后要以编程方式读取您的 PDF 填充,则将找不到它们。
    • 首先感谢警告。由于我导出的PDF是打印出来的,所以上面的代码符合我的要求。
    猜你喜欢
    • 1970-01-01
    • 2013-10-15
    • 1970-01-01
    • 1970-01-01
    • 2011-07-23
    • 1970-01-01
    • 1970-01-01
    • 2015-09-16
    相关资源
    最近更新 更多