如何(水平)对齐 PDFBox 中 PDTextField 的文本?

How to (horizontally) align text of PDTextField in PDFBox?(如何(水平)对齐 PDFBox 中 PDTextField 的文本?)
本文介绍了如何(水平)对齐 PDFBox 中 PDTextField 的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个程序可以在 PDF 文件中创建文本字段,以便将其用作表单.我想让我在我创建的 TextFields 中写的文本居中.这怎么可能?我的代码目前如下所示:

I have a program that create TextFields inside a PDF-file so it can be used as a form. I would like to have the text I write in the TextFields I created to be centered though. How is that possible? My code currently looks like this:

PDTextField textBox = new PDTextField(acroForm);
textBox.setPartialName("Field " + j + " " + i);
defaultAppearanceString = "/Helv 8 Tf 0 g"; //Textsize: 8
textBox.setDefaultAppearance(defaultAppearanceString);
acroForm.getFields().add(textBox);

PDAnnotationWidget widget = textBox.getWidgets().get(0);
PDRectangle rect = new PDRectangle(inputField.getX(), inputField.getY(), inputField.getWidth(), inputField.getHeight());
widget.setRectangle(rect);
widget.setPage(page);
widget.setPrinted(true);
page.getAnnotations().add(widget);

我想到了一个简单的函数来对齐这样的文本:

and I thought of an easy function to align text like this:

textBox.setAlignment(Alignment.CENTER);

但我没找到.

推荐答案

使用 Q 标志:

textBox.setQ(PDTextField.QUADDING_CENTERED);

其他可能的值是 QUADDING_RIGHT 和 QUADDING_LEFT(这是默认值).

Other possible values are QUADDING_RIGHT and QUADDING_LEFT (which is the default).

这篇关于如何(水平)对齐 PDFBox 中 PDTextField 的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

quot;Char cannot be dereferencedquot; error(“Char 不能被取消引用错误)
Java Switch Statement - Is quot;orquot;/quot;andquot; possible?(Java Switch 语句 - 是“或/“和可能的?)
Java Replace Character At Specific Position Of String?(Java替换字符串特定位置的字符?)
What is the type of a ternary expression with int and char operands?(具有 int 和 char 操作数的三元表达式的类型是什么?)
Read a text file and store every single character occurrence(读取文本文件并存储出现的每个字符)
Why do I need to explicitly cast char primitives on byte and short?(为什么我需要在 byte 和 short 上显式转换 char 原语?)