如何将PDFormField的内容居中?

huangapple go评论92阅读模式
英文:

How to center the content of a PDFormField?

问题

可以尝试将我的PDFormField内容居中吗?现在的方式是,它只是从左到右填充字段。

英文:

Let's say I'm filling a PDF using AcroForms.

File blankDocument = new File("blank-document.pdf");
PDDocument document = PDDocument.load(blankDocument);
PDDocumentCatalog catalog = document.getDocumentCatalog();
PDAcroForm acroForm = catalog.getAcroForm();

for (PDFormField formField : acroForm.getFields()) {
    if (formField.getPartialName().equals("name")) {
         formField.setValue("Allan");
    }
}

document.save("filled_document.pdf");

Is it possible to center the content of my PDFormField? The way it is now, it justs fills the field from left to right.

答案1

得分: 2

在调用setValue()之前,请执行以下操作:

if (formField instanceof PDVariableText)
{
    PDVariableText txtFormField = (PDVariableText) formField;
    txtFormField.setQ(PDVariableText.QUADDING_CENTERED);
}
英文:

before calling setValue(), do this:

if (formField instanceof PDVariableText)
{
    PDVariableText txtFormField = (PDVariableText) formField;
    txtFormField.setQ(PDVariableText.QUADDING_CENTERED);
}

huangapple
  • 本文由 发表于 2020年8月19日 19:53:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/63486407.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定