public static List <string> GetScreenshotFiles(string file, System.Drawing.Imaging.ImageFormat format) { List <string> files = new List <string>(); foreach (System.Windows.Forms.Screen s in System.Windows.Forms.Screen.AllScreens) { string f; if (s.Primary) { f = file; } else { f = PathRoutines.InsertSuffixBeforeFileExtension(file, "_" + PathRoutines.GetLegalizedFileName(s.DeviceName)); } System.Drawing.Rectangle bounds = s.Bounds; using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(bounds.Width, bounds.Height)) { using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap)) { g.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy); } bitmap.Save(f, format); } files.Add(f); } return(files); }
override public void __FillStartInputItemQueue(InputItemQueue start_input_item_queue, Type start_input_item_type) { Log.Main.Write("Filling queue of " + start_input_item_queue.Name + " with input file."); if (!File.Exists(Bot.Settings.Input.File)) { throw (new Exception("Input file " + Bot.Settings.Input.File + " does not exist.")); } if (Path.GetExtension(Bot.Settings.Input.File).StartsWith(".xls", StringComparison.InvariantCultureIgnoreCase)) { throw new Exception("Reading excel is not supported"); } FileReader fr = new FileReader(Bot.Settings.Input.File, Bot.Settings.Input.FileFormat); string input_locations = Cliver.Log.AppDir + "\\" + PathRoutines.GetFileNameFromPath("input_locations.txt"); if (!File.Exists(input_locations)) { throw (new Exception("Input file " + input_locations + " does not exist.")); } for (FileReader.Row r = fr.ReadLine(); r != null; r = fr.ReadLine()) { FileReader fr2 = new FileReader(input_locations, FileFormatEnum.TSV); for (FileReader.Row r2 = fr2.ReadLine(); r2 != null; r2 = fr2.ReadLine()) { start_input_item_queue.Add(new CustomBotCycle.SearchItem(r["Keyword"], r2["City"] + ", " + r2["State"])); } } if (start_input_item_queue.CountOfNew < 1) { LogMessage.Error("Input queue is empty so nothing is to do. Check your input data."); } }
public void Save(string file) { if (Name == null) { Name = PathRoutines.GetFileNameWithoutExtentionFromPath(file); } xd.Save(file); }
private void ChooseInputFile_Click(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.InitialDirectory = PathRoutines.GetFileDir(File.Text); d.ShowDialog(); if (!string.IsNullOrWhiteSpace(d.FileName)) { File.Text = d.FileName; } }
public SessionsForm() { InitializeComponent(); Ok.Enabled = false; Sessions.ValueMember = "Value"; Sessions.DisplayMember = "Name"; foreach (string d in Directory.EnumerateDirectories(Log.RootDir)) { if (Directory.Exists(d + "\\" + Cliver.Config.CONFIG_FOLDER_NAME)) { Sessions.Items.Add(new { Value = d, Name = PathRoutines.GetDirName(d) }); } } }
public CustomSession() { //InternetDateTime.CHECK_TEST_PERIOD_VALIDITY(2016, 12, 25); output_dir = PathRoutines.CreateDirectory(Dir + "\\files"); Cliver.BotGui.Program.BindProgressBar2InputItemQueue <EmailItem>(); BotCycle.TreatExceptionAsFatal = true; Session.GetInputItemQueue <EmailItem>().PickNext = pick_next_PdfItem; foreach (int i in Settings.Offer.SelectedAttachmentIds) { string f = PathRoutines.CreateDirectory(output_dir + "\\attachments") + "\\" + PathRoutines.GetFileNameFromPath(Settings.Offer.AttachmentFiles[i]); if (attachment_files.Add(f) && !File.Exists(f)) { File.Copy(Settings.Offer.AttachmentFiles[i], f); } } }
public static IEnumerable <Process> GetProcesses(string exeFile) { string exeFileDir = PathRoutines.GetFileDir(exeFile).ToLower(); return(Process.GetProcessesByName(PathRoutines.GetFileNameWithoutExtention(exeFile)).Where(p => { ProcessModule pm; try { pm = p.MainModule; } catch//sometimes it throws exception (if the process exited?) { pm = null; } return pm == null ? false : pm.FileName.StartsWith(exeFileDir, StringComparison.InvariantCultureIgnoreCase); } )); }
static private void m_pRtpSession_NewReceiveStream(object sender, RTP_ReceiveStreamEventArgs e) { try { //for unicast make sure that the stream is from the expected source ip if (!multicast && !e.Stream.SSRC.RtpEP.Address.Equals(source_ip)) { return; } session.Sessions[0].NewReceiveStream -= NewReceiveStream; AudioOutDevice device = AudioOut.Devices.Where(d => d.Name == Settings.Default.AudioDeviceName).FirstOrDefault(); if (device == null) { Message.Error("Could not find audio device: " + Settings.Default.AudioDeviceName); return; } AudioCodec ac = new PCMU(); ao = new AudioOut_RTP( device, e.Stream, new Dictionary <int, AudioCodec> { { payload, ac } } ); Dictionary <AudioCodec, string> acs2of = new Dictionary <AudioCodec, string>(); if (Settings.Default.RecordIncomingRtpStreams) { string wav_file = PathRoutines.CreateDirectory(Settings.Default.RtpStreamStorageFolder) + "\\" + e.Stream.SSRC.RtpEP.Address.ToString() + DateTime.Now.ToString("_yyyy-MM-dd_HH-mm-ss") + ".wav"; acs2of[ac] = wav_file; if (execute != null) { execute.Record = wav_file; } } ao.Start(volume100, acs2of); } catch (Exception ex) { Message.Error(ex); } }
public ProjectInstaller() { InitializeComponent(); this.Committed += delegate { //try //{ //starts for initial configuration under SYSTEM account Process p = Process.Start(Assembly.GetExecutingAssembly().Location, "-initial_configuration"); p.WaitForExit(); ProcessRoutines.CreateProcessAsUserOfCurrentSession(Assembly.GetExecutingAssembly().Location); //starts the process as the current user while the installer runs as SYSTEM //} //catch (Exception ex) //{ // //Message.Error(ex);//brings to an error: object is null // MessageBox.Show(); //} }; this.BeforeUninstall += delegate { //try //{ foreach (Process p in Process.GetProcessesByName(PathRoutines.GetFileNameWithoutExtentionFromPath(Assembly.GetExecutingAssembly().Location))) { ProcessRoutines.KillProcessTree(p.Id); } //} //catch (Exception e) //{ // //Message.Error(ex);//brings to an error: object is null // MessageBox.Show(); // //throw e;//to stop uninstalling(?) //} }; }
static public void Run(Action <int, int> progress) { Log.Main.Inform("STARTED"); progress(0, 0); if (string.IsNullOrWhiteSpace(Settings.General.InputFolder)) { Win.LogMessage.Error("Input Folder is not specified."); return; } if (!Directory.Exists(Settings.General.InputFolder)) { Win.LogMessage.Error("Input folder '" + Settings.General.InputFolder + "' does not exist."); return; } string output_records_file = FileSystemRoutines.CreateDirectory(Settings.General.OutputFolder) + "\\_output.csv"; if (File.Exists(output_records_file)) { File.Delete(output_records_file); } TextWriter tw = new StreamWriter(output_records_file, false); List <Template2> active_templates = Settings.Template2s.Template2s.Where(x => x.Active).OrderBy(x => x.OrderWeight).ThenByDescending(x => { return(Settings.TemplateLocalInfo.GetInfo(x.Template.Name).UsedTime); }).ToList(); if (active_templates.Count < 1) { Win.LogMessage.Error("There is no active template!"); return; } List <string> headers = new List <string> { "File", "Template", "First Page", "Last Page", "Invoice", "Total", "Product Name", "Product Cost" }; tw.WriteLine(FieldPreparation.GetCsvHeaderLine(headers, FieldPreparation.FieldSeparator.COMMA)); List <string> files = FileSystemRoutines.GetFiles(Settings.General.InputFolder, false); files.Remove(output_records_file); files = files.Select(f => new FileInfo(f)).Where(fi => !fi.Attributes.HasFlag(FileAttributes.Hidden)).Select(fi => fi.FullName).ToList(); int processed_files = 0; int total_files = files.Count; List <string> failed_files = new List <string>(); progress(processed_files, total_files); foreach (string f in files) { try { bool?result = PdfProcessor.Process(f, active_templates, (templateName, firstPageI, lastPageI, document) => { { List <string> values = new List <string>() { PathRoutines.GetFileName(f), templateName, firstPageI.ToString(), lastPageI.ToString(), document.Invoice, document.Total, "", "" }; tw.WriteLine(FieldPreparation.GetCsvLine(values, FieldPreparation.FieldSeparator.COMMA)); } foreach (PdfProcessor.Document.Product p in document.Products) { List <string> values = new List <string>() { "", "", "", "", "", "", p.Name, p.Cost }; tw.WriteLine(FieldPreparation.GetCsvLine(values, FieldPreparation.FieldSeparator.COMMA)); } }); if (result != true) { failed_files.Add(f); } } catch (Exception e) { Log.Main.Error("Processing file '" + f + "'", e); failed_files.Add(f); } progress(++processed_files, total_files); } tw.Close(); try { System.Diagnostics.Process.Start(output_records_file); } catch { } Log.Main.Inform("COMPLETED:\r\nTotal files: " + processed_files + "\r\nSuccess files: " + (processed_files - failed_files.Count) + "\r\nFailed files: " + failed_files.Count + "\r\n" + string.Join("\r\n", failed_files)); if (failed_files.Count > 0) { Message.Error("There were " + failed_files.Count + " failed files.\r\nSee details in the log."); } //progress(0, 0); }
public ProjectInstaller() { InitializeComponent(); this.Committed += delegate { //try //{ ServiceController sc = new ServiceController(Program.SERVICE_NAME); sc.Start(); //} //catch (Exception e) //{ // //Message.Error(ex);//brings to an error: object is null // System.Windows.Forms.MessageBox.Show(e.Message); //} }; this.BeforeUninstall += delegate { //try //{ ServiceController sc = new ServiceController(Program.SERVICE_NAME); if (sc.Status != ServiceControllerStatus.Stopped) { sc.Stop(); double timeoutSecs = 20; sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(timeoutSecs)); if (sc.Status != ServiceControllerStatus.Stopped) { throw new Exception("Could not stop service '" + Cliver.CisteraScreenCaptureService.Program.SERVICE_NAME + "'. To unistall it, stop it manually."); } } //} //catch (Exception e) //{ // //Message.Error(ex);//brings to an error: object is null // MessageBox.Show(); // throw e;//to stop uninstalling(?) //} try { string servicePath = this.Context.Parameters["assemblypath"]; AssemblyRoutines.AssemblyInfo ai = new AssemblyRoutines.AssemblyInfo(servicePath); WindowsFirewall.DeleteRule(ai.AssemblyProduct, servicePath); WindowsFirewall.DeleteRule(ffmpegFirewallRuleName, PathRoutines.GetDirFromPath(servicePath) + "\\ffmpeg.exe"); } catch (Exception e) { //MessageBox.Show("You'll may need to set firewall manually because of the following error that happened while setting firewall:\r\n" + e.Message, "Cistera Screen Capture", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); // throw e; } }; this.AfterInstall += delegate { try { string servicePath = this.Context.Parameters["assemblypath"]; AssemblyRoutines.AssemblyInfo ai = new AssemblyRoutines.AssemblyInfo(servicePath); WindowsFirewall.DeleteRule(ai.AssemblyProduct); WindowsFirewall.AllowProgram(ai.AssemblyProduct, servicePath, WindowsFirewall.Direction.IN); WindowsFirewall.AllowProgram(ai.AssemblyProduct, servicePath, WindowsFirewall.Direction.OUT); WindowsFirewall.DeleteRule(ffmpegFirewallRuleName); WindowsFirewall.AllowProgram(ffmpegFirewallRuleName, PathRoutines.GetDirFromPath(servicePath) + "\\ffmpeg.exe", WindowsFirewall.Direction.OUT); } catch (Exception e) { MessageBox.Show("You'll may need to set firewall manually because of the following error that happened while setting firewall:\r\n" + e.Message, "Cistera Screen Capture", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); // throw e; } }; }
public TemplateForm(TemplateManager templateManager) { InitializeComponent(); Icon = Win.AssemblyRoutines.GetAppIcon(); Text = Program.FullName + " - Template Editor"; templateManager.TemplateForm = this; this.templateManager = templateManager; this.bitmapPreparationForm = new ScanTemplateForm(this); initializeAnchorsTable(); initializeConditionsTable(); initializeFieldsTable(); TesseractPageSegMode.DataSource = Enum.GetValues(typeof(Tesseract.PageSegMode)); picture.MouseDown += delegate(object sender, MouseEventArgs e) { if (pages == null) { return; } Point p = new Point((int)(e.X / (float)pictureScale.Value), (int)(e.Y / (float)pictureScale.Value)); ResizebleBox rb = findResizebleBox(p, out ResizebleBoxSides resizebleBoxSide); if (rb != null) { drawingMode = resizebleBoxSide == ResizebleBoxSides.Left || resizebleBoxSide == ResizebleBoxSides.Right ? DrawingModes.resizingSelectionBoxV : DrawingModes.resizingSelectionBoxH; Cursor.Current = drawingMode == DrawingModes.resizingSelectionBoxV ? Cursors.VSplit : Cursors.HSplit; selectionBoxPoint0 = rb.R.Location; selectionBoxPoint1 = rb.R.Location; selectionBoxPoint2 = new Point(rb.R.Right, rb.R.Bottom); } else { if (ModifierKeys.HasFlag(Keys.Shift)) { drawingMode = DrawingModes.movingImage; Cursor.Current = Cursors.SizeAll; screenMousePosition0 = Control.MousePosition; imageScrollPostion0 = new Point(splitContainer1.Panel2.HorizontalScroll.Value, splitContainer1.Panel2.VerticalScroll.Value);//to avoid jerking } else { drawingMode = DrawingModes.drawingSelectionBox; selectionBoxPoint0 = p; selectionBoxPoint1 = p; selectionBoxPoint2 = p; } } showSelectionCoordinates(selectionBoxPoint1); }; picture.MouseWheel += delegate(object sender, MouseEventArgs e) { if (pages == null) { return; } }; picture.MouseMove += delegate(object sender, MouseEventArgs e) { if (pages == null) { return; } Point p; if (drawingMode == DrawingModes.movingImage) { p = Control.MousePosition; int h = imageScrollPostion0.X + screenMousePosition0.X - p.X; if (h < splitContainer1.Panel2.HorizontalScroll.Minimum) { h = splitContainer1.Panel2.HorizontalScroll.Minimum; } else if (h > splitContainer1.Panel2.HorizontalScroll.Maximum) { h = splitContainer1.Panel2.HorizontalScroll.Maximum; } splitContainer1.Panel2.HorizontalScroll.Value = h; int v = imageScrollPostion0.Y + screenMousePosition0.Y - p.Y; if (v < splitContainer1.Panel2.VerticalScroll.Minimum) { v = splitContainer1.Panel2.VerticalScroll.Minimum; } else if (v > splitContainer1.Panel2.VerticalScroll.Maximum) { v = splitContainer1.Panel2.VerticalScroll.Maximum; } splitContainer1.Panel2.VerticalScroll.Value = v; return; } p = new Point((int)(e.X / (float)pictureScale.Value), (int)(e.Y / (float)pictureScale.Value)); switch (drawingMode) { case DrawingModes.NULL: showSelectionCoordinates(p); if (findResizebleBox(p, out ResizebleBoxSides resizebleBoxSide) != null) { Cursor.Current = resizebleBoxSide == ResizebleBoxSides.Left || resizebleBoxSide == ResizebleBoxSides.Right ? Cursors.VSplit : Cursors.HSplit; } else { Cursor.Current = Cursors.Default; } return; case DrawingModes.drawingSelectionBox: if (selectionBoxPoint0.X < p.X) { selectionBoxPoint1.X = selectionBoxPoint0.X; selectionBoxPoint2.X = p.X; } else { selectionBoxPoint1.X = p.X; selectionBoxPoint2.X = selectionBoxPoint0.X; } if (selectionBoxPoint0.Y < p.Y) { selectionBoxPoint1.Y = selectionBoxPoint0.Y; selectionBoxPoint2.Y = p.Y; } else { selectionBoxPoint1.Y = p.Y; selectionBoxPoint2.Y = selectionBoxPoint0.Y; } break; case DrawingModes.resizingSelectionBoxV: if (Math.Abs(selectionBoxPoint2.X - p.X) < Math.Abs(p.X - selectionBoxPoint1.X)) { selectionBoxPoint2.X = p.X; } else { selectionBoxPoint1.X = p.X; } break; case DrawingModes.resizingSelectionBoxH: if (Math.Abs(selectionBoxPoint2.Y - p.Y) < Math.Abs(p.Y - selectionBoxPoint1.Y)) { selectionBoxPoint2.Y = p.Y; } else { selectionBoxPoint1.Y = p.Y; } break; } showSelectionCoordinates(selectionBoxPoint1, selectionBoxPoint2); RectangleF r = new RectangleF(selectionBoxPoint1.X, selectionBoxPoint1.Y, selectionBoxPoint2.X - selectionBoxPoint1.X, selectionBoxPoint2.Y - selectionBoxPoint1.Y); clearImageFromBoxes(); drawBoxes(Settings.Appearance.SelectionBoxColor, Settings.Appearance.SelectionBoxBorderWidth, new List <System.Drawing.RectangleF> { r }); }; picture.MouseUp += delegate(object sender, MouseEventArgs e) { try { if (pages == null) { return; } if (drawingMode == DrawingModes.NULL) { return; } if (drawingMode == DrawingModes.movingImage) { Cursor.Current = Cursors.Default; } drawingMode = DrawingModes.NULL; Template.RectangleF r = new Template.RectangleF(selectionBoxPoint1.X, selectionBoxPoint1.Y, selectionBoxPoint2.X - selectionBoxPoint1.X, selectionBoxPoint2.Y - selectionBoxPoint1.Y); if (r.Width == 0 || r.Y == 0)//accidental tap { return; } switch (settingMode) { case SettingModes.SetAnchor: { if (currentAnchorControl == null) { break; } //currentAnchorControl.SetTagFromControl();??? Template.Anchor a = (Template.Anchor)currentAnchorControl.Row.Tag; if (pages[currentPageI].DetectedImageScale >= 0 && pages[currentPageI].DetectedImageScale < 1 && a.Id == GetTemplateFromUI(false).ScalingAnchorId) { Message.Exclaim("When the detected image scale is not 1, changing coordinates of the scaling anchor must not be done. Either switch off scaling by anchor and reload the page or open a page where the detected image scale is 1.", this); break; } a.Position = new Template.PointF { X = r.X, Y = r.Y }; try { switch (a.Type) { case Template.Anchor.Types.PdfText: { Template.Anchor.PdfText pt = (Template.Anchor.PdfText)a; pt.CharBoxs = new List <Template.Anchor.PdfText.CharBox>(); foreach (Pdf.CharBox cb in Pdf.GetCharBoxsSurroundedByRectangle(pages[currentPageI].PdfCharBoxs, r.GetSystemRectangleF(), true)) { pt.CharBoxs.Add(new Template.Anchor.PdfText.CharBox { Char = cb.Char, Rectangle = new Template.RectangleF(cb.R.X, cb.R.Y, cb.R.Width, cb.R.Height), }); } pt.Size = new Template.SizeF { Width = r.Width, Height = r.Height }; } break; case Template.Anchor.Types.OcrText: { Template.Anchor.OcrText ot = (Template.Anchor.OcrText)a; ot.CharBoxs = new List <Template.Anchor.OcrText.CharBox>(); var selectedOcrCharBoxs = new List <Ocr.CharBox>(); if (ot.OcrEntirePage) { selectedOcrCharBoxs.AddRange(Ocr.GetCharBoxsSurroundedByRectangle(pages[currentPageI].ActiveTemplateOcrCharBoxs, r.GetSystemRectangleF())); } else { using (Bitmap b = pages[currentPageI].GetRectangleFromActiveTemplateBitmap(r.X / Settings.Constants.Pdf2ImageResolutionRatio, r.Y / Settings.Constants.Pdf2ImageResolutionRatio, r.Width / Settings.Constants.Pdf2ImageResolutionRatio, r.Height / Settings.Constants.Pdf2ImageResolutionRatio)) { if (b == null) { throw new Exception("Selected image is empty."); } foreach (Ocr.CharBox cb in Ocr.This.GetCharBoxs(b, pages.ActiveTemplate.TesseractPageSegMode)) { cb.R.X += r.X; cb.R.Y += r.Y; selectedOcrCharBoxs.Add(cb); } } } foreach (Ocr.CharBox cb in selectedOcrCharBoxs) { ot.CharBoxs.Add(new Template.Anchor.OcrText.CharBox { Char = cb.Char, Rectangle = new Template.RectangleF(cb.R.X, cb.R.Y, cb.R.Width, cb.R.Height), }); } ot.Size = new Template.SizeF { Width = r.Width, Height = r.Height }; } break; case Template.Anchor.Types.ImageData: { Template.Anchor.ImageData id = (Template.Anchor.ImageData)a; using (Bitmap b = pages[currentPageI].GetRectangleFromActiveTemplateBitmap(r.X / Settings.Constants.Pdf2ImageResolutionRatio, r.Y / Settings.Constants.Pdf2ImageResolutionRatio, r.Width / Settings.Constants.Pdf2ImageResolutionRatio, r.Height / Settings.Constants.Pdf2ImageResolutionRatio)) { if (b == null) { throw new Exception("Selected image is empty."); } id.Image = new ImageData(b); } } break; case Template.Anchor.Types.CvImage: { Template.Anchor.CvImage ci = (Template.Anchor.CvImage)a; using (Bitmap b = pages[currentPageI].GetRectangleFromActiveTemplateBitmap(r.X / Settings.Constants.Pdf2ImageResolutionRatio, r.Y / Settings.Constants.Pdf2ImageResolutionRatio, r.Width / Settings.Constants.Pdf2ImageResolutionRatio, r.Height / Settings.Constants.Pdf2ImageResolutionRatio)) { if (b == null) { throw new Exception("Selected image is empty."); } ci.Image = new CvImage(b); } } break; default: throw new Exception("Unknown option: " + a.Type); } setAnchorRow(currentAnchorControl.Row, a); clearImageFromBoxes(); findAndDrawAnchor(a.Id); } finally { anchors.EndEdit(); } } break; case SettingModes.SetField: { if (fields.SelectedRows.Count < 1) { break; } var row = fields.SelectedRows[0]; Template.Field f = (Template.Field)row.Tag; f.Rectangle = r; if (f.LeftAnchor != null) { Page.AnchorActualInfo aai = pages[currentPageI].GetAnchorActualInfo(f.LeftAnchor.Id); f.LeftAnchor.Shift = aai.Shift.Width; } if (f.TopAnchor != null) { Page.AnchorActualInfo aai = pages[currentPageI].GetAnchorActualInfo(f.TopAnchor.Id); f.TopAnchor.Shift = aai.Shift.Height; } if (f.RightAnchor != null) { Page.AnchorActualInfo aai = pages[currentPageI].GetAnchorActualInfo(f.RightAnchor.Id); f.RightAnchor.Shift = aai.Shift.Width; } if (f.BottomAnchor != null) { Page.AnchorActualInfo aai = pages[currentPageI].GetAnchorActualInfo(f.BottomAnchor.Id); f.BottomAnchor.Shift = aai.Shift.Height; } setFieldRow(row, f); } break; case SettingModes.NULL: break; default: throw new Exception("Unknown option: " + settingMode); } } catch (Exception ex) { Message.Error2(ex, this); } }; Shown += delegate { Application.DoEvents();//make form be drawn completely setUIFromTemplate(templateManager.Template); }; this.EnumControls((Control c) => { if (c is SplitContainer s) { s.BackColor = Color.FromArgb(80, 70, 0); s.SplitterWidth = 2; s.Panel1.BackColor = SystemColors.Control; s.Panel2.BackColor = SystemColors.Control; } }, true); testFile.TextChanged += delegate { try { dispose(false); if (string.IsNullOrWhiteSpace(testFile.Text)) { return; } templateManager.LastTestFile = testFile.Text; testFile.SelectionStart = testFile.Text.Length; testFile.ScrollToCaret(); if (!File.Exists(testFile.Text)) { string m = "File '" + testFile.Text + "' does not exist!"; Log.Error(m); Message.Error(m, this); return; } pages = new PageCollection(testFile.Text, true); totalPageNumber = pages.TotalCount; lTotalPages.Text = " / " + totalPageNumber; showPage(1); } catch (Exception ex) { Log.Error(ex); Message.Error(ex, this); } }; pictureScale.ValueChanged += delegate { if (!loadingTemplate) { setScaledImage(); } }; Load += delegate { //Application.DoEvents();//make form be drawn completely //BeginInvoke((Action<Template>)setUIFromTemplate, templateManager.Template); }; FormClosed += delegate { bitmapPreparationForm.Close(); }; bSave.Click += Save_Click; bOK.Click += OK_Click; bCancel.Click += delegate { Close(); }; Help.LinkClicked += Help_LinkClicked; Configure.LinkClicked += Configure_LinkClicked; About.LinkClicked += About_LinkClicked; bTestFile.Click += delegate(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); if (!string.IsNullOrWhiteSpace(testFile.Text)) { d.InitialDirectory = PathRoutines.GetFileDir(testFile.Text); } else if (!string.IsNullOrWhiteSpace(templateManager.TestFileDefaultFolder)) { d.InitialDirectory = templateManager.TestFileDefaultFolder; } d.Filter = "PDF|*.pdf|" + "All files (*.*)|*.*"; if (d.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } testFile.Text = d.FileName; }; ShowPdfText.LinkClicked += ShowPdfText_LinkClicked; ShowOcrText.LinkClicked += ShowOcrText_LinkClicked; ShowAsJson.LinkClicked += showAsJson_LinkClicked; tCurrentPage.Leave += delegate { changeCurrentPage(); }; tCurrentPage.KeyDown += delegate(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { changeCurrentPage(); } }; }
public TemplateForm(TemplateManager templateManager) { InitializeComponent(); Icon = Win.AssemblyRoutines.GetAppIcon(); Text = Program.FullName + ": Template Editor"; this.templateManager = templateManager; initializeAnchorsTable(); initializeConditionsTable(); initializeFieldsTable(); picture.MouseDown += delegate(object sender, MouseEventArgs e) { if (pages == null) { return; } Point p = new Point((int)(e.X / (float)pictureScale.Value), (int)(e.Y / (float)pictureScale.Value)); ResizebleBox rb = findResizebleBox(p, out ResizebleBoxSides resizebleBoxSide); if (rb != null) { drawingMode = resizebleBoxSide == ResizebleBoxSides.Left || resizebleBoxSide == ResizebleBoxSides.Right ? DrawingModes.resizingSelectionBoxV : DrawingModes.resizingSelectionBoxH; Cursor.Current = drawingMode == DrawingModes.resizingSelectionBoxV ? Cursors.VSplit : Cursors.HSplit; selectionBoxPoint0 = rb.R.Location; selectionBoxPoint1 = rb.R.Location; selectionBoxPoint2 = new Point(rb.R.Right, rb.R.Bottom); } else { drawingMode = DrawingModes.drawingSelectionBox; selectionBoxPoint0 = p; selectionBoxPoint1 = p; selectionBoxPoint2 = p; } selectionCoordinates.Text = selectionBoxPoint1.ToString(); }; picture.MouseMove += delegate(object sender, MouseEventArgs e) { if (pages == null) { return; } Point p = new Point((int)(e.X / (float)pictureScale.Value), (int)(e.Y / (float)pictureScale.Value)); switch (drawingMode) { case DrawingModes.NULL: selectionCoordinates.Text = p.ToString(); if (findResizebleBox(p, out ResizebleBoxSides resizebleBoxSide) != null) { Cursor.Current = resizebleBoxSide == ResizebleBoxSides.Left || resizebleBoxSide == ResizebleBoxSides.Right ? Cursors.VSplit : Cursors.HSplit; } else { Cursor.Current = Cursors.Default; } return; case DrawingModes.drawingSelectionBox: if (selectionBoxPoint0.X < p.X) { selectionBoxPoint1.X = selectionBoxPoint0.X; selectionBoxPoint2.X = p.X; } else { selectionBoxPoint1.X = p.X; selectionBoxPoint2.X = selectionBoxPoint0.X; } if (selectionBoxPoint0.Y < p.Y) { selectionBoxPoint1.Y = selectionBoxPoint0.Y; selectionBoxPoint2.Y = p.Y; } else { selectionBoxPoint1.Y = p.Y; selectionBoxPoint2.Y = selectionBoxPoint0.Y; } break; case DrawingModes.resizingSelectionBoxV: if (Math.Abs(selectionBoxPoint2.X - p.X) < Math.Abs(p.X - selectionBoxPoint1.X)) { selectionBoxPoint2.X = p.X; } else { selectionBoxPoint1.X = p.X; } break; case DrawingModes.resizingSelectionBoxH: if (Math.Abs(selectionBoxPoint2.Y - p.Y) < Math.Abs(p.Y - selectionBoxPoint1.Y)) { selectionBoxPoint2.Y = p.Y; } else { selectionBoxPoint1.Y = p.Y; } break; } selectionCoordinates.Text = selectionBoxPoint1.ToString() + ":" + selectionBoxPoint2.ToString(); RectangleF r = new RectangleF(selectionBoxPoint1.X, selectionBoxPoint1.Y, selectionBoxPoint2.X - selectionBoxPoint1.X, selectionBoxPoint2.Y - selectionBoxPoint1.Y); clearImageFromBoxes(); drawBoxes(Settings.Appearance.SelectionBoxColor, Settings.Appearance.SelectionBoxBorderWidth, new List <System.Drawing.RectangleF> { r }); }; picture.MouseUp += delegate(object sender, MouseEventArgs e) { try { if (pages == null) { return; } if (drawingMode == DrawingModes.NULL) { return; } drawingMode = DrawingModes.NULL; Template.RectangleF r = new Template.RectangleF(selectionBoxPoint1.X, selectionBoxPoint1.Y, selectionBoxPoint2.X - selectionBoxPoint1.X, selectionBoxPoint2.Y - selectionBoxPoint1.Y); if (r.Width == 0 || r.Y == 0)//accidental tap { return; } switch (settingMode) { case SettingModes.SetAnchor: { if (currentAnchorControl == null) { break; } currentAnchorControl.SetTagFromControl(); Template.Anchor a = (Template.Anchor)currentAnchorControl.Row.Tag; a.Position = new Template.PointF { X = r.X, Y = r.Y }; try { switch (a.Type) { case Template.Anchor.Types.PdfText: { Template.Anchor.PdfText pt = (Template.Anchor.PdfText)a; pt.CharBoxs = new List <Template.Anchor.PdfText.CharBox>(); List <Pdf.Line> lines = Pdf.GetLines(Pdf.GetCharBoxsSurroundedByRectangle(pages[currentPageI].PdfCharBoxs, r.GetSystemRectangleF(), true), null); foreach (Pdf.Line l in lines) { foreach (Pdf.CharBox cb in l.CharBoxs) { pt.CharBoxs.Add(new Template.Anchor.PdfText.CharBox { Char = cb.Char, Rectangle = new Template.RectangleF(cb.R.X, cb.R.Y, cb.R.Width, cb.R.Height), }); } } pt.Size = new Template.SizeF { Width = r.Width, Height = r.Height }; } break; case Template.Anchor.Types.OcrText: { Template.Anchor.OcrText ot = (Template.Anchor.OcrText)a; ot.CharBoxs = new List <Template.Anchor.OcrText.CharBox>(); var selectedOcrCharBoxs = new List <Ocr.CharBox>(); if (ot.OcrEntirePage) { selectedOcrCharBoxs.AddRange(Ocr.GetCharBoxsSurroundedByRectangle(pages[currentPageI].ActiveTemplateOcrCharBoxs, r.GetSystemRectangleF())); } else { foreach (Ocr.CharBox cb in Ocr.This.GetCharBoxs(pages[currentPageI].GetRectangleFromActiveTemplateBitmap(r.X / Settings.Constants.Image2PdfResolutionRatio, r.Y / Settings.Constants.Image2PdfResolutionRatio, r.Width / Settings.Constants.Image2PdfResolutionRatio, r.Height / Settings.Constants.Image2PdfResolutionRatio))) { cb.R.X += r.X; cb.R.Y += r.Y; selectedOcrCharBoxs.Add(cb); } } foreach (Ocr.Line l in Ocr.GetLines(selectedOcrCharBoxs, null)) { foreach (Ocr.CharBox cb in l.CharBoxs) { ot.CharBoxs.Add(new Template.Anchor.OcrText.CharBox { Char = cb.Char, Rectangle = new Template.RectangleF(cb.R.X, cb.R.Y, cb.R.Width, cb.R.Height), }); } } ot.Size = new Template.SizeF { Width = r.Width, Height = r.Height }; } break; case Template.Anchor.Types.ImageData: { Template.Anchor.ImageData id = (Template.Anchor.ImageData)a; using (Bitmap b = pages[currentPageI].GetRectangleFromActiveTemplateBitmap(r.X / Settings.Constants.Image2PdfResolutionRatio, r.Y / Settings.Constants.Image2PdfResolutionRatio, r.Width / Settings.Constants.Image2PdfResolutionRatio, r.Height / Settings.Constants.Image2PdfResolutionRatio)) { id.Image = new ImageData(b); } } break; case Template.Anchor.Types.CvImage: { Template.Anchor.CvImage ci = (Template.Anchor.CvImage)a; using (Bitmap b = pages[currentPageI].GetRectangleFromActiveTemplateBitmap(r.X / Settings.Constants.Image2PdfResolutionRatio, r.Y / Settings.Constants.Image2PdfResolutionRatio, r.Width / Settings.Constants.Image2PdfResolutionRatio, r.Height / Settings.Constants.Image2PdfResolutionRatio)) { ci.Image = new CvImage(b); } } break; default: throw new Exception("Unknown option: " + a.Type); } setAnchorRow(currentAnchorControl.Row, a); clearImageFromBoxes(); findAndDrawAnchor(a.Id); } finally { anchors.EndEdit(); } } break; case SettingModes.SetField: { if (fields.SelectedRows.Count < 1) { break; } var row = fields.SelectedRows[0]; Template.Field f = (Template.Field)row.Tag; f.Rectangle = r; if (f.LeftAnchor != null) { Page.AnchorActualInfo aai = pages[currentPageI].GetAnchorActualInfo(f.LeftAnchor.Id); f.LeftAnchor.Shift = aai.Shift.Width; } if (f.TopAnchor != null) { Page.AnchorActualInfo aai = pages[currentPageI].GetAnchorActualInfo(f.TopAnchor.Id); f.TopAnchor.Shift = aai.Shift.Height; } if (f.RightAnchor != null) { Page.AnchorActualInfo aai = pages[currentPageI].GetAnchorActualInfo(f.RightAnchor.Id); f.RightAnchor.Shift = aai.Shift.Width; } if (f.BottomAnchor != null) { Page.AnchorActualInfo aai = pages[currentPageI].GetAnchorActualInfo(f.BottomAnchor.Id); f.BottomAnchor.Shift = aai.Shift.Height; } setFieldRow(row, f); extractFieldAndDrawSelectionBox(f); //owners2resizebleBox[f] = new ResizebleBox(f, f.Rectangle.GetSystemRectangleF(), Settings.Appearance.SelectionBoxBorderWidth); } break; case SettingModes.NULL: break; default: throw new Exception("Unknown option: " + settingMode); } } catch (Exception ex) { Message.Error2(ex); } }; Shown += delegate { Application.DoEvents();//make form be drawn completely setUIFromTemplate(templateManager.Template); }; FormClosed += delegate { if (scaledCurrentPageBitmap != null) { scaledCurrentPageBitmap.Dispose(); scaledCurrentPageBitmap = null; } if (pages != null) { pages.Dispose(); pages = null; } templateManager.LastTestFile = testFile.Text; }; this.EnumControls((Control c) => { if (c is SplitContainer s) { s.BackColor = Color.FromArgb(80, 70, 0); s.SplitterWidth = 2; s.Panel1.BackColor = SystemColors.Control; s.Panel2.BackColor = SystemColors.Control; } }, true); testFile.TextChanged += delegate { try { if (picture.Image != null) { picture.Image.Dispose(); picture.Image = null; } if (scaledCurrentPageBitmap != null) { scaledCurrentPageBitmap.Dispose(); scaledCurrentPageBitmap = null; } if (pages != null) { pages.Dispose(); pages = null; } if (string.IsNullOrWhiteSpace(testFile.Text)) { return; } testFile.SelectionStart = testFile.Text.Length; testFile.ScrollToCaret(); if (!File.Exists(testFile.Text)) { Win.LogMessage.Error("File '" + testFile.Text + "' does not exist!"); return; } pages = new PageCollection(testFile.Text); totalPageNumber = pages.PdfReader.NumberOfPages; lTotalPages.Text = " / " + totalPageNumber; showPage(1); } catch (Exception ex) { Win.LogMessage.Error(ex); } }; pictureScale.ValueChanged += delegate { if (!loadingTemplate) { setScaledImage(); } }; pageRotation.SelectedIndexChanged += delegate { reloadPageBitmaps(); //showPage(currentPageI); }; autoDeskew.CheckedChanged += delegate { reloadPageBitmaps(); //showPage(currentPageI); }; Load += delegate { }; save.Click += Save_Click; cancel.Click += delegate { Close(); }; Help.LinkClicked += Help_LinkClicked; Configure.LinkClicked += Configure_LinkClicked; About.LinkClicked += About_LinkClicked; bTestFile.Click += delegate(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); if (!string.IsNullOrWhiteSpace(testFile.Text)) { d.InitialDirectory = PathRoutines.GetFileDir(testFile.Text); } else if (!string.IsNullOrWhiteSpace(templateManager.TestFileDefaultFolder)) { d.InitialDirectory = templateManager.TestFileDefaultFolder; } d.Filter = "PDF|*.pdf|" + "All files (*.*)|*.*"; if (d.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } testFile.Text = d.FileName; }; ShowPdfText.LinkClicked += ShowPdfText_LinkClicked; ShowOcrText.LinkClicked += ShowOcrText_LinkClicked; ShowAsJson.LinkClicked += showAsJson_LinkClicked; tCurrentPage.Leave += delegate { changeCurrentPage(); }; tCurrentPage.KeyDown += delegate(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { changeCurrentPage(); } }; }
public static InfoWindow Create(string title, string text, string image_url, string action_name, Action action, string sound_file = null, Brush box_brush = null, Brush button_brush = null) { InfoWindow w = null; if (text.Length > Settings.View.InfoToastMaxTextLength) { text = text.Remove(Settings.View.InfoToastMaxTextLength, text.Length - Settings.View.InfoToastMaxTextLength) + "<...>"; } Action a = () => { w = new InfoWindow(title, text, image_url, action_name, action); w.SetAppearance(box_brush, button_brush); WindowInteropHelper h = new WindowInteropHelper(w); h.EnsureHandle(); w.Show(); ThreadRoutines.StartTry(() => { Thread.Sleep(Settings.View.InfoToastLifeTimeInSecs * 1000); w.Dispatcher.BeginInvoke((Action)(() => { w.Close(); })); }); if (string.IsNullOrWhiteSpace(sound_file)) { sound_file = Settings.View.InfoSoundFile; } sound_file = PathRoutines.GetAbsolutePath(sound_file); SoundPlayer sp = new SoundPlayer(sound_file); sp.Play(); }; lock (ws) { if (dispatcher == null) {//!!!the following code does not work in static constructor because creates a deadlock!!! dispatcher_t = ThreadRoutines.StartTry(() => { if (invisible_owner_w == null) {//this window is used to hide notification windows from Alt+Tab panel invisible_owner_w = new Window(); invisible_owner_w.Width = 0; invisible_owner_w.Height = 0; invisible_owner_w.WindowStyle = WindowStyle.ToolWindow; invisible_owner_w.ShowInTaskbar = false; invisible_owner_w.Show(); invisible_owner_w.Hide(); } if (dispatcher == null) { //dispatcher = System.Windows.Threading.Dispatcher.CurrentDispatcher; dispatcher = System.Windows.Threading.Dispatcher.FromThread(Thread.CurrentThread); System.Windows.Threading.Dispatcher.Run(); } }, null, null, true, ApartmentState.STA); if (!SleepRoutines.WaitForCondition(() => { return(dispatcher != null); }, 3000)) { throw new Exception("Could not get dispatcher."); } } } dispatcher.Invoke(a); return(w); }
private void bTestFileFilterRegex_Click(object sender, EventArgs e) { try { string d = string.IsNullOrWhiteSpace(template2.Template.Editor.TestFile) ? Settings.General.InputFolder : PathRoutines.GetFileDir(template2.Template.Editor.TestFile); FileFilterForm f = new FileFilterForm(d, Serialization.Json.Deserialize <Regex>(FileFilterRegex.Text)); f.ShowDialog(); } catch (Exception ex) { Win.LogMessage.Error(ex); } }
override public void __Processor(BotCycle bc) { CustomSession session = (CustomSession)bc.Session; string address = new System.Globalization.CultureInfo("en-US", false).TextInfo.ToTitleCase(Address.ToLower()); string file_dir = PathRoutines.CreateDirectory(session.output_dir + "\\" + address, true); string output_pdf = file_dir + "\\" + Regex.Replace(address + " RPA.pdf", @"\s+", " "); { //lock (template_pdf) //{ // File.Copy(template_pdf, pdf); //} PdfReader.unethicalreading = true; PdfReader pr = new PdfReader(template_pdf); //pr.RemoveUsageRights(); //pr.SelectPages("7,8"); PdfStamper ps = new PdfStamper(pr, new FileStream(output_pdf, FileMode.Create, FileAccess.Write, FileShare.None)); //string fs = ""; //foreach (KeyValuePair<string, AcroFields.Item> kvp in ps.AcroFields.Fields) // fs += "\n{\"" + kvp.Key + "\", \"\"},"; set_field(ps.AcroFields, "Todays Date", DateTime.Today.ToShortDateString()); set_field(ps.AcroFields, "Buyer Name", Settings.Parties.BuyerProfile.Name); set_field(ps.AcroFields, "Address and Unit Number", address + " " + UnitNumber); set_field(ps.AcroFields, "City/Town", City); //set_field(ps.AcroFields, "CLARK", ); set_field(ps.AcroFields, "Zip", ZipCode); set_field(ps.AcroFields, "PARCEL NUMBER", ParcelNumber); set_field(ps.AcroFields, "OfferAmt", OfferAmt); string offer_amt_ = Regex.Replace(OfferAmt, @"[^\d]", ""); if (offer_amt_.Length > 0) { set_field(ps.AcroFields, "OfferAmt in words", ConvertionRoutines.NumberToWords(int.Parse(offer_amt_)).ToUpper()); } set_field(ps.AcroFields, "EMD", Settings.Offer.Emd); //set_field(ps.AcroFields, "Check Box1", ); //set_field(ps.AcroFields, "Balance", ); set_field(ps.AcroFields, "Co Buyer Name", Settings.Parties.BuyerProfile.CoBuyerName); set_field(ps.AcroFields, "<address> <UnitNumber> <City/town> NV <ZIP Code>", address + " " + UnitNumber + ", " + City + " NV " + ZipCode); set_field(ps.AcroFields, "ML#", "ALL PER ML# " + ML_Id); set_field(ps.AcroFields, "Title Company", Settings.Parties.EscrowProfile.TitleCompany); set_field(ps.AcroFields, "Escrow Officer", Settings.Parties.EscrowProfile.Officer); set_field(ps.AcroFields, "Close of Escrow", Settings.Offer.CloseOfEscrow.ToShortDateString()); //String[] values = ps.AcroFields.GetAppearanceStates("Licensee Yes"); //String[] values2 = ps.AcroFields.GetAppearanceStates("Licensee No"); if (Settings.Parties.BuyerProfile.UseLicensee) { set_field(ps.AcroFields, "Licensee Yes", "Yes"); //set_field(ps.AcroFields, "Licensee No", "Off"); //set_field(ps.AcroFields, "Licensee relationship", DateTime.Today.ToShortDateString()); set_field(ps.AcroFields, "Licensee relationship", Settings.Parties.BuyerProfile.LicenseeRelationship); switch (Settings.Parties.BuyerProfile.RelationshipType) { case "Family Firm": set_field(ps.AcroFields, "Licensee Family Firm", "Yes"); break; case "Principal": set_field(ps.AcroFields, "Licensee Principal", "Yes"); break; } } else { set_field(ps.AcroFields, "Licensee No", "Yes"); //set_field(ps.AcroFields, "Licensee Yes", "Off"); } DateTime date = DateTime.Now.AddDays(7); set_field(ps.AcroFields, "Response Month", date.ToString("MMMM")); set_field(ps.AcroFields, "Response day", date.ToString("%d")); set_field(ps.AcroFields, "year", date.ToString("yyyy"));; string emd_ = Regex.Replace(Settings.Offer.Emd, @"[^\d]", ""); if (offer_amt_.Length > 0 && emd_.Length > 0) { set_field(ps.AcroFields, "Balance", (int.Parse(offer_amt_) - int.Parse(emd_)).ToString()); } // string AdditionalTerms = @"This form is available for use by the real estate industry. It is not intended to identify the user as a REALTOR®. //8 REALTOR® is a registered collective membership mark which may be used only by members of the NATIONAL //9 ASSOCIATION OF REALTORS® who subscribe to its Code."; string s = AdditionalTerms; s = fill_field_by_words(ps.AcroFields, "AdditionalTerms1", s); s = fill_field_by_words(ps.AcroFields, "AdditionalTerms2", s); s = fill_field_by_words(ps.AcroFields, "AdditionalTerms3", s); if (s.Length > 0) { s = AdditionalTerms; s = fill_field_by_chars(ps.AcroFields, "AdditionalTerms1", s); s = fill_field_by_chars(ps.AcroFields, "AdditionalTerms2", s); set_field(ps.AcroFields, "AdditionalTerms3", s); } set_field(ps.AcroFields, "Buyer Broker", Settings.Parties.BrokerProfile.Name); set_field(ps.AcroFields, "Agent Name", Settings.Parties.AgentProfile.Name); set_field(ps.AcroFields, "ListAgentFullName", ListAgentFullName); set_field(ps.AcroFields, "Company Name", Settings.Parties.BrokerProfile.Company); set_field(ps.AcroFields, "ListOfficeName", ListOfficeName); set_field(ps.AcroFields, "Agents License", Settings.Parties.AgentProfile.LicenseNo); set_field(ps.AcroFields, "Brokers License", Settings.Parties.BrokerProfile.LicenseNo); set_field(ps.AcroFields, "Office Address", Settings.Parties.BrokerProfile.Address); set_field(ps.AcroFields, "Office Phone", Settings.Parties.BrokerProfile.Phone); set_field(ps.AcroFields, "City State Zip", Settings.Parties.BrokerProfile.City + " " + Settings.Parties.BrokerProfile.State + " " + Settings.Parties.BrokerProfile.Zip); set_field(ps.AcroFields, "Agent Email", Settings.Parties.AgentProfile.Email); //set_field(ps.AcroFields, "Response Month", ); //set_field(ps.AcroFields, "Response day", ); //set_field(ps.AcroFields, "year", ); //set_field(ps.AcroFields, "Date_2", ); //set_field(ps.AcroFields, "Date_3", ); //set_field(ps.AcroFields, "Sellers Broker", ); set_field(ps.AcroFields, "Agents Name_2", Settings.Parties.AgentProfile.Name); set_field(ps.AcroFields, "Company Name_2", Settings.Parties.BrokerProfile.Company); set_field(ps.AcroFields, "Agents License Number_2", Settings.Parties.AgentProfile.LicenseNo); set_field(ps.AcroFields, "Brokers License Number_2", Settings.Parties.BrokerProfile.LicenseNo); set_field(ps.AcroFields, "Office Address_2", Settings.Parties.BrokerProfile.Address); set_field(ps.AcroFields, "Phone_2", Settings.Parties.BrokerProfile.Phone); set_field(ps.AcroFields, "City State Zip_2", Settings.Parties.BrokerProfile.Zip); set_field(ps.AcroFields, "Email_2", Settings.Parties.AgentProfile.Email); set_field(ps.AcroFields, "ListAgentEmail", ListAgentEmail); ps.FormFlattening = true; for (int i = 1; i <= pr.NumberOfPages; i++) { var pcb = ps.GetOverContent(i); add_image(pcb, System.Drawing.Image.FromFile(Settings.Parties.BuyerProfile.InitialFile), new System.Drawing.Point(497, 67)); if (Settings.Parties.BuyerProfile.UseCoBuyer) { add_image(pcb, System.Drawing.Image.FromFile(Settings.Parties.BuyerProfile.CoBuyerInitialFile), new System.Drawing.Point(536, 67)); } } { var pcb = ps.GetOverContent(3); add_image(pcb, System.Drawing.Image.FromFile(Settings.Parties.BuyerProfile.InitialFile), new System.Drawing.Point(140, 103)); if (Settings.Parties.BuyerProfile.UseCoBuyer) { add_image(pcb, System.Drawing.Image.FromFile(Settings.Parties.BuyerProfile.CoBuyerInitialFile), new System.Drawing.Point(280, 103)); } } { var pcb = ps.GetOverContent(9); add_image(pcb, System.Drawing.Image.FromFile(Settings.Parties.BuyerProfile.SignatureFile), new System.Drawing.Point(60, 190)); if (Settings.Parties.BuyerProfile.UseCoBuyer) { add_image(pcb, System.Drawing.Image.FromFile(Settings.Parties.BuyerProfile.CoBuyerSignatureFile), new System.Drawing.Point(60, 155)); } } ps.Close(); pr.Close(); } string output_addendum_pdf = null; if (Settings.Offer.ShortSaleAddendum) { output_addendum_pdf = file_dir + "\\" + Regex.Replace(address + " SS Addendum.pdf", @"\s+", " "); PdfReader.unethicalreading = true; PdfReader pr = new PdfReader(template_addendum_pdf); PdfStamper ps = new PdfStamper(pr, new FileStream(output_addendum_pdf, FileMode.Create, FileAccess.Write, FileShare.None)); string fs = ""; foreach (KeyValuePair <string, AcroFields.Item> kvp in ps.AcroFields.Fields) { fs += "\n{\"" + kvp.Key + "\", \"\"},"; } if (Settings.Parties.BuyerProfile.UseCoBuyer) { set_field(ps.AcroFields, "<Buyer Name> and <Co Buyer Name>", Settings.Parties.BuyerProfile.Name + " and " + Settings.Parties.BuyerProfile.CoBuyerName); } else { set_field(ps.AcroFields, "<Buyer Name> and <Co Buyer Name>", Settings.Parties.BuyerProfile.Name); } set_field(ps.AcroFields, "Todays Date", DateTime.Today.ToShortDateString()); set_field(ps.AcroFields, "<Address> <UnitNumber> <City/Town> NV <Zip Code>", address + " " + UnitNumber + ", " + City + " NV " + ZipCode); set_field(ps.AcroFields, "Agent Name", Settings.Parties.AgentProfile.Name); //set_field(ps.AcroFields, "Agent Phone", ); ps.FormFlattening = true; for (int i = 1; i <= pr.NumberOfPages; i++) { var pcb = ps.GetOverContent(i); add_image(pcb, System.Drawing.Image.FromFile(Settings.Parties.BuyerProfile.InitialFile), new System.Drawing.Point(120, 70)); if (Settings.Parties.BuyerProfile.UseCoBuyer) { add_image(pcb, System.Drawing.Image.FromFile(Settings.Parties.BuyerProfile.CoBuyerInitialFile), new System.Drawing.Point(157, 70)); } } { var pcb = ps.GetOverContent(1); add_image(pcb, System.Drawing.Image.FromFile(Settings.Parties.BuyerProfile.InitialFile), new System.Drawing.Point(140, 400)); if (Settings.Parties.BuyerProfile.UseCoBuyer) { add_image(pcb, System.Drawing.Image.FromFile(Settings.Parties.BuyerProfile.CoBuyerInitialFile), new System.Drawing.Point(197, 400)); } } { var pcb = ps.GetOverContent(3); add_image(pcb, System.Drawing.Image.FromFile(Settings.Parties.BuyerProfile.SignatureFile), new System.Drawing.Point(150, 547)); if (Settings.Parties.BuyerProfile.UseCoBuyer) { add_image(pcb, System.Drawing.Image.FromFile(Settings.Parties.BuyerProfile.CoBuyerSignatureFile), new System.Drawing.Point(150, 504)); } } ps.Close(); pr.Close(); } string output_addendum1_pdf = null; if (Settings.Offer.OtherAddendum1) { output_addendum1_pdf = file_dir + "\\" + Regex.Replace("duites " + address + ".pdf", @"\s+", " "); PdfReader.unethicalreading = true; PdfReader pr = new PdfReader(template_addendum1_pdf); PdfStamper ps = new PdfStamper(pr, new FileStream(output_addendum1_pdf, FileMode.Create, FileAccess.Write, FileShare.None)); string fs = ""; foreach (KeyValuePair <string, AcroFields.Item> kvp in ps.AcroFields.Fields) { fs += "\n{\"" + kvp.Key + "\", \"\"},"; } set_field(ps.AcroFields, "AgentName", Settings.Parties.AgentProfile.Name); set_field(ps.AcroFields, "LicenseNumber", Settings.Parties.AgentProfile.LicenseNo); set_field(ps.AcroFields, "Buyer Name", Settings.Parties.BuyerProfile.Name); set_field(ps.AcroFields, "Co-Buyer Name", Settings.Parties.BuyerProfile.CoBuyerName); set_field(ps.AcroFields, "BrokerName", Settings.Parties.BrokerProfile.Name); set_field(ps.AcroFields, "Company", Settings.Parties.BrokerProfile.Company); set_field(ps.AcroFields, "Date_3", DateTime.Now.ToShortDateString()); set_field(ps.AcroFields, "Time_3", DateTime.Now.ToShortTimeString()); set_field(ps.AcroFields, "Date_4", DateTime.Now.ToShortDateString()); set_field(ps.AcroFields, "Time_4", DateTime.Now.ToShortTimeString()); ps.FormFlattening = true; { var pcb = ps.GetOverContent(1); add_image(pcb, System.Drawing.Image.FromFile(Settings.Parties.BuyerProfile.InitialFile), new System.Drawing.Point(70, 190)); if (Settings.Parties.BuyerProfile.UseCoBuyer) { add_image(pcb, System.Drawing.Image.FromFile(Settings.Parties.BuyerProfile.CoBuyerInitialFile), new System.Drawing.Point(140, 190)); } } { var pcb = ps.GetOverContent(1); add_image(pcb, System.Drawing.Image.FromFile(Settings.Parties.BuyerProfile.SignatureFile), new System.Drawing.Point(110, 85)); if (Settings.Parties.BuyerProfile.UseCoBuyer) { add_image(pcb, System.Drawing.Image.FromFile(Settings.Parties.BuyerProfile.CoBuyerSignatureFile), new System.Drawing.Point(110, 85)); } } ps.Close(); pr.Close(); } bc.Add(new EmailItem(output_pdf, output_addendum_pdf, output_addendum1_pdf)); }