private void combineFilesConvertedToPdf_Ordered() { ModalOverlayIsVisible = false; SetFileOrderModalIsVisible = false; UpdateLabelPdf = ""; try { var combined_file_names = new List <string>(); var combine_files = FilesConvertedToPdf_Ordered.ToList(); var ticket_atty = FilesConvertedToPdf.Where(x => !string.IsNullOrEmpty(x.TicketPlusAttorney)).Select(x => x.TicketPlusAttorney).FirstOrDefault(); var new_file_name = PdfUtilities.GenerateFilenameForNewPdf(DestinationFolderConvertedFiles, "CombinedPdf", ticket_atty); if (StaticSystemTests.IsAdobePdfPrinterAvailable()) { // create combined pdf Models.MergePdf.SimpleMergedPdf simpleMergedPdf; if (!string.IsNullOrEmpty(new_file_name)) { simpleMergedPdf = new Models.MergePdf.SimpleMergedPdf(combine_files, "Acrobat", true, new_file_name); } else { simpleMergedPdf = new Models.MergePdf.SimpleMergedPdf(combine_files, "Acrobat", true); } // add new file to FilesConvertedToPdf collection if (System.IO.File.Exists(simpleMergedPdf?.NewCombinedFile)) { if (!FilesConvertedToPdf.Any(x => x.FullName == simpleMergedPdf.NewCombinedFile)) { FilesConvertedToPdf.Add(new CockleFilePdf(simpleMergedPdf.NewCombinedFile, SourceFileTypeEnum.Combined_Pdf)); UpdateLabelPdf = "Created: " + simpleMergedPdf.NewCombinedFile; } } } else // using PdfSharp or iTextSharp ??? { //combined_file_name = new SimpleMergedPdf(SelectedPdfFiles, "PdfSharp").NewCombinedFile; //var combined_file = new SimpleMergedPdf(SelectedPdfFiles, "iTextSharp").NewFileName; } } catch (Exception ex) { Console.Write(ex.Message); UpdateLabelPdf = ex.Message; } }
private async void executeCenterPdf() { ModalOverlayIsVisible = false; CoverLengthSelectorIsVisible = false; UpdateLabelPdf = ""; try { // get new file name var cv_type = CenteredCoverType.NotSet; var custom_filename_text = string.Empty; if (BookletSelected_CenterPdf) { cv_type = CenteredCoverType.Booklet; custom_filename_text = "CenteredOnBookletSizedPage"; } else if (LetterSelected_CenterPdf) { cv_type = CenteredCoverType.Letter; custom_filename_text = "CenteredOnLetterSizedPage"; } var ticket_atty = FilesConvertedToPdf.Where(x => !string.IsNullOrEmpty(x.TicketPlusAttorney)).Select(x => x.TicketPlusAttorney).FirstOrDefault(); var new_file_name = PdfUtilities.GenerateFilenameForNewPdf(DestinationFolderConvertedFiles, custom_filename_text, ticket_atty); // typeset -- upper left if (UpperLeftPosition_CenterPdf) { // this is a simple typeset centering, done with the one step process int?cv_len = null; if (HasCover_CenterPdf) { // two ways to get cover length: 1) check other files in directory, 2) iText method if (FilesConvertedToPdf.Any(x => null != x.CoverLength)) { cv_len = FilesConvertedToPdf.Where(x => null != x.CoverLength).FirstOrDefault().CoverLength; } else { cv_len = PdfCropAndNUp.StaticUtils.GetCoverLength_FirstPageTypesetPdf(SelectedPdfFile.FullName); } } var c = await System.Threading.Tasks.Task.Run(() => new Models.CenterPdfText.CenterTypesetPdf(SelectedPdfFile, cv_len, new_file_name, cv_type)); if (null != c && null != c.NewFileCreated && System.IO.File.Exists(c.NewFileCreated.FullName)) { if (!FilesConvertedToPdf.Any(x => x.FullName == c.NewFileCreated.FullName)) { FilesConvertedToPdf.Add(c.NewFileCreated); } UpdateLabelPdf = "Created: " + System.IO.Path.GetFileNameWithoutExtension(c.NewFileCreated.FullName); } } // already centered else if (CenterPosition_CenterPdf) { // if already centered, no need to separate out cover Models.CenterPdfText.CenterCameraReadyBrief ctr = null; if (BookletSelected_CenterPdf) { ctr = await System.Threading.Tasks.Task.Run(() => new Models.CenterPdfText.CenterCameraReadyBrief(SelectedPdfFile, new_file_name, CenteredCoverType.Booklet)); } else if (LetterSelected_CenterPdf) { ctr = await System.Threading.Tasks.Task.Run(() => new Models.CenterPdfText.CenterCameraReadyBrief(SelectedPdfFile, new_file_name, CenteredCoverType.Letter)); } if (null != ctr && null != ctr.NewFileCreated && System.IO.File.Exists(ctr.NewFileCreated.FullName)) { if (!FilesConvertedToPdf.Any(x => x.FullName == ctr.NewFileCreated.FullName)) { FilesConvertedToPdf.Add(ctr.NewFileCreated); UpdateLabelPdf = "Created: " + System.IO.Path.GetFileNameWithoutExtension(ctr.NewFileCreated.FullName); } } } // need to develop this: method to crop (find text boundaries) and center else if (NotCentered_CenterPdf) { } } catch (Exception ex) { Console.Write(ex.Message); UpdateLabelPdf = ex.Message; } }
private string[] generateImposedTypesetPdfFilename(int num_pages) { var new_file_name = new string[] { string.Empty, string.Empty }; // get custom name var custom_name_a = string.Empty; var custom_name_b = string.Empty; if (IsSaddleStitchPdf) { if (HasCoverPdf && num_pages == 1) { custom_name_a = "Cover_SaddleStitch"; } else if (HasCoverPdf && num_pages > 1) { custom_name_a = "Cover_&_Brief_SaddleStitch"; } else if (!HasCoverPdf) { custom_name_a = "Brief_SaddleStitch"; } } else // Perfect Bind { if (HasCoverPdf && num_pages == 1) { custom_name_a = "Cover_PerfectBind"; } else if (HasCoverPdf && num_pages > 1) { // need two names here custom_name_a = "Cover_PerfectBind"; custom_name_b = "Brief_PerfectBind"; } else if (!HasCoverPdf) { custom_name_a = "Brief_PerfectBind"; } } // get ticket + atty var ticket_atty = FilesConvertedToPdf.Where(x => x.TicketNumber != null && !(string.IsNullOrEmpty(x.Attorney))).Select(x => x.TicketPlusAttorney).FirstOrDefault().Trim(); if (string.IsNullOrEmpty(ticket_atty)) { ticket_atty = FilesConvertedToPdf.Where(x => x.TicketNumber != null).Select(x => x.TicketNumber).FirstOrDefault().ToString().Trim(); } custom_name_a = ticket_atty + " " + custom_name_a; if (!string.IsNullOrEmpty(custom_name_b)) { custom_name_b = (ticket_atty + " " + custom_name_b).Trim(); } new_file_name[0] = System.IO.Path.Combine(DestinationFolderConvertedFiles, custom_name_a + ".pdf"); var i = 0; while (System.IO.File.Exists(new_file_name[0])) { new_file_name[0] = new_file_name[0].Substring(0, new_file_name[0].Length - 4); new_file_name[0] = System.IO.Path.Combine(DestinationFolderConvertedFiles, new_file_name[0] + "_" + i + ".pdf"); i++; } if (!string.IsNullOrEmpty(custom_name_b)) { new_file_name[1] = System.IO.Path.Combine(DestinationFolderConvertedFiles, custom_name_b + ".pdf"); i = 0; while (System.IO.File.Exists(new_file_name[1])) { new_file_name[1] = new_file_name[1].Substring(0, new_file_name[1].Length - 4); new_file_name[1] = System.IO.Path.Combine(DestinationFolderConvertedFiles, new_file_name[1] + "_" + i + ".pdf"); i++; } } return(new_file_name); }
private void centerPdfOptions() { try { // preset booleans // preset cover length var cv_len = FilesConvertedToPdf.Where(x => x.CoverLength != null).Select(x => x.CoverLength).FirstOrDefault(); switch (cv_len) { case 48: Cover48PicaPdf = true; break; case 49: Cover49PicaPdf = true; break; case 50: Cover50PicaPdf = true; break; case 51: Cover51PicaPdf = true; break; default: Cover48PicaPdf = false; Cover49PicaPdf = false; Cover50PicaPdf = false; Cover51PicaPdf = false; break; } // preset "has cover" var file_type = SelectedPdfFile.FileType; switch (file_type) { case SourceFileTypeEnum.Cover: NoCover_CenterPdf = false; HasCover_CenterPdf = true; break; default: NoCover_CenterPdf = true; HasCover_CenterPdf = false; break; } // preset page size LetterSelected_CenterPdf = true; BookletSelected_CenterPdf = false; // preset position of original UpperLeftPosition_CenterPdf = false; CenterPosition_CenterPdf = true; NotCentered_CenterPdf = false; // call modal overlay ModalOverlayIsVisible = true; CoverLengthSelectorIsVisible = true; } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void refreshLoadedPdfFolder() { try { // Command:RunRefreshLoadedPdfFolder if (!System.IO.Directory.Exists(DestinationFolderConvertedFiles)) { FilesConvertedToPdf.Clear(); DestinationFolderConvertedFiles = string.Empty; return; } else { var files = System.IO.Directory.EnumerateFiles(DestinationFolderConvertedFiles).ToList(); var files_to_add = files.Where(x => !FilesConvertedToPdf.Any(y => x == y.FullName)); if (files_to_add.Count() > 0) { files_to_add.ToList().ForEach(x => { FilesConvertedToPdf.Add(new CockleFilePdf(x, Models.Utilities.SourceFileTypeEnum.Unrecognized)); }); } var files_to_remove = FilesConvertedToPdf.Where(x => !System.IO.File.Exists(x.FullName)); if (files_to_remove?.Count() > 0) { foreach (var x in files_to_remove) { FilesConvertedToPdf.Remove(x); } } var files_dup = FilesConvertedToPdf.GroupBy(x => x.FullName) .Where(g => g.Count() > 1).Select(y => y.Key).ToList(); foreach (var y in files_dup) { var options_to_remove = FilesConvertedToPdf.Where(x => x.FullName == y); var unrec_option = options_to_remove.Where(x => x.FileType == SourceFileTypeEnum.Unrecognized || x.FileType == SourceFileTypeEnum.UnrecognizedCentered); if (unrec_option.Count() == 1) { FilesConvertedToPdf.Remove(unrec_option.FirstOrDefault()); } else { var other_option = FilesConvertedToPdf.Where(x => x.FullName == y); FilesConvertedToPdf.Remove(other_option.FirstOrDefault()); } } foreach (var x in FilesConvertedToPdf) { foreach (var y in files_dup) { if (x.FullName == y) { if (x.FileType == SourceFileTypeEnum.Unrecognized) { } } } } } } catch (Exception ex) { Console.Write(ex.Message); } }