봄과 함께 나머지 API를 호출하는 PDF 파일을 다운로드해야합니다. 내 코드는 다음iText를 사용하여 봄과 편안한 서비스에서 PDF를 다운로드
@RequestMapping(value = "downloadPDF", method = RequestMethod.GET, produces = MediaType.APPLICATION_PDF_VALUE)
public @ResponseBody ResponseEntity<InputStreamResource> getPDF() throws IOException {
ByteArrayInputStream bis = GeneratePdfReport.createReport();
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Disposition", "inline; filename=migration.pdf");
return ResponseEntity
.ok()
.headers(headers)
.contentType(MediaType.APPLICATION_PDF)
.body(new InputStreamResource(bis));
}
이이 문서에 간단한 표를 인쇄 createReport의 방법을 나는 나머지 API를 호출하고 나는이 오류를 얻을 때 문제가 발생합니다
public static ByteArrayInputStream createReport() {
Document document = new Document();
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
PdfPTable table = new PdfPTable(3);
table.setWidthPercentage(60);
table.setWidths(new int[]{1, 3, 3});
Font headFont = FontFactory.getFont(FontFactory.HELVETICA_BOLD);
PdfPCell hcell;
hcell = new PdfPCell(new Phrase("Id", headFont));
hcell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(hcell);
hcell = new PdfPCell(new Phrase("Name", headFont));
hcell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(hcell);
hcell = new PdfPCell(new Phrase("Population", headFont));
hcell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(hcell);
PdfWriter.getInstance(document, out);
document.open();
document.add(table);
document.close();
} catch (DocumentException ex) {
System.out.println("error");
}
return new ByteArrayInputStream(out.toByteArray());
}
서버
HTTP Status 406 – Not Acceptable
The target resource does not have a current representation that would be acceptable to the user agent, according to the proactive negotiation header fields received in the request, and the server is unwilling to supply a default representation
내가 https://stackoverflow.com/questions/45159523/download-file-using-spring-restful로 해결을 -service – chris