我正在尝试在我的页面上下载 pdf 文件:
<p:commandButton action="#{patientCardMB.saveHistoryPdf()}" value="PDF" ajax="false" icon="ui-icon-document" onclick="PrimeFaces.monitorDownload(start, stop)">
<p:fileDownload value="#{patientCardMB.file}" />
</p:commandButton>
保存历史方法:
public String saveHistoryPdf() throws FileNotFoundException {
ArrayList<PatientCard> patientHistory = (ArrayList) getHistory();
if (new HistoryPdf().createPdf(patientHistory)) {
InputStream stream = new FileInputStream("C:\\Users\\XXXX\\Documents\\NetBeansProjects\\Project\\pdf\\" + patientHistory.get(0).getPatientId().getFirstName() + patientHistory.get(0).getPatientId().getLastName() + ".pdf");
file = new DefaultStreamedContent(stream, "application/pdf", "dsadsaa.pdf");
sendInfoMessageToUser("Pdf został stworzony");
} else {
sendErrorMessageToUser("Podczas tworzenia pliku pdf wystąpił błąd");
}
return "pdf";
}
但是文件下载不起作用。任何人都可以帮忙吗?