Я пытаюсь добавить генератор PDF на мой сайт.Все работает нормально, поскольку генератор в контроллере
ConsumerController.java:
public String downloadPDF(@PathVariable("id") Long id, @PathVariable("transaction") Long transaction, Model uiModel, HttpServletRequest httpServletRequest, HttpServletResponse response) {
Document document = new Document();
try{
response.setContentType("application/pdf");
PdfWriter.getInstance(document, response.getOutputStream());
document.open();
document.add(new Paragraph("Hello Kiran"));
document.add(new Paragraph("Hello" + id));
document.add(new Paragraph("For"+ transaction));
document.add(new Paragraph(new Date().toString()));
}catch(Exception e){
e.printStackTrace();
}
document.close();
return null;
}
это то, что у меня есть в данный момент, и именно так я хочу, чтобы оно работало, нотот, который я хотел бы добавить, был бы лучше в своем собственном классе (код ниже).
PDFGenerator.java:
public void generatorPDF() throws Exception{
Document d = new Document();
try{
PdfWriter writer = PdfWriter.getInstance(d, new FileOutputStream("CodeOfDoom.pdf"));
d.open();
for(int i=0; i<10; i++){
PdfPTable table = generateLineItemTable(_order.getLineItems());
PdfPTable headerTable= generateHeaderTable(_order.getCustomer());
addBarcode(writer,headerTable);
//add customer barcode to the header
d.add(headerTable);
d.add(table);
Paragraph p = new Paragraph("\n\nFor more, please visit ");
Anchor anchor = new Anchor("www.codeofdoom.com/wordpress");
p.add(anchor);
d.add(p);
d.newPage();
}
d.close();
}catch(Exception e){
e.printStackTrace();
}
}
до сих пор со всем, что я пробовал, PDFКажется, проблема в писателе, потому что я не уверен, как добавить документ в писатель из отдельного класса