PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jun 30, 2024 6:21 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Fri Jun 04, 2010 7:52 pm 
Offline

Joined: Fri Jun 04, 2010 7:45 pm
Posts: 1
I have some code to convert a series of Tiffs (multiple files, not a multipage Tiff) into a single pdf. The code works fine to do this; however it appears to be locking up access to the Tiffs even after it is done. So when I go to delete the tiff files I get an IOException stating that the process cannot access the file because is being used by another process. I am fairly confident it is the pdf conversion that is doing this as if I skip that step and just delete the tiffs everything works fine.

The code for the conversion is as follows. Any help would be appreciated.

Code:
        public static void ConvertTifFiles(ArrayList sourceFiles, string destination)
        {
            PdfDocument doc = new PdfDocument();
            for (int i = 0; i < sourceFiles.Count; i++)
            {
                string fileName = Path.GetFileNameWithoutExtension((string)sourceFiles[i]);
                string source = (string)sourceFiles[i];
                doc.Pages.Add(new PdfPage());
                XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[i], XGraphicsPdfPageOptions.Append);
                XImage img = XImage.FromFile(source);
                xgr.DrawImage(img, 0, 0);
            }
            doc.Save(destination);

doc.Close();
}


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 07, 2010 8:40 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Try the GDI+ build.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 07, 2013 2:46 pm 
Offline

Joined: Wed Nov 06, 2013 3:32 pm
Posts: 5
Necro I know, but the GDI build does not handle CMYK tif's so I am stuck with the WPF build. Is there another work around for this? My code almost exactly as the OP. It's leaving locks on the Tif files.


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 07, 2013 3:21 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
XImage implements IDisposable, but the sample code given above does not call Dispose() nor frees the XImage. This could make a difference.

Or use streams as shown here:
http://stackoverflow.com/a/19839642/162529

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 07, 2013 4:10 pm 
Offline

Joined: Wed Nov 06, 2013 3:32 pm
Posts: 5
XImage.FromFile does not take a Stream parameter. By the way, that stackoverflow question is mine.

I've narrowed it down to this code, running this code *alone* will leave the lock.

using (var image = XImage.FromFile(path))
{}


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 07, 2013 4:26 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
mxmissile wrote:
XImage.FromFile does not take a Stream parameter.
It does - but better use XImage.FromStream().

mxmissile wrote:
By the way, that stackoverflow question is mine.
I know - but others may also read this thread.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 07, 2013 5:31 pm 
Offline

Joined: Wed Nov 06, 2013 3:32 pm
Posts: 5
I'm still not seeing XImage.FromStream().

Looking here: https://pdfsharp.codeplex.com/SourceCon ... /XImage.cs I'm not seeing it, what am I missing? I would love to use that method.


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 07, 2013 5:54 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
mxmissile wrote:
I'm still not seeing XImage.FromStream().
Sorry, my fault. :oops:
Will be in the next public release.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 98 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:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group