我在实现一种生成pdf然后显示另存为对话框以选择文件路径的方法时遇到了麻烦,我的代码有什么问题?
public void generatePDF(ActionEvent ev) throws Exception{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Document document = new Document();
PdfWriter.getInstance(document, baos);
document.open();
...
document.close();
// Prepare.
byte[] pdfData = baos.toByteArray();
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
// Initialize response.
response.reset();
response.setContentType("application/pdf");
response.setHeader("Content-disposition","attachment;filename=\"ResumenEjecutivo.pdf\"");
// Write file to response.
OutputStream output = response.getOutputStream();
output.write(pdfData);
output.close();
// Inform JSF to not take the response in hands.
facesContext.responseComplete();
}