[英]How to return a non-editable PDF as a response?
I have a URL: 我有一个网址:
http://www.irs.gov/pub/irs-pdf/fw4.pdf http://www.irs.gov/pub/irs-pdf/fw4.pdf
It contains an editable PDF. 它包含一个可编辑的PDF。 I have make it non-editable.
我已将其设为不可编辑。 I did so and kept it in the temp directory of a folder.
我这样做了,并将其保存在文件夹的temp目录中。 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.
现在,我想发送不可编辑的PDF作为响应,当用户单击此URL时,他必须获取不可编辑的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. 现在,我需要删除
temp
文件夹,就好像它根本不存在一样,并返回不可编辑的PDF作为上述指定URL的响应。
How can i do this? 我怎样才能做到这一点?
createTempFile()
and deleteOnExit()
methods of java.io.File
). java.io.File
的createTempFile()
和deleteOnExit()
方法)。 setContentType
of the HttpServletResponse to set the MIME type of the pdf. setContentType
设置pdf的MIME类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.