Мой пример кода выглядит следующим образом:
Код: Выделить всё
public static void main(String[] args) throws IOException {
try (PDDocument doc = PDDocument.load(Main.class.getResourceAsStream("/pdf/template.pdf"))) {
// Access the AcroForm
PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm();
PDType0Font load = PDType0Font.load(doc, new File("C:/windows/fonts/arial.ttf"));
PDResources resources = acroForm.getDefaultResources();
if (resources == null) {
resources = new PDResources();
acroForm.setDefaultResources(resources);
}
String fontName = resources.add(load).getName();
String defaultAppearanceString = "/" + fontName + " 12 Tf 0 g";
acroForm.setDefaultResources(resources);
PDTextField myField = (PDTextField) acroForm.getField("field");
myField.setDefaultAppearance(defaultAppearanceString);
myField.getWidgets().get(0).setAppearance(null);
myField.setValue("ŞŞ"); // Text with the Ş character
// Save the updated document
doc.save("target/SimpleFormWithCorrectFont.pdf");
}
}
U+015E («Scedilla») недоступен в шрифте Helvetica, кодировка: WinAnsiEncoding
Я пробовал разные шрифты и разные методы добавления шрифта в pdfbox, но ошибка та же.
Какая у меня ошибка?
Подробнее здесь: https://stackoverflow.com/questions/792 ... -exception
Мобильная версия