title: How to create a PDF file from HTML using PDFBox?
body: <p>I am trying to create a PDF from HTML content. </p>
  
  <pre><code>public byte[] generatePdf(final XhtmlPDFGenerationRequest request) {
  
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      PDDocument document = new PDDocument();
      InputStream stream = new ByteArrayInputStream(request.getContent()
              .getBytes());
  
      PDStream pdstream = new PDStream(document, stream);
      document.save(baos);
      document.close();
      return this.toByteArray(baos);
  
  }
  </code></pre>
  
  <p>When I take this <code>byte[]</code> and save to a file, the file is blank. I am using <code>PDStream</code> to embed the input stream into the document</p>
  
  <p>From the <a href="http://pdfbox.apache.org/apidocs/" rel="noreferrer">http://pdfbox.apache.org/apidocs/</a></p>
  
  <pre><code>public PDStream(PDDocument doc,
                  InputStream str)
           throws IOException
  </code></pre>
  
  <p>Reads all data from the input stream and embeds it into the document, this will close the <code>InputStream</code>.</p>