title: PDFBox - Create java.io.InputStream from String
body: <p>I am integrating my RESTful service to support download of documents etc. For that I am exploring PDFBox library which has capability to work with PDF docs (fantastic) and it works OK if I have to create and save documents.</p>
  
  <p>My example code looks like following;</p>
  
  <pre><code>    PDDocument doc = null;
  PDPage page = null;
  try{
      doc = new PDDocument();
      page = new PDPage();
      doc.addPage(page);
      PDFont font = PDType1Font.HELVETICA;
      PDPageContentStream content = new PDPageContentStream(doc,page);
      content.beginText();
      content.drawString("Some Content Received At Runtime");
      content.endText();
      content.close();
      doc.save("SomeName.pdf");
      doc.close();
  
      // Now load and return the stream
      return PDDocument.load("SomeName.pdf").getDocument().createCOSStream().getFilteredStream();
  } catch (Exception e) {
      // Do nothing for now
  }
  </code></pre>
  
  <p>If you see in above example I have an option to convert document into InputStream but to achieve this I first have to <strong>Save the document and then reload!</strong> This is not desirable because this will clutter the server I am running on with junk.</p>
  
  <p>What I really want is to achieve this without saving the document! Is it possible? Should I be looking at some other library like iText? If you know an example for the same please share.</p>