How to get font size of form field on iText7?

穿精又带淫゛_ 提交于 2019-12-07 04:34:25

I managed to did it. But I am not sure if this is a straight forward way.

try (PdfDocument readDoc = new PdfDocument(new PdfReader(SRC))) {
  PdfAcroForm pdfAcroForm = PdfAcroForm.getAcroForm(readDoc, false);
  PdfFormField field = pdfAcroForm.getField(FIELDNAME);
  PdfString defaultAppearance = field.getDefaultAppearance(); // like "/MSGothic 9 Tf 0 g" 
  float fontSize;
  if (defaultAppearance != null) {
    String[] array = defaultAppearance.toString().split(" ");
    if (array.length > 2) {
      fontSize = Float.parseFloat(array[1]);
    }
  }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!