static List<string> GetSortedImagesFromDirectory(string directory) { string[] filenameArray = Directory.GetFiles(directory, "*.tif", SearchOption.TopDirectoryOnly); List<string> filenameList = new List<string>(filenameArray); filenameList.Sort(StringComparer.InvariantCultureIgnoreCase); return filenameList; }
/// <summary> /// Slices the WMF image per pool. /// </summary> /// <returns>Returns an array of string with the path of sliced images.</returns> public string[] Slice() { if (string.IsNullOrEmpty(this.wmfPath)) { throw new InvalidOperationException(GlobalStringResource.IMAGE_PATH_NOT_SUPPLIED); } List<int> whites = new List<int>(); int x = 0; int width = 0; int height = 0; using (Bitmap baseImage = (Bitmap)Bitmap.FromFile(this.wmfPath)) { height = baseImage.Height; width = baseImage.Width; for (int i = 0; i < baseImage.Height; i++) { System.Drawing.Color c = baseImage.GetPixel(x, i); if (c.A == 255 && c.B == 255 && c.R == 255 && c.G == 255) { if (i == 0) { continue; } whites.Add(i); } } } whites.Sort(); List<System.Drawing.Rectangle> rectangles = CreateCoordinates(whites, width, height); return CropAndSave(rectangles); }
/** * Overriding standard PdfObject.ToPdf because we need sorted PdfDictionaries. */ private static void ToPdf(PdfObject @object, PdfWriter writer, ByteBuffer os) { if (@object is PdfDictionary) { os.Append('<'); os.Append('<'); List<PdfName> keys = new List<PdfName>(((PdfDictionary) @object).Keys); keys.Sort(); foreach (PdfName key in keys) { ToPdf(key, writer, os); PdfObject value = ((PdfDictionary) @object).Get(key); int type = value.Type; if (type != PdfObject.ARRAY && type != PdfObject.DICTIONARY && type != PdfObject.NAME && type != PdfObject.STRING) { os.Append(' '); } ToPdf(value, writer, os); } os.Append('>'); os.Append('>'); } else { @object.ToPdf(writer, os); } }
private void InitializeComboBox() { LiteCConfig cfg = new LiteCConfig(/*xmlDynamicDirectory +*/ "Instruments.xml"); InstrumentComboBox.Items.Clear(); //Using temp List<> for easy sorting List<string> temp = new List<string>(); foreach (LiteCParameter x in cfg.Read()) { temp.Add(x.Value); } temp.Sort(); foreach (string x in temp) { InstrumentComboBox.Items.Add(x); } }
private void loadFilesFromFolderToolStripMenuItem_Click(object sender, EventArgs e) { this.statusListView.BeginUpdate(); this.statusListView.Items.Clear(); if (!System.IO.Directory.Exists(this.outputFolderLabel.Text)) { MessageBox.Show("Unable to find directory", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string[] inputFilenames; inputFilenames = Directory.GetFiles(this.outputFolderLabel.Text, "*.tif", SearchOption.TopDirectoryOnly); if (inputFilenames.Length == 0) { inputFilenames = Directory.GetFiles(this.outputFolderLabel.Text, "*.png", SearchOption.TopDirectoryOnly); } List<string> fileNamesSortList = new List<string>(inputFilenames); fileNamesSortList.Sort(StringComparer.CurrentCultureIgnoreCase); foreach (string file in fileNamesSortList) { ListViewItem item = new ListViewItem(file); this.statusListView.Items.Add(item); } this.statusListView.EndUpdate(); }
void GeneratePDF(object argumentsObject) { try { GeneratePDFArguments arguments = argumentsObject as GeneratePDFArguments; FileStream outputStream = new FileStream(arguments.OutputFilename, FileMode.Create); List<string> fileNamesSortList = new List<string>(arguments.InputFilenames); fileNamesSortList.Sort(StringComparer.CurrentCultureIgnoreCase); arguments.InputFilenames = fileNamesSortList.ToArray(); int totalNmberOfFiles = arguments.InputFilenames.Length; int numberOfFilesProcessed = 0; Document document = new Document(); PdfWriter writer = PdfWriter.GetInstance(document, outputStream); writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_5); writer.CompressionLevel = PdfStream.BEST_COMPRESSION; document.Open(); PdfContentByte content = writer.DirectContent; foreach (string file in arguments.InputFilenames) { string dliName = String.Empty; try { FileInfo info = new FileInfo(file); string name = info.Name.Split(new char[] { '.' })[0]; string formatString = string.Empty; if (System.IO.File.Exists(outputFolderLabel.Text + @"\formatString.txt")) { formatString = System.IO.File.ReadAllText(outputFolderLabel.Text + @"\formatString.txt"); } dliName = string.Format(formatString, name); } catch { } try { iTextSharp.text.Image image; if (arguments.useOriginalImages) { image = iTextSharp.text.Image.GetInstance(file); } else { image = iTextSharp.text.Image.GetInstance(ConvertImage(file, arguments.imageScaleFactor, arguments.imageQuality)); } // scale image to fit either the 8.5 or 11 inch margins // default dpi is 72 float scaleFactor = 1f; if (image.Height > 11*72f) { scaleFactor = 11f / (image.Height/72f); } if (image.Width > 8.5*72f) { float widthScaleFactor = 8.5f / (image.Width/72f); if (widthScaleFactor > scaleFactor) { scaleFactor = widthScaleFactor; } } if (scaleFactor != 1f) { image.ScalePercent(scaleFactor * (float)100.0); } document.SetPageSize(new iTextSharp.text.Rectangle(image.Width*scaleFactor, image.Height*scaleFactor)); document.NewPage(); image.SetAbsolutePosition(0, 0); content.AddImage(image); if (this.AddWatermarktoPDF && !string.IsNullOrEmpty(dliName)) { BaseFont baseFont = FontFactory.GetFont(FontFactory.COURIER).GetCalculatedBaseFont(false); content.BeginText(); content.SetFontAndSize(baseFont, 35); content.ShowTextAligned(PdfContentByte.ALIGN_CENTER, dliName, image.Width / 2, 35, 0); content.EndText(); } int progress = this.CalculatePercentage(++numberOfFilesProcessed, totalNmberOfFiles); this.progressBarBook.Invoke(new SetInt(SetBookProgress), progress); this.statusListView.Invoke(new AddStatusItemDelegate(AddStatusItem), new object[] { file, "Added" }); } catch (ThreadAbortException) { } catch (Exception ex) { this.statusListView.Invoke(new AddStatusItemDelegate(AddStatusItem), new object[] { file, ex.Message }); } } document.Close(); if (OpenPDFAfterCreation) { OpenFile(arguments.OutputFilename); } if (deleteImagesAfterPDFCreationToolStripMenuItem.Checked) { DeleteTemporaryFiles(arguments); } } catch (ThreadAbortException) { return; } catch (Exception e) { this.Invoke(new ShowException(ShowError), e); } finally { this.downloadButton.Invoke(new SetButtonStatusDelegate(SetButtonStatus), new object[] { this.downloadButton, true }); this.allWorkerThreads.Clear(); } }
public ActionResult getAllDepManagers() { var m = from e in db.EmployeeRoles where e.Role.RoleName == "Department Manager" select e.Employee; List<Employee> list = new List<Employee>(); list = m.ToList(); list.Sort((x, y) => string.Compare(x.EmployeeName, y.EmployeeName)); return Json(m.ToList(), JsonRequestBehavior.AllowGet); }
public String demographicfield(int fieldID,int pollID,String [] items) { var result = ""; var poll = pollRepository.GetPollByID(pollID); List<string> values = new List<string>(); IList<ParticipantFieldValue> valued = participantRepository.GetParticipantFieldByID(fieldID).fieldValues.Where(valu => (!valu.value.Equals(""))).ToList(); if (poll.isGroup) valued = valued.Where(v => v.groupd != null).ToList(); else valued = valued.Where(v => v.participant != null).ToList(); values = (from v in valued select v.value).Distinct().ToList(); bool num = true; int number; if (values.Any(v => (!int.TryParse(v, out number)))) num = false; if (num == false) { values.Sort((x, y) => string.Compare(x, y)); foreach (String value in values) { if (items != null && items.Contains(value)) result = result + "<label><input type=\"checkbox\" name=\"items\" checked=\"yes\" value=\"" + value + "\"/>" + value + "</label><br />"; else result = result + "<label><input type=\"checkbox\" name=\"items\" value=\"" + value + "\"/>" + value + "</label><br />"; } } else { List<int> intvalues = values.ConvertAll<int>(delegate(String i) { return int.Parse(i); }); intvalues.Sort(); foreach (int value in intvalues) { if (items != null && items.Contains(value.ToString())) result = result + "<label><input type=\"checkbox\" name=\"items\" checked=\"yes\" value=\"" + value + "\"/>" + value + "</label><br />"; else result = result + "<label><input type=\"checkbox\" name=\"items\" value=\"" + value + "\"/>" + value + "</label><br />"; } } return result; }
protected void AnalyzeFile() { analyzeFailed = false; this.SetStatusText("Analyzing..."); SetPictureVisible(ref imgError, false); SetPictureVisible(ref imgOK, false); if (radRadioButton2.IsChecked && txtPageNumbers.Text.Trim().Length > 0) { try { String[] pages = txtPageNumbers.Text.Trim().Replace(" ", "").Split(','); foreach (string s in pages) { if (s.Contains('-')) { String[] pageRange = s.Split('-'); if (Convert.ToInt32(pageRange[0]) >= Convert.ToInt32(pageRange[1])) { MessageBox.Show("Cannot count pages backwards. Please correct your page range.", "Invalid Page Range", MessageBoxButtons.OK); analyzeFailed = true; SetButtonEnabled(ref btnSourcePDF, true); SetButtonEnabled(ref btnDestinationPDF, true); SetPictureVisible(ref imgError, true); SetGroupBoxEnabled(ref radGroupBox1, true); this.SetStatusText("Invalid Page Range"); this.SetProgressBar(ref progressStatus, false, 100); this.SetProgressPanelVisible(false); analyzeThread.Abort(); return; } else if (pageRange.Length > 2) { MessageBox.Show("Invalid page range entered. Please correct your entry and try again", "Invalid Page Range", MessageBoxButtons.OK); analyzeFailed = true; SetButtonEnabled(ref btnSourcePDF, true); SetButtonEnabled(ref btnDestinationPDF, true); SetGroupBoxEnabled(ref radGroupBox1, true); SetPictureVisible(ref imgError, true); this.SetStatusText("Invalid Page Range"); this.SetProgressBar(ref progressStatus, false, 100); this.SetProgressPanelVisible(false); analyzeThread.Abort(); return; } } } } catch (Exception ex) { analyzeFailed = true; SetButtonEnabled(ref btnSourcePDF, true); SetButtonEnabled(ref btnDestinationPDF, true); SetPictureVisible(ref imgError, true); SetGroupBoxEnabled(ref radGroupBox1, true); this.SetStatusText("Invalid Page Range"); this.SetProgressBar(ref progressStatus, false, 100); this.SetProgressPanelVisible(false); analyzeThread.Abort(); return; } } PdfReader pdfDocument = new PdfReader(lblSourcePDF.Text); PdfDictionary document = new PdfDictionary( ); SortPagesProvider sortPagesProvider = new SortPagesProvider(); int page_number = 0; if (radRadioButton1.IsChecked) { bookMarkReferences = new List<BookMarkReference>(); IList<Dictionary<string, object>> bookmarks = SimpleBookmark.GetBookmark(pdfDocument); if (bookmarks != null) { int i = 0; this.SetProgressBar(ref progressStatus, true, bookmarks.Count); foreach (Dictionary<string, object> bk in bookmarks) { foreach (KeyValuePair<string, object> kvr in bk) { if (kvr.Key == "Page" || kvr.Key == "page") page_number = Convert.ToInt32(Regex.Match(kvr.Value.ToString(), "[0-9]+").Value); } bookMarkReferences.Add(new BookMarkReference(bookmarks[i].Values.ToArray().GetValue(0).ToString(), page_number)); this.AddTreeNode(radTreeView1, bookmarks[i].Values.ToArray().GetValue(0).ToString() + " (Page: " + page_number.ToString() + ")"); this.SetStatusText(string.Format("Analyzing, {0}...", bookmarks[i].Values.ToArray().GetValue(0).ToString())); this.SetProgressBarValue(ref progressStatus, i); Thread.Sleep(500); i++; } bookMarkReferences.Sort(sortPagesProvider); SetButtonEnabled(ref btnSourcePDF, true); SetButtonEnabled(ref btnDestinationPDF, true); SetPictureVisible(ref imgOK, true); SetGroupBoxEnabled(ref radGroupBox1, true); this.SetStatusText("Done."); this.SetProgressBar(ref progressStatus, false, 100); this.SetProgressPanelVisible(false); } else { analyzeFailed = true; SetButtonEnabled(ref btnSourcePDF, true); SetButtonEnabled(ref btnDestinationPDF, true); SetPictureVisible(ref imgError, true); SetGroupBoxEnabled(ref radGroupBox1, true); this.SetStatusText("No Bookmarks Found!"); this.SetProgressBar(ref progressStatus, false, 100); this.SetProgressPanelVisible(false); } } else if (radRadioButton2.IsChecked) { String[] pages = txtPageNumbers.Text.Trim().Replace(" ", "").Split(','); Int32 pageCount = pdfDocument.NumberOfPages; if (pages.Length > 0) { this.SetProgressBar(ref progressStatus, true, pages.Length); try { for (int i = 0; i < pages.Length; i++) { this.SetStatusText(string.Format("Analyzing, {0}...", pages[i])); this.SetProgressBarValue(ref progressStatus, i+1); if (pages[i].Trim() != "") { if (pages[i].Contains("-")) { if (pages[i].Split('-')[1].Trim() != "") { Int32 lastnum = Convert.ToInt32(pages[i].Split('-')[1]); if (lastnum > pageCount) { analyzeFailed = true; this.AddTreeNode(radTreeView1, "Page(s): " + pages[i] + " - Invalid"); } else { this.AddTreeNode(radTreeView1, "Page(s): " + pages[i] + " - \u2713"); } } } else { if (Convert.ToInt32(pages[i]) > pageCount) { analyzeFailed = true; this.AddTreeNode(radTreeView1, "Page(s): " + pages[i] + " - Invalid"); } else { this.AddTreeNode(radTreeView1, "Page(s): " + pages[i] + " - \u2713"); } } } } this.SetStatusText("Done."); SetButtonEnabled(ref btnSourcePDF, true); SetButtonEnabled(ref btnDestinationPDF, true); SetPictureVisible(ref imgOK, true); SetGroupBoxEnabled(ref radGroupBox1, true); this.SetProgressBar(ref progressStatus, false, 100); this.SetProgressPanelVisible(false); } catch (Exception ex) { MessageBox.Show("There was a problem analyzing your document. Please check your entries and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.SetStatusText("Failed."); SetButtonEnabled(ref btnSourcePDF, true); SetButtonEnabled(ref btnDestinationPDF, true); SetPictureVisible(ref imgError, true); SetGroupBoxEnabled(ref radGroupBox1, true); this.SetProgressBar(ref progressStatus, false, 100); this.SetProgressPanelVisible(false); } } } else { analyzeFailed = true; this.SetStatusText("No pages documented."); SetButtonEnabled(ref btnSourcePDF, true); SetButtonEnabled(ref btnDestinationPDF, true); SetPictureVisible(ref imgError, true); SetGroupBoxEnabled(ref radGroupBox1, true); this.SetProgressBar(ref progressStatus, false, 100); this.SetProgressPanelVisible(false); } pdfDocument.Close(); pdfDocument.Dispose(); }
public void Generate(string fn) { //MessageBox.Show(fn); //List<UniqueWords> wordstoiterate = new List<UniqueWords>(wordstoprint); //sorting words of list in alphabetical order wordstoprint.Sort((x, y) => string.Compare(x.Term, y.Term)); List<string> lines = new List<string>(); lines.Add("<html>"); lines.Add("<head>"); lines.Add("<style>"); lines.Add(".divleft{width:50%;float:left;}"); lines.Add(".divright{width:50%;float:right;}"); lines.Add("</style>"); lines.Add("</head>"); lines.Add("<body>"); int n = wordstoprint.Count; // int incr = (n/2) - 1; int count = 0; while (count<n) { lines.Add("<hr />"); lines.Add("<div class=\"divleft\">"); int end = count + 25; for (; count <= end;count++ ) { try { lines.Add(wordstoprint[count].Term); } catch (ArgumentOutOfRangeException aore) { break; } int[] pagenos = wordstoprint[count].PagenoWithFrequency.Keys.ToArray(); List<int> pagenostosort = new List<int>(); foreach (var pno in pagenos) { pagenostosort.Add(pno); } //sorting page nos pagenostosort.Sort(); foreach (var i in pagenostosort) { lines.Add("(" + i.ToString() + ")" + " "); } lines.Add("<br />"); } lines.Add("</div>"); lines.Add("<div class=\"divright\">"); int end1 = count + 25; for (; count <= end1; count++) { try { lines.Add(wordstoprint[count].Term); } catch (ArgumentOutOfRangeException aore) { break; } int[] pagenos = wordstoprint[count].PagenoWithFrequency.Keys.ToArray(); List<int> pagenostosort = new List<int>(); foreach (var pno in pagenos) { pagenostosort.Add(pno); } //sorting page nos pagenostosort.Sort(); foreach (var i in pagenostosort) { lines.Add("(" + i.ToString() + ")" + " "); } lines.Add("<br />"); } lines.Add("</div>"); } lines.Add("</body>"); lines.Add("</html>"); // File.Create("F:\\myfile.html"); if (File.Exists(fn)) { { File.Delete(fn); } foreach (var line in lines) { File.AppendAllText(fn, line); } } else { foreach (var line in lines) { File.AppendAllText(fn, line); } } }