简体   繁体   English

MigraDoc图片-什么时候可以删除图片

[英]MigraDoc Images - When can I delete the images

I am using MigraDoc for PDF Exports and part of the application allows the user to Embed an image (MigraDoc.DocumentObjectModel.Shapes.Image) into a Document. 我正在使用MigraDoc进行PDF导出,该应用程序的一部分允许用户将图像(MigraDoc.DocumentObjectModel.Shapes.Image)嵌入到文档中。 The images exist in the database and I am not able to upgrade to the latest MigraDoc BETA that handles FileStream images from Memory. 图像存在于数据库中,我无法升级到处理来自内存的FileStream图像的最新MigraDoc BETA。 So, my solution is to read the images from the database and store them in a 'Temporary' folder in my Images folder and MigraDoc will reference the images there. 因此,我的解决方案是从数据库中读取图像并将其存储在我的图像文件夹中的“临时”文件夹中,MigraDoc将在其中引用这些图像。 Once the PDF has rendered then I will no longer need the image and will want to get rid of it. PDF呈现后,我将不再需要该图像,并且希望摆脱它。

The PDF Document is rendered as follows: PDF文档的呈现方式如下:

            PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
            renderer.Document = this.document;
            renderer.RenderDocument();

            byte[] pdfContents = null;
            using (MemoryStream stream = new MemoryStream())
            {
                renderer.PdfDocument.Save(stream, true);
                pdfContents = stream.ToArray();
            }

            return pdfContents;

and is eventually passed as a FileContentResult. 并最终作为FileContentResult传递。

My problem is that I do not seem to be able to get rid of the files added to the PDF document at any stage of the process... They seem to be required up to and including the point I return the FileContentResult. 我的问题是,在该过程的任何阶段,我似乎都无法摆脱添加到PDF文档中的文件……直到我返回FileContentResult为止,它们似乎都是必需的。

Is there a setting on the PdfDocumentRenderer (or anywhere else) that will embed the images instead of relying on them being in-situ until after the FileContentResult is rendered? PdfDocumentRenderer(或其他任何地方)上是否有设置将嵌入图像,而不是依赖它们在渲染FileContentResult之后就地放置?

After the call to renderer.PdfDocument.Save the image files are no longer needed. 调用renderer.PdfDocument.Save之后,不再需要图像文件。

Actually the images should no longer be needed after the call to renderer.RenderDocument(); 实际上,在调用renderer.RenderDocument();之后不再需要图像renderer.RenderDocument(); .

Some background information 一些背景资料
The WPF build of MigraDoc uses class BitmapSource to open the image. MigraDoc的WPF构建使用BitmapSource类打开图像。 By default this class caches the images and version 1.32 used the default options and thus the image files remain locked even after disposing the MigraDoc image. 默认情况下,此类会缓存图像,并且1.32版使用默认选项,因此即使处理MigraDoc图像后,图像文件仍保持锁定状态。
This unwanted side effect of caching was fixed in November 2014 - since then MigraDoc disables caching when opening images using class BitmapSource . 缓存的这种不良副作用已在2014年11月修复,此后,MigraDoc在使用BitmapSource类打开图像时禁用了缓存。
The GDI+ build of MigraDoc never had this caching problem. MigraDoc的GDI +版本从来没有这个缓存问题。
If your company insists on using a version that was published four years ago then you will miss all the improvements and bug fixes that were applied since then. 如果您的公司坚持使用四年前发布的版本,那么您将错过此后应用的所有改进和错误修复。
Maybe the GDI build is the solution to this locking issue (assuming this question is about image files that remain locked when they are no longer needed). 也许GDI构建是解决此锁定问题的解决方案(假设此问题是关于不再需要时保持锁定状态的图像文件)。

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

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