How do I print a document to a memory stream? ... virtual printer to in-memory PDF


We need to print a document to a memory stream (of course, a “PDF” stream), basically a virtual printer to in-memory PDF. We do want to avoid saving the document as PDF on the disk as we’re going to send the stream to a different sub-system, possibly manipulating the stream a little bit. Does PDFNet API support this?


Yes, this is possible. As a starting point please see Convert sample that is included as part of PDFNet SDK. Instead of saving the PDF to a file you could save it to a bugger or a stream. I am not

using (PDFDoc pdfdoc = new PDFDoc()) {
if (pdftron.PDF.Convert.RequiresPrinter(path)){ 
Console.WriteLine("Printing file: " + path); // we assume here that PDFNet virtual driver is installed (see Convert sample for details).
pdftron.PDF.Convert.ToPdf(pdfdoc, inputPath + file.inputFile);
// save to some type of output stream (or use Save() that return memory bugger byte[])…
using (FileStream ostm = new FileStream(output_path + "doc_memory_edit.txt", FileMode.Create, FileAccess.Write)) {
pdfdoc.Save(ostm, SDFDoc.SaveOptions.e_remove_unused);