Force download PDF
I want to download a pdf file on this url but don't download: http://s开发者_如何学Pythonede.juntaex.es/empleodoc/6e22820d-ec8f-400f-9f80-75c007bdfd43
I copy and paste on browser and don't work.
I used this code but does not work
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse(url));
startActivity(intent);
How I force the download?
Update: Obviously I mean downloading the pdf does not work in android browser and does not work either through code above. The download works in the browser on my computer.
I need to force download how pdf file.
I want to download the pdf by clicking a button in my application
It can be Done in JSP page I hope it can also be done in JAVA too as follows
DownloadPage.JSP code :-
<a href='downloadPdf.jsp?file=FILE.pdf' >Download PDF File</a>
downloadPdf.JSP code :-
<%@ page import="java.util.*,java.io.*"%>
<%
File f = new File ("E:/PDFfiles/Downloads/" + request.getParameter("file") );
response.setContentType ("application/pdf");
response.setHeader ("Content-Disposition", "attachment; filename=""+request.getParameter("file")+""");
String name = f.getName().substring(f.getName().lastIndexOf("/") + 1,f.getName().length());
InputStream in = new FileInputStream(f);
ServletOutputStream outs = response.getOutputStream();
int bit = 256;
int i = 0;
try {
while ((bit) >= 0) {
bit = in.read();
outs.write(bit);
}
} catch (IOException ioe) {ioe.printStackTrace(System.out);
}
outs.flush();
outs.close();
in.close();
%>
Source : http://bloggerplugnplay.blogspot.in/2012/05/how-to-create-force-download-link-for.html
It sounds like you are just trying to download the PDF to your computer and I'm not clear if you are trying to do it in Java code or if that is just what you are are attempting because you can't get the computer to download it directly.
The easiest way is probably going to be to bring it up in the browser and then right click on it and then on "Save As". At least that is how it works in Chrome--there are similar methods in other browsers.
精彩评论