public void chooseTiffDir() { FolderBrowserDialog fbd_mainFBD = new FolderBrowserDialog(); if (fbd_mainFBD.ShowDialog() == DialogResult.OK) { tiffDir = fbd_mainFBD.SelectedPath; tiffFiles = Directory.GetFiles(@tiffDir, "*.tif"); if (tiffFiles.Length == 0) { Rtb_output.AppendText("\nNo Tiff Files in" + tiffDir); DialogResult dr = MessageBox.Show("Would you like to select another directory?", "No Tiff Files Found!", MessageBoxButtons.YesNo); switch (dr) { case DialogResult.Yes: chooseTiffDir(); break; case DialogResult.No: return; } } else { Rtb_output.AppendText("\n" + tiffFiles.Length + " Tiff File(s) Found"); txt_tiffDir.Text = fbd_mainFBD.SelectedPath; for (int i = 0; i < tiffFiles.Length; i++) { lbx_tiffFiles.Items.Add(tiffFiles[i].Substring(txt_tiffDir.Text.Length + 1)); Rtb_output.AppendText("\n" + tiffFiles[i].Substring(txt_tiffDir.Text.Length + 1) + " found!"); } } } }
public void ChooseFolder() { FolderBrowserDialog Fbd_selectDirectory = new FolderBrowserDialog(); if (Fbd_selectDirectory.ShowDialog() == DialogResult.OK) { Txt_folderSelected.Text = Fbd_selectDirectory.SelectedPath; directory = Fbd_selectDirectory.SelectedPath; Files = Directory.GetFiles(Txt_folderSelected.Text, "*.mp3"); Rtb_output.AppendText("\n" + Files.Length + " MP3 File(s) found"); if (Files.Length == 0) { DialogResult dr = MessageBox.Show("You selected a folder with no MP3 Files in it, Would you like to pick another folder?", "No Files Found", MessageBoxButtons.YesNo, MessageBoxIcon.Error); switch (dr) { case DialogResult.Yes: ChooseFolder(); break; case DialogResult.No: return; } } else { for (int i = 0; i < Files.Length; i++) { Lbx_files.Items.Add(Files[i].Substring(Txt_folderSelected.TextLength + 1)); } selected = 0; Lbx_files.SetSelected(selected, true); } } }
void RemoveTags(string file) { try { TagLib.File MetaFile = TagLib.File.Create(Txt_folderSelected.Text + "\\" + file); MetaFile.RemoveTags(TagTypes.AllTags); Rtb_output.AppendText("\n" + file + " : Tags have been removed"); } catch (Exception ex) { MessageBox.Show(ex.Message, "An Error has Occured", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btn_convert_Click(object sender, EventArgs e) { for (int i = 0; i < tiffFiles.Length; i++) { try { string[] pdfFile = lbx_tiffFiles.Items[i].ToString().Split('.'); string exists = tiffDir + "/" + pdfFile[0] + ".pdf"; if (File.Exists(exists)) { Rtb_output.AppendText("\n" + lbx_tiffFiles.Items[i].ToString() + ".pdf already exists. Skipping!"); continue; } else { ConvertTiffToPdf(tiffDir + "/" + lbx_tiffFiles.Items[i].ToString(), lbx_tiffFiles.Items[i].ToString()); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void Rtb_output_TextChanged(object sender, EventArgs e) { Rtb_output.ScrollToCaret(); }
private void Frm_mainForm_Load(object sender, EventArgs e) { Rtb_output.AppendText("Launch: Successful"); }
private void Btn_clearOutput_Click(object sender, EventArgs e) { Rtb_output.Text = ""; Rtb_output.AppendText("Cleared Output..."); }
private void Btn_write_Click(object sender, EventArgs e) { if (Chk_song.Checked && Txt_song.Text == "") { MessageBox.Show("Song field enabled but left blank", "Song Field Blank", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (Chk_artist.Checked && Txt_artist.Text == "") { MessageBox.Show("Artist field enabled but left blank", "Artist Field Blank", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (Chk_album.Checked && Txt_album.Text == "") { MessageBox.Show("Album field enabled but left blank", "Album Field Blank", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (Chk_year.Checked && Txt_year.Text == "") { MessageBox.Show("Year field enabled but left blank", "Year Field Blank", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { TagLib.File MetaFile = TagLib.File.Create(Txt_folderSelected.Text + "\\" + Txt_selectedSong.Text); if (Chk_song.Checked) { MetaFile.Tag.Title = Txt_song.Text; } if (Chk_artist.Checked) { MetaFile.Tag.Performers = new string[1] { Txt_artist.Text } } ; if (Chk_album.Checked) { MetaFile.Tag.Album = Txt_album.Text; } if (Chk_year.Checked) { MetaFile.Tag.Year = Convert.ToUInt16(Txt_year.Text); } MetaFile.Save(); Rtb_output.AppendText("\n" + Txt_selectedSong.Text + " : Tags have been wrote"); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + Txt_folderSelected.Text + "\\" + Txt_selectedSong.Text, "An Error Occured", MessageBoxButtons.OK, MessageBoxIcon.Error); Console.WriteLine(ex); } if (Properties.Settings.Default.ContOnWrite) { if (selected < Lbx_files.Items.Count - 1) { selected++; Lbx_files.SetSelected(selected, true); } else { return; } } }
private string ConvertTiffToPdf(string tiffFileName, string fileName) { //iTextSharp.text.Rectangle pgSize = PageSize.LETTER; iTextSharp.text.Rectangle pgSize = PageSize.LEGAL; string pdfFile; string[] FileName = fileName.Split('.'); do { pdfFile = Path.GetDirectoryName(tiffFileName) + Path.DirectorySeparatorChar + FileName[0] + ".pdf"; } while (File.Exists(pdfFile)); if (File.Exists(pdfFile)) { File.Delete(pdfFile); } if (!File.Exists(tiffFileName)) { return(null); } Bitmap bmp = new Bitmap(tiffFileName); int totalPages = bmp.GetFrameCount(FrameDimension.Page); float margin = 0.0f; //float margin = 50.0f; Document document = new Document(pgSize, margin, margin, margin, margin); try { // creation of the different writers PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(pdfFile, FileMode.Create)); // Which of the multiple images in the TIFF file do we want to load // 0 refers to the first, 1 to the second and so on. document.Open(); PdfContentByte cb = writer.DirectContent; iTextSharp.text.Image img; for (int ii = 0; ii < totalPages; ii++) { bmp.SelectActiveFrame(FrameDimension.Page, ii); img = iTextSharp.text.Image.GetInstance(BitmapToBytes(bmp)); img.ScalePercent(72f / bmp.HorizontalResolution * 100); img.SetAbsolutePosition(0, 0); cb.AddImage(img); document.NewPage(); } document.Close(); document = null; bmp.Dispose(); bmp = null; Rtb_output.AppendText("\n" + FileName[0] + " Converted"); } catch (Exception ex) { this.Cursor = Cursors.Default; MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } return(pdfFile); }