public static bool TrySetupBackgroundImage(BackgroundImageEnum imageSource, string source = null) { var image = default(BitmapImage); var stream = default(Stream); switch (imageSource) { case BackgroundImageEnum.Default: stream = Assembly.LoadFrom( Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Launcher.Resources.dll")) .GetManifestResourceStream("Launcher.Resources.Images.bg_default.jpg"); image = _LoadImageFromStream(stream); stream.Close(); stream.Dispose(); _TryDeleteCustomImage(); break; case BackgroundImageEnum.Custom: if (string.IsNullOrEmpty(source)) { return(false); } try { var validationResult = _ValidateImageFile(source); if (!validationResult) { return(false); } File.Copy(source, _resourceFilePath, false); stream = File.OpenRead(_resourceFilePath); image = _LoadImageFromStream(stream); stream.Close(); stream.Dispose(); } catch (Exception e) { return(false); } break; case BackgroundImageEnum.None: default: throw new ArgumentOutOfRangeException(); } _SetupImage(image); _backgroundImage = image; return(true); }
public static bool TrySetBackgroundImage(BackgroundImageEnum imageSource, string path) { switch (imageSource) { case BackgroundImageEnum.Default: { var filePath = Path.Combine(_ResourcesDirectory, _ResourceFileName); if (File.Exists(filePath)) { _backgroundImage?.StreamSource.Dispose(); File.Delete(filePath); } return(true); } case BackgroundImageEnum.Custom: { var stream = File.OpenRead(path); var image = _LoadImageFromStream(stream); if ((image.StreamSource.Length * .000001) > ImageFileSizeLimit) // image size over 10Mb { return(false); } if (image.PixelHeight > ImagePixelHeightLimit || image.PixelWidth > ImagePixelWightLimit) // image pixel size over 2k 2048x1080 { return(false); } stream.Dispose(); var filePath = Path.Combine(_ResourcesDirectory, _ResourceFileName); File.Copy(path, filePath, true); return(true); } case BackgroundImageEnum.None: default: throw new ArgumentOutOfRangeException(nameof(imageSource)); } }
public static void GenerateAndSendData(ViewModel.SenderAndRecieverFivePersonsSingleChoice model, string contenttext, BackgroundImageEnum background, Mp3Enum song, FontsEnum font) { var stringpath = ITextSharpPdfCreator.GeneratefileForCustomers.GeneratePdfFileForCustomer(ReturnPathString.ReturnUniqueFileName(), model.sender.firstname, model.sender.lastname, contenttext, background, song, font); SmtpMailService.SendCustomerMail.SendMailToCustomer(model.Recipient1.Email, stringpath, song); SmtpMailService.SendCustomerMail.SendMailToCustomer(model.Recipient2.Email, stringpath, song); SmtpMailService.SendCustomerMail.SendMailToCustomer(model.Recipient3.Email, stringpath, song); SmtpMailService.SendCustomerMail.SendMailToCustomer(model.Recipient4.Email, stringpath, song); SmtpMailService.SendCustomerMail.SendMailToCustomer(model.Recipient5.Email, stringpath, song); }
public static void GenerateAndSendData(ViewModel.SenderAndRecieversOnePersonSingleChoice model, string contenttext, BackgroundImageEnum background, Mp3Enum song, FontsEnum font) { var stringpath = ITextSharpPdfCreator.GeneratefileForCustomers.GeneratePdfFileForCustomer(ReturnPathString.ReturnUniqueFileName(), model.sender.firstname, model.sender.lastname, contenttext, background, song, font); //<summary> // commented out, to test pdf generation without sending file //<summary> //SmtpMailService.SendCustomerMail.SendMailToCustomer(model.Recipient1.Email,stringpath); }
public void GenerateAndSendGeneralChoice(ViewModel.SenderAndRecieverFivePersonsSingleChoice model, string contenttext, BackgroundImageEnum background, Mp3Enum song, FontsEnum font) { var item2 = new GenerateAndSendDataQuintupleDelegate(GeneralFunctions.GeneratePdfAndSendToRecipients.GenerateAndSendData); item.QuintupleGeneralChoiceEvent += item2; item.QuintupleGeneralChoiceEvent(model, contenttext, background, song, font); item.QuintupleGeneralChoiceEvent -= item2; }
public static string GeneratePdfFileForCustomer(string filename, string firstname, string lastname, string contenttext, BackgroundImageEnum backgroundimage, Mp3Enum song, FontsEnum font, string addition = "empty") { filename = filename + ".pdf"; Document doc = new Document(iTextSharp.text.PageSize.A4, 0f, 0f, 0f, 0f); PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream(filename, FileMode.Create)); //string backgroundfilepath; //if (backgroundimage == BackgroundImageEnum.Background1) //{ // string backgroundfile = "christmas-background1.jpg"; // FileInfo f = new FileInfo(backgroundfile); // backgroundfilepath = f.FullName; //} //if (backgroundimage == BackgroundImageEnum.Background2) //{ // string backgroundfile = "Christmas-background2.jpg"; // FileInfo f = new FileInfo(backgroundfile); // backgroundfilepath = f.FullName; //} //if (backgroundimage == BackgroundImageEnum.Background3) //{ // string backgroundfile = "christmas-background3.jpg"; // FileInfo f = new FileInfo(backgroundfile); // backgroundfilepath = f.FullName; //} doc.Open(); //string storestring1 = "Dear Sir/Ma'am @ thank you heartilly for de purchase at Sjonnie's liquor store @ we will keep you up to date with the latest news"; //string addnewlines1 = storestring1.Replace("@", Environment.NewLine); string storestring1 = "From: @"; storestring1 = storestring1 + "@" + firstname + " " + lastname + "@"; storestring1 = storestring1 + "@" + contenttext; string backgroundfile; if (backgroundimage == BackgroundImageEnum.Background1) { backgroundfile = "christmas-background1.jpg"; } if (backgroundimage == BackgroundImageEnum.Background2) { backgroundfile = "Christmas-background2.jpg"; } else { backgroundfile = "christmas-background3.jpg"; } FileInfo f = new FileInfo(backgroundfile); var backgroundfilepath = f.FullName; iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(backgroundfilepath); jpg.SetAbsolutePosition(0, 0); jpg.ScaleAbsolute(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height); jpg.Alignment = iTextSharp.text.Image.UNDERLYING; string addnewlines1 = storestring1.Replace("@", Environment.NewLine); //Paragraph paragraph = new Paragraph(addnewlines1); Paragraph paragraph = new Paragraph(); if (font == FontsEnum.Courier) { paragraph = new Paragraph(addnewlines1, new Font(Font.FontFamily.COURIER, 40)); } if (font == FontsEnum.Helvetica) { paragraph = new Paragraph(addnewlines1, new Font(Font.FontFamily.HELVETICA, 40)); } if (font == FontsEnum.TimesNewRoman) { paragraph = new Paragraph(addnewlines1, new Font(Font.FontFamily.TIMES_ROMAN, 40)); } //paragraph.Alignment = Element.ALIGN_CENTER; paragraph.Alignment = Element.ALIGN_CENTER; paragraph.PaddingTop = Element.ALIGN_MIDDLE; //ColumnText.ShowTextAligned(wri.DirectContent, Element.ALIGN_CENTER, new Phrase("test",), (PageSize.A4.Width/2),(PageSize.A4.Height/2), 0f); ColumnText column = new ColumnText(wri.DirectContent); column.SetSimpleColumn(new Rectangle((PageSize.A4.Width / 2) - 300, 0, PageSize.A4.Width, ((int)Math.Floor(PageSize.A4.Height / 1.5)))); column.AddElement(paragraph); column.Go(); //paragraph.IndentationRight = 100; //paragraph.IndentationLeft = 100; //if (font == FontsEnum.Arial) //{ // paragraph.Font = FontFactory.GetFont("Arial"); //} //else //{ // paragraph.Font = FontFactory.GetFont("Times New Roman"); //} doc.Add(jpg); //doc.Add(paragraph); doc.Close(); var pathpdffile = Path.GetFullPath(filename); return(pathpdffile); }