I assume that you want to write to a
ByteArrayOutputStream instead of to a
FileOutputStream. There are different examples on how to do that on the iText web site. Note that there is no
PdfStamper in iText 7, we simply use
See for instance the FormServlet example where it says:
// We create an OutputStream for the new PDF ByteArrayOutputStream baos = new ByteArrayOutputStream(); // Now we create the PDF PdfDocument pdfDoc = new PdfDocument(new PdfReader(is, null), new PdfWriter(baos));
Then later in the example, we do this:
// We write the PDF bytes to the OutputStream OutputStream os = response.getOutputStream(); baos.writeTo(os);
If you want a
byte, you can simply do this:
byte pdfBytes = baos.toByteArray();
I hope your question wasn't about writing a
PdfContentByte stream to a
byte because that wouldn't make sense: a content stream doesn't contain any resources such as fonts, images, form XObjects, etc...
Click this link if you want to see how to answer this question in iText 5.