Ejemplo n.º 1
0
        public void MergeAll( string fullOutputPath, string[] files )
        {
            var stopwatch = Stopwatch.StartNew();

            var pdfMerger = new PdfMerger( new PdfFileReader() );

            try
            {
                using ( var document = pdfMerger.Merge( files, IncrementProgressBar ) )
                {
                    document.Save( fullOutputPath );
                }
            }
            catch ( Exception ex )
            {
                ShowExceptionMessage( ex );
            }

            string message = string.Format( "Complete. Elapsed time: {0}", stopwatch.GetElapsedTimeString() );

            MessageBoxWrapper.Show( message, "Complete", MessageBoxButton.OK, MessageBoxImage.Information );

            EnableMergeButton();

            OpenOutputDirectory();
        }
Ejemplo n.º 2
0
        public void MergeInBatches( string fullOutputPath, string[] files, int batchSize  )
        {
            string outputPath = Path.GetDirectoryName( fullOutputPath );

            string outputFileName = Path.GetFileNameWithoutExtension( fullOutputPath );

            string extension = Path.GetExtension( fullOutputPath );

            var stopwatch = Stopwatch.StartNew();

            var pdfMerger = new PdfMerger( new PdfFileReader() );

            var filePaths = files.AsEnumerable();

            int iteration = 1;

            while ( filePaths.Any() )
            {
                var filePathBatch = filePaths.Take( batchSize );

                try
                {
                    using ( var document = pdfMerger.Merge( filePathBatch.ToArray(), IncrementProgressBar ) )
                    {
                        if ( iteration > 1 )
                        {
                            string newFileName = string.Format( "{0}{1}{2}", outputFileName, iteration, extension );

                            string newPath = Path.Combine( outputPath, newFileName );

                            document.Save( newPath );
                        }
                        else
                        {
                            document.Save( fullOutputPath );
                        }
                    }
                }
                catch ( Exception ex )
                {
                    ShowExceptionMessage( ex );
                }

                iteration++;

                filePaths = filePaths.Skip( batchSize );
            }

            string message = string.Format( "Complete. Elapsed time: {0}", stopwatch.GetElapsedTimeString() );

            MessageBoxWrapper.Show( message, "Complete", MessageBoxButton.OK, MessageBoxImage.Information );

            EnableMergeButton();

            OpenOutputDirectory();
        }