The crux of the code is the line where pass false to the Save method of PdfDocument, which keeps the memory stream open. And, then, before giving that stream to the Azure SDK method, you need to rewind the stream to the beginning. Other than that, all pretty boilerplate.