title: Convert pdfReader to byte[] - Itext Java
body: <p>I am using itext in Java for updating a pdf file.</p>
  
  <ul>
  <li>I read the pdf</li>
  <li>I update the content (get PRStream, convert into stream then string, update the string, convert it back PRStream)</li>
  <li><p>I regenerate the output file using</p>
  
  <pre><code>pdfStamper = new PdfStamper(pdfReader, new FileOutputStream("new-file.pdf"));
  </code></pre></li>
  </ul>
  
  <p>It's working all fine, now I want to send the stream as output to a rest API call, how can I convert <code>pdfReader</code> to <code>byte[]</code></p>
  
  <p>I have been able to save the file and then read the stream from it using</p>
  
  <pre><code> byte[] stream = Files.readAllBytes(file.toPath());
  </code></pre>
  
  <p>but I don' want to save the file, I want to retrieve the stream directly instead of saving the file and then getting <code>byte[]</code> of the newly generated pdf</p>