title: iTextSharp sign PDF created in MemoryStream
body: <p>I need to dynamically create a PDF file, so I use a MemoryStream and iTextSharp for editing the PDF. But I want to digitally sign the PDF file before sending it to the browser. I've seen in a sample project that iTextSharp has a PDFSigner class, which mostly does all the work. But as I've seen it, it works like this:</p>
  
  <pre><code>PDFSigner signer = new PDFSigner(inputFileName, outputFileName, certificate, metaData);
  signer.Sign(......)
  </code></pre>
  
  <p>But with MemoryStream, I can't provide a physical file name for input or output either. My code is below:</p>
  
  <pre><code>MemoryStream memoryStream = new MemoryStream();
  var document = new Document(iTextSharp.text.PageSize.LETTER, 40, 40, 60, 40);
  PdfWriter.GetInstance(document, memoryStream).CloseStream = false;
  
  document.Open();
  PopulatePDF(document, someId);
  document.Close();
  
  byte[] byteArray = memoryStream.ToArray();
  
  memoryStream.Write(byteArray, 0, byteArray.Length);
  memoryStream.Position = 0;
  
  return new FileStreamResult(memoryStream, "application/pdf");
  </code></pre>
  
  <p>My question is how can I use a PDFSigner object to sign the document, giving that PDFSigner takes only strings - filenames as arguments.</p>