Home > OS >  Create a PDF file for each request but without storing it in disk using JAVA
Create a PDF file for each request but without storing it in disk using JAVA

Time:02-23

I want to create a PDF file for each request. In that PDF file I have to append some contents then I need to ouput the byte array of that PDF. How can I do that?

CodePudding user response:

You can try this! It might help you! https://www.baeldung.com/java-pdf-creation

CodePudding user response:

Please try the following code using iText 7 java.

         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         PdfDocument pdfDocument = new PdfDocument(new PdfWriter(baos ));
        Document doc1 = new Document(pdfDoc).add(new Paragraph("Hello there..."));
        doc1.close();
        baos.close();
        byte[] bytes = baos .toByteArray();
  • Related