pdfbox java.io.IOException: Page tree root must be a dictionary
示例代码
public static void main(String[] args) {
try (InputStream sampleInputs = new ClassPathResource("sample/untitle2.pdf").getInputStream();
PDDocument doc = PDDocument.load(sampleInputs, MemoryUsageSetting.setupTempFileOnly())) {
// get the document catalog
PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm();
// as there might not be an AcroForm entry a null check is necessary
if (acroForm != null) {
// Retrieve an individual field and set its value.
PDTextField field = (PDTextField) acroForm.getField("sampleField");
field.setValue("Text Entry");
// If a field is nested within the form tree a fully qualified name
// might be provided to access the field.
field = (PDTextField) acroForm.getField("fieldsContainer.nestedSampleField");
field.setValue("Text Entry");
}
// Save and close the filled out form.
// doc.save("target/FillFormField.pdf");
} catch (IOException e) {
e.printStackTrace();
}
}
maven 中添加配置
org.springframework.boot
spring-boot-maven-plugin
maven-resources-plugin
参考:http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html