开发者

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 t开发者_StackOverflow社区o 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜