java - how to save file from html to pdf -
string w=request.getparameter("fpath"); try { filereader fr = new filereader(w); bufferedreader reader = new bufferedreader(fr); stringbuilder sb = new stringbuilder(); string line = ""; while ((line = reader.readline()) != null) { sb.append(line.trim()); } string result = sb.tostring(); outputstream file = new fileoutputstream(new file("e:\\test.pdf")); document document = new document(); pdfwriter.getinstance(document, file); document.open(); @suppresswarnings("deprecation") htmlworker htmlworker = new htmlworker(document); htmlworker.parse(new stringreader(result)); response.addheader("content-disposition", "attachment; filename=\"file.pdf\""); response.setcontenttype("application/pdf"); document.close(); file.flush(); } catch (exception e) { e.printstacktrace(); } this code save html pdf file when click on save button save e:\test.pdf ,while don't want set e:\test.pdf physical path want if user click on save button should ask u need save if user select location save place response.addheader("content-disposition", "attachment; filename=\"file.pdf\""); response.setcontenttype("application/pdf"); dont know how set file name , file content can able save pdf file desire location.
so, instead of creating new fileoutputstream use response.getoutputstream(). apart setting headers not sending else in response
Comments
Post a Comment