PDFsharp保存到的MemoryStream

PDFsharp保存到的MemoryStream

本文介绍了PDFsharp保存到的MemoryStream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过它的保存方法来保存PdfSharp.Pdf.PdfDocument到流,但它不附加PDF标题设置它。所以,当我读回的数据流,并返回给用户,他看到该PDF文件是无效的。有没有一种解决方案来连接PDF标题设置时PDFsharp保存到内存?

I want to save a PdfSharp.Pdf.PdfDocument by its Save method to a Stream, but it doesn't attach the PDF header settings to it. So when I read back the Stream and return it to the user, he see that the PDF file is invalid. Is there a solution to attach the PDF header settings when PDFsharp saves to memory?

推荐答案

因此​​,解决办法:

MigraDoc.DocumentObjectModel.Document doc = new MigraDoc.DocumentObjectModel.Document();
MigraDoc.Rendering.DocumentRenderer renderer = new DocumentRenderer(doc);
MigraDoc.Rendering.PdfDocumentRenderer pdfRenderer = new MigraDoc.Rendering.PdfDocumentRenderer();
pdfRenderer.PdfDocument = pDoc;
pdfRenderer.DocumentRenderer = renderer;
using (MemoryStream ms = new MemoryStream())
{
  pdfRenderer.Save(ms, false);
  byte[] buffer = new byte[ms.Length];
  ms.Seek(0, SeekOrigin.Begin);
  ms.Flush();
  ms.Read(buffer, 0, (int)ms.Length);
}

有这样MigraDoc东西附带PdfSharp,但我发现,几乎没有任何正当doc / FAQ里吧。谷歌上搜索后几个小时我已经找到了一个片断这是这样的事情。现在,它的工作原理。

There is this MigraDoc stuff which comes with PdfSharp, but i hardly found any proper doc/faq for it. After hours of googling i've found a snippet which was something like this. Now it works.

这篇关于PDFsharp保存到的MemoryStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 16:39