How do I convert PDF to a PNG without writing to disk?

Q: How do I render PDF to a PNG without writing to disk using PDFNet
(http://www.pdftron.com/pdfnet)? I can see that PDFDraw has Export()
method [e.g. as in http://www.pdftron.com/pdfnet/samplecode.html#PDFDraw],
however I would prefer to serialize PNG to memory instead of writing
it to a temporary file.
------
A:

You could do so along the following lines:

public static byte[] GeneratePNGFFromPDF(byte[] pdfdata, int
pPageNumber)
{
      PDFNet.Initialize(); // really should be called only once in
App initialize.
      PDFDraw draw = new PDFDraw();
      PDFDoc doc = new PDFDoc(pdfdata, pdfdata.Length);
      doc.InitSecurityHandler();
      draw.SetDPI(92);
      Page pg = doc.GetPage(pPageNumber);
      Bitmap bitmap = draw.GetBitmap(pg);
      MemoryStream lStream = new MemoryStream();
      bitmap.Save(lStream, ImageFormat.Png);
      byte[] lResult = lStream.ToArray();
      lStream.Close();
      lStream.Dispose();
      draw.Dispose();
      doc.Close();
      return lResult;
}