diff --git a/UtilitatPdf/MainWindow.xaml.cs b/UtilitatPdf/MainWindow.xaml.cs index 5e449a4..0d3df7b 100644 --- a/UtilitatPdf/MainWindow.xaml.cs +++ b/UtilitatPdf/MainWindow.xaml.cs @@ -153,12 +153,8 @@ namespace UtilitatPdf try { PdfMergeFiles mClas = new PdfMergeFiles(FinalPdfFile); - - foreach (PdfInfo fi in list) - { - mClas.AddFile(fi.FileName); - } - mClas.Copy(); + mClas.AddFiles(list); + mClas.Generate(); } catch (IOException ex) { diff --git a/UtilitatPdf/PdfMergeFiles.cs b/UtilitatPdf/PdfMergeFiles.cs index 80a50e2..145a756 100644 --- a/UtilitatPdf/PdfMergeFiles.cs +++ b/UtilitatPdf/PdfMergeFiles.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.ObjectModel; using System.IO; using iText.Kernel.Pdf; using iText.Kernel.Utils; @@ -31,9 +32,19 @@ namespace UtilitatPdf { if (new FileInfo(_FinalPdfFile).Exists) File.Delete(_FinalPdfFile); } - } } + public bool AddFiles(ObservableCollection sourceFiles) + { + foreach (PdfInfo fitxer in sourceFiles) + { + if (!this.AddFile(fitxer.FileName)) + { + return false; + } + } + return true; + } public bool AddFile(string PdfFilename) { checkVars(PdfFilename); @@ -52,7 +63,7 @@ namespace UtilitatPdf _pdfMerger = new PdfMerger(_pdfDocument); _pdfMerger.Merge(_pdfDocument2, 1, _pdfDocument2.GetNumberOfPages()); - this.Close(); + this.ClosePdfDocs(); } catch (IOException) { @@ -72,11 +83,11 @@ namespace UtilitatPdf } return true; } - public void Copy() + public void Generate() { File.Copy(_tmpFile, _FinalPdfFile); } - private void Close() + private void ClosePdfDocs() { _pdfDocument?.Close(); _pdfDocument2?.Close();