Ejemplo n.º 1
0
        private void GenerateXlsxCommand_Execute()
        {
            try
            {
                SetBusy(true);
                var saveFileDialog = new SaveFileDialog
                {
                    Filter = "XLSX Files (*.xlsx) | *.xlsx"
                };
                if (saveFileDialog.ShowDialog() == true)
                {
                    var fileName  = saveFileDialog.FileName;
                    var documents = PdfFiles.Select(FordParser.Parser.FordParser.GetFordDocument).ToArray();

                    var writer = new PoExcelWriter(fileName, documents);
                    writer.Write();

                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo()
                    {
                        FileName        = Path.GetDirectoryName(saveFileDialog.FileName),
                        UseShellExecute = true,
                        Verb            = "open"
                    });
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
                Console.WriteLine(exception);
            }
            finally
            {
                SetBusy(false);
            }
        }
Ejemplo n.º 2
0
        public async Task <bool> MergePdfs()
        {
            var fileList = PdfFiles
                           .Select(pf => pf.File)
                           .ToList();

            var byteList = new List <byte[]>();

            foreach (var file in fileList)
            {
                byte[] byteArray;
                using (var fileStream = await file.OpenStreamForReadAsync())
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        fileStream.CopyTo(memoryStream);
                        byteArray = memoryStream.ToArray();
                    }
                }
                byteList.Add(byteArray);
            }

            var mergedPdfBytes = pdfMergeUtility.MergePdfs(byteList);

            var savePicker = new FileSavePicker
            {
                SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
                SuggestedFileName      = "Merged Pdf"
            };

            savePicker.FileTypeChoices.Add("Pdf", new List <string>()
            {
                ".pdf"
            });

            var mergedFile = await savePicker.PickSaveFileAsync();

            if (mergedFile != null)
            {
                // Prevent updates to the remote version of the file until
                // are changes are finished and CompleteUpdatesAsync is called
                CachedFileManager.DeferUpdates(mergedFile);

                await FileIO.WriteBytesAsync(mergedFile, mergedPdfBytes);

                // Let Windows know that changes to the file are finished so
                // that the remote version of the file can be updated.
                var status = await CachedFileManager.CompleteUpdatesAsync(mergedFile);

                if (status == Windows.Storage.Provider.FileUpdateStatus.Complete)
                {
                    LatestMergedFile = mergedFile;
                    return(true);
                }
            }
            return(false);
        }