I have a URL:
http://www.irs.gov/pub/irs-pdf/fw4.pdf
It contains an editable PDF. I have make it non-editable. I did so and kept it in the temp directory of a folder. Now i want to send the non-editable PDF as a response, when the user clicks this url, he must get the non-editable pdf. This is what I have done till now:
String strDirectoy ="C:\\Temp";
boolean success = (
new File(strDirectoy)).mkdir();
if (success) {
System.out.println("Directory: "
+ strDirectoy + " created");
}
PdfReader reader = new PdfReader("http://www.irs.gov/pub/irs-pdf/fw4.pdf");//C:\\fw4.pdf
PdfStamper stamp2 = new PdfStamper(reader, new FileOutputStream("C:\\Temp\\Flattened.pdf"));
AcroFields form2 = stamp2.getAcroFields();
stamp2.setFormFlattening(true);
stamp2.close();
Now i need to delete the temp
folder as if it never existed and return the non-editable PDF as the response for the above specified URL.
How can i do this?
createTempFile()
and deleteOnExit()
methods of java.io.File
). setContentType
of the HttpServletResponse to set the MIME type of the pdf.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.