0
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {

    PdfWriter pdfWriter = new PdfWriter(response.getOutputStream());
    PdfDocument pdf = new PdfDocument(pdfWriter);
    Document doc = new Document(pdf);

with the above code, I am rendering a pdf as an html response. When I do that, I also want to save this to the database. How should I do it?

Should I create another byte stream and redo the same steps?

2
  • If you redo the same steps, you'll get a slightly different pdf with changes in metadata like creation time and document ID. Instead either target the PdfWriter to a ByeArrayOutputStream and write the resulting byte array to all outputs you want your pdf to go to, or use something like explained in answers to this question.
    – mkl
    Commented Apr 19, 2020 at 8:39
  • Thanks for the feedback!
    – Jay Kumo
    Commented Apr 19, 2020 at 22:49

0

Browse other questions tagged or ask your own question.