In an ASP.NET MVC 4.8 C# app, I have an HTML string in memory that needs to be converted to a PDF byte array using Aspose's library. All the processing occurs in-memory and nothing is saved to disk. The HTML is generated on the fly and PDF isn't saved to disk but will be attached to an email and sent.
The Aspose docs explain how to load an HTML from disk and save a PDF to disk. I can't find anything on how to do this all in-memory.
Thank you.
Here's the answer with the relevant code:
byte[] pdfBytes = null;
using (var ms = new MemoryStream())
{
var pdfDocument = new Document();
var htmlFragment = new HtmlFragment(myHtmlString);
pdfDocument.Pages.Add().Paragraphs.Add(htmlFragment);
pdfDocument.Save(ms);
pdfDocument.Dispose();
pdfBytes = ms.ToArray();
}