fields.setFieldProperty(fieldName, "textsize", fontSize, null);设置字体大小不生效
时间: 2024-03-17 21:41:03 浏览: 19
如果 `fields.setFieldProperty(fieldName, "textsize", fontSize, null)` 不起作用,可能是因为您使用的字体不支持指定的字体大小。在设置字体大小之前,您可以先检查一下使用的字体是否支持您想要的字体大小。您可以使用以下代码来列出可用字体及其属性:
```
AcroFields fields = pdfStamper.getAcroFields();
List<AcroFields.FieldPosition> positions = fields.getFieldPositions(fieldName);
for (AcroFields.FieldPosition position : positions) {
PdfDictionary dict = fields.getFieldItem(fieldName).getMerged(0);
PdfDictionary appearance = dict.getAsDict(PdfName.AP);
if (appearance != null) {
PdfStream normalAppearance = appearance.getAsStream(PdfName.N);
PdfDictionary resources = normalAppearance.getAsDict(PdfName.RESOURCES);
if (resources != null) {
for (PdfName fontName : resources.getAsDict(PdfName.FONT).getKeys()) {
PRIndirectReference fontReference = resources.getAsDict(PdfName.FONT).getAsIndirectObject(fontName);
PdfObject font = PdfReader.getPdfObject(fontReference);
System.out.println("Font Name: " + fontName.toString());
System.out.println("Font Properties: " + font.toString());
}
}
}
}
```
如果字体不支持您想要的字体大小,您可以尝试使用其他字体或调整字体大小以使其适合所选字体。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![mp4](https://img-home.csdnimg.cn/images/20210720083504.png)