Skip to content

Instantly share code, notes, and snippets.

@dotemacs
Created February 22, 2020 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotemacs/ff9fb8ccf11abeb2ac6c1c461f2c1eb9 to your computer and use it in GitHub Desktop.
Save dotemacs/ff9fb8ccf11abeb2ac6c1c461f2c1eb9 to your computer and use it in GitHub Desktop.
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