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();
}