PDFBox: How to “flatten” a PDF-form?

后端 未结 11 2186
难免孤独
难免孤独 2020-12-09 06:32

How do I \"flatten\" a PDF-form (remove the form-field but keep the text of the field) with PDFBox?

Same question was answered here:

a quick

11条回答
  •  眼角桃花
    2020-12-09 07:00

    This is the answer of Thomas, from the PDFBox-Mailinglist:

    You will need to get the Fields over the COSDictionary. Try this code...

    PDDocument pdDoc = PDDocument.load(new File("E:\\Form-Test.pdf"));
    PDDocumentCatalog pdCatalog = pdDoc.getDocumentCatalog();
    PDAcroForm acroForm = pdCatalog.getAcroForm();
    
    COSDictionary acroFormDict = acroForm.getDictionary();
    COSArray fields = acroFormDict.getDictionaryObject("Fields");
    fields.clear();
    

提交回复
热议问题