Cześć,
od kilku godzin walcze z generowaniem pliku pdf w Javie. Utknąłem w punkcie, gdzie generuje się plik który się nie otwiera ( wydaje się pusty ), a lokalnie zapisuje się prawidłowo działający plik pdf.
Potrzebuje jednak, aby ten plik był dostępny do pobrania,a nie zapisywał się lokalnie w projekcie.
Bardzo proszę o wsparcie.
@WebServlet("/pdf")
public class PDFServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
HttpSession session = req.getSession();
List<Installment> installments = (List<Installment>) session.getAttribute("schedule");
resp.setContentType("application/pdf");
resp.setHeader("Content-Type","application/x-www-form-urlencoded");
resp.setHeader("Content-disposition","inline; filename='1_orders.pdf'");
createPdf(installments);
}
private void createPdf(List<Installment> installments){
Document document = new Document(PageSize.A4);
try {
File file = new File("1_orders.pdf");
PdfWriter.getInstance(document,new FileOutputStream(file));
document.open();
PdfPTable table = new PdfPTable(5);
table.addCell("#");
table.addCell("Kwota kapitalu");
table.addCell("Kwota odsetek");
table.addCell("Oplaty stale");
table.addCell("Kwota laczna");
for(Installment i: installments){
table.addCell(""+i.getNumber());
table.addCell(""+i.getCapital());
table.addCell(""+i.getInterest());
table.addCell(""+i.getFixedFees());
table.addCell(""+i.getTotalAmount());
}
document.add(table);
document.close();
} catch (IOException | DocumentException e) {
e.printStackTrace();
}
}