-
Notifications
You must be signed in to change notification settings - Fork 312
Description
My function was merge two PDF files into one file
public static bool MergePDF(string filePath1, string filePath2)
{
var resultFileBytes = PdfMerger.Merge(filePath1, filePath2);
FileStream stream = new FileStream(filePath1, FileMode.Create);
stream.Write(resultFileBytes, 0, resultFileBytes.Length);
stream.Close();
stream.Dispose();
return true;
}
Error catch on " PdfMerger.Merge(filePath1, filePath2);"
Error as following:
System.IO.IOException: The process cannot access the file 'E:\LocalPath-TSH\F080 TSH\2025\03\Bank\1114013000\PLT676330156.pdf' because it is being used by another process.
at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
at TDK.Archive.Util.Helper.PDFHelper.MergePDF(String filePath1, String filePath2) in D:\workspace\OutPro\TDK\档案归档项目\TSH\src\TDK.Archive.Util\TDK.Archive.Util\Helper\PDFHelper.cs:line 108