title: How to add metadata to PDF document using PDFbox?
body: <p>I have an input stream of a PDF document available to me. I would like to add <code>subject</code> metadata to the document and then save it. I'm not sure how to do this. </p>
  
  <p>I came across a sample recipe here: <a href="https://pdfbox.apache.org/1.8/cookbook/workingwithmetadata.html" rel="noreferrer">https://pdfbox.apache.org/1.8/cookbook/workingwithmetadata.html</a></p>
  
  <p>However, it is still fuzzy. Below is what I'm trying and places where I have questions</p>
  
  <pre><code>PDDocument doc = PDDocument.load(myInputStream);
  PDDocumentCatalog catalog = doc.getDocumentCatalog();
  InputStream newXMPData = ...; //what goes here? How can I add subject tag?
  PDMetadata newMetadata = new PDMetadata(doc, newXMLData, false );
  catalog.setMetadata( newMetadata );
  //does anything else need to happen to save the document??
  //I would like an outputstream of the document (with metadata) so that I can save it to an S3 bucket
  </code></pre>