简体   繁体   中英

WPF/iTextSharp: How to send MemoryStream to Windows, for it to handle opening PDF?

I am using iTextSharp to generate PDF out of HTML. I can save the PDF file ok, but I want to handle the PDF for the OS to open it, without having to save it to disk first. How can I do that? I am doing this from within a WPF application.

Here's my code so far:

MemoryStream memoryStream = new MemoryStream();
TextReader reader = new StringReader(tb.Text);
Document document = new Document(PageSize.A4, 30, 30, 30, 30);
PdfWriter pdfWriter = PdfWriter.GetInstance(document, memoryStream);
HTMLWorker worker = new HTMLWorker(document);
document.Open();
worker.StartDocument();
worker.Parse(reader);
worker.EndDocument();
worker.Close();
pdfWriter.CloseStream = false;
document.Close();

How can I "materialize" memoryStream.ToArray() into a .pdf file (in memory) and send it to Windows?

"Send to Windows" doesn't mean anything. Only a process knows how to deal with a PDF document. Like Adobe Acrobat. A process has no use for what you store in memory, it can't get to it. It needs a file. That's a non-issue in Windows, when you write a file you write to memory first. The file system cache. The difference between the disk and memory is very small in Windows, an important design feature of the operating system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM