How to convert images to PDF in memory?

Question:
I need to convert PNG, JPEG and TIFF images to PDF all in memory. No reading or writing to disk.

Answer:

The following C# code shows how to convert an image to a PDF all in memory, using this class.

https://www.pdftron.com/api/PDFTronSDK/dotnet/pdftron.PDF.Convert.html#pdftron_PDF_Convert_StreamingPDFConversion_pdftron_Filters_Filter_pdftron_PDF_ConversionOptions_

PDFNet.Initialize(yourLicenseOrDemoKey);
// At the beginning of your process
PDFNet.SetDefaultDiskCachingEnabled(false); // disables writing temporary streams to disk
string imageExt = "png";
byte[] imageData = System.IO.File.ReadAllBytes(input_path + "butterfly.png"); // for demo purpose read from disk
using (pdftron.Filters.MemoryFilter memoryFilter = new pdftron.Filters.MemoryFilter((int)imageData.Length, false)) // false = sink
{
	pdftron.Filters.FilterWriter writer = new pdftron.Filters.FilterWriter(memoryFilter); // helper filter to allow us to write to buffer
	writer.WriteBuffer(imageData);
	writer.Flush();
	memoryFilter.SetAsInputFilter(); // switch from sink to source

	using (var newDoc = new PDFDoc())
	{
		var options = new ConversionOptions();
		options.SetFileExtension(imageExt);
		DocumentConversion documentConversion = pdftron.PDF.Convert.StreamingPDFConversion(newDoc, memoryFilter, options);
		documentConversion.Convert();
		byte[] pdfData = newDoc.Save(SDFDoc.SaveOptions.e_linearized);
		// System.IO.File.WriteAllBytes(outPath, pdfData); // if you want to test/verify the output
	}
}