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?

James Z
  • 12,209
  • 10
  • 24
  • 44
Jay Kumo
  • 671
  • 1
  • 5
  • 9
  • 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](https://stackoverflow.com/q/7987395/1729265). – mkl Apr 19 '20 at 08:39
  • Thanks for the feedback! – Jay Kumo Apr 19 '20 at 22:49

0 Answers0