Created
February 22, 2020 17:18
-
-
Save dotemacs/ff9fb8ccf11abeb2ac6c1c461f2c1eb9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.IOException; | |
import org.apache.pdfbox.pdmodel.PDDocument; | |
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm; | |
import org.apache.pdfbox.pdmodel.interactive.form.PDField; | |
public class Flatten | |
{ | |
public static void main(String[] args) throws IOException { | |
PDDocument doc = PDDocument.load(new File("interactiveform.pdf")); | |
PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm(); | |
for (PDField field : acroForm.getFields()) | |
{ | |
field.setReadOnly(true); | |
} | |
doc.getDocumentCatalog().getAcroForm().flatten(); | |
doc.save("new.pdf"); | |
doc.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment