简体   繁体   English

WPF / iTextSharp:如何将MemoryStream发送到Windows,以便它处理打开的PDF?

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

I am using iTextSharp to generate PDF out of HTML. 我正在使用iTextSharp从HTML生成PDF。 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. 我可以保存PDF文件,但是我想处理该PDF以供操作系统打开,而不必先将其保存到磁盘。 How can I do that? 我怎样才能做到这一点? I am doing this from within a WPF application. 我正在WPF应用程序中执行此操作。

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? 如何将memoryStream.ToArray()“实现”为.pdf文件(在内存中)并将其发送到Windows?

"Send to Windows" doesn't mean anything. “发送到Windows”没有任何意义。 Only a process knows how to deal with a PDF document. 只有一个进程知道如何处理PDF文档。 Like Adobe Acrobat. 像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. 在Windows中这不是问题,当您写入文件时,首先要写入内存。 The file system cache. 文件系统缓存。 The difference between the disk and memory is very small in Windows, an important design feature of the operating system. 在Windows中,磁盘和内存之间的差异很小,这是操作系统的重要设计功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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