PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 4:03 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
PostPosted: Fri Nov 28, 2014 1:59 pm 
Offline

Joined: Tue Nov 25, 2014 8:43 am
Posts: 2
Hi there,

my company uses PDFSharp to render PDFs with images. The images are added to the PDF while creating a table by using the MigraDoc classes from the PDFSharp library. Also these images are created on the fly in a temporary folder which needs to be cleared afterwards. The issue here is that initiating the render process results in calling the following code which is responsible for the file lock:

Code:
namespace PdfSharp.Drawing
{
  ...
  XImage(string path)
  {
    ...
#if WPF && !SILVERLIGHT
    //BitmapSource.Create()
    // BUG: BitmapImage locks the file
    this.wpfImage = new BitmapImage(new Uri(path));  // AGHACK
#endif


The file lock can be prevented by changing this code section to

Code:
namespace PdfSharp.Drawing
{
  ...
  XImage(string path)
  {
    ...
#if WPF && !SILVERLIGHT
    // read image into stream to avoid locking the file
    // see http://tedshelloworld.blogspot.de/2010/11/bitmaps-in-wpf-disposing-of-bitmaps-in.html
    BitmapImage image = new BitmapImage();
    using (FileStream stream = File.OpenRead(path))
    {
      image.BeginInit();
      image.CacheOption = BitmapCacheOption.OnLoad;
      image.StreamSource = stream;
      image.EndInit();
    }

    this.wpfImage = image;
#endif


I've tested PDFSharp with the code change and the file lock is gone. Credits go to the author behind the link mentioned in the comments.

Please include this bug fix in the next release.

So lonG


Top
 Profile  
 
PostPosted: Mon Dec 01, 2014 9:24 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
This has been changed in current internal builds of PDFsharp.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 49 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group