Anil Bhendarkar
Anil Bhendarkar

Reputation: 51

PDFBox: How to “flatten” a PDF-form? Tried suggested answer but It's not working

I am Flatten the pdf using PDFBOX,but flatten the PDF is not working.What is missing in the code .

As per documentation I tried pdAcroForm.flatten(); but this is not producing flattened file

public class SampleConvert {

    public static void main(String[] args) {

try
{
PDDocument doc = PDDocument.load(newFile("C:\\Users\\admin\\Extract\\Output\\Sample.pdf"));

PDAcroForm pdAcroForm = doc.getDocumentCatalog().getAcroForm(); 
//pdAcroForm.setNeedAppearances(true); //With or without is also not working
pdAcroForm.flatten();

doc.save("C:\\Users\\admin\\Extract\\Output\\Sample_out.pdf");
doc.close();
System.out.println("Done");
}
catch(Exception e)
{
e.printStackTrace();
}

}
}

Expected result : is the Flattened file

Actual result coming : Same as original file (Which is wrong)

EDIT1: link for the pdf https://www.dropbox.com/sh/6bbjz1fyiaz5z7b/AAB2d4KspbLKDgsGLLjhwOgwa?dl=0

Input : Sample.pdf Output :Sample_out.pdf (Generated by code)

[Note : PDF is XFA form PDF so it might not be view able directly .Need to convert to or open in adobe ]

Upvotes: 2

Views: 1437

Answers (0)

Related Questions