private void BtnConvert_Click(object sender, EventArgs e) { List<string> files = new List<string>(); foreach (object o in FileList.Items) { files.Add(o as string); } if (files.Count == 0) return; Cursor = Cursors.WaitCursor; try { MSUtils util = new MSUtils(); if (RdoMultiToSingle.Checked) { foreach (string fn in files) { util.ConvertToSinglePageTiffs(fn, Path.GetFileNameWithoutExtension(fn)); } } else { util.ConvertToMultiPageTiff(files, OutputFileNameTextBox.Text); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Cursor = Cursors.Default; MessageBox.Show("The selected files has been successfully processed.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void ProcessCommandLine(string[] args) { MSUtils util = new MSUtils(); string invalidSwitchMessage = string.Concat("*** ERROR ***: Invalid switch {0}!", Environment.NewLine); switch (args.Length) { case 0: Console.WriteLine(CopyrightsStr()); Console.WriteLine(UsageStr()); break; case 1: if (args[0].ToUpper().Trim() != "-H") { Console.WriteLine(string.Format(invalidSwitchMessage, args[0])); } Console.WriteLine(UsageStr()); break; default: string option = args[0].ToUpper().Trim(); if (option == "-S") { string destFolder = Environment.CurrentDirectory; if (args.Length > 2) { destFolder = args[2]; } util.ConvertToSinglePageTiffs(args[1].Trim(), destFolder); } else if (option == "-O") { if (args.Length < 4 || args[2].ToUpper().Trim() != "-M") { Console.WriteLine(string.Format(invalidSwitchMessage, "options")); } else { string destFile = args[1].Trim(); List<string> fileList = new List<string>(); for (int i = 3; i < args.Length; i++) { fileList.Add(args[i]); } util.ConvertToMultiPageTiff(fileList, destFile); } } else if (option == "-C") { if (args.Length != 2) { Console.WriteLine(string.Format(invalidSwitchMessage, "options")); } else { if (!File.Exists(args[1])) { Console.WriteLine(String.Format("*** ERROR ***: Configuration File {0} does not exist.", args[1])); } else { Config cfg = new Config(); string err = string.Empty; ConfigurationValues values = cfg.GetConfigurations(args[1],ref err); if (err != string.Empty) Console.WriteLine(err); string[] fns = values.InputFiles.Split(';'); switch (values.Action) { case Config.ACTION_SPLIT: foreach (string fn in fns) { util.ConvertToSinglePageTiffs(Path.Combine(values.SrcDir,fn), Path.Combine(values.DestDir,Path.GetFileNameWithoutExtension(fn))); } break; case Config.ACTION_MERGE: fns = values.InputFiles.Split(';'); List<string> list = new List<string>(); foreach (string fn in fns) { Console.WriteLine(values.SrcDir); list.Add(Path.Combine(values.SrcDir, fn)); } util.ConvertToMultiPageTiff(list, Path.Combine(values.DestDir,values.OutputFile)); break; default: Console.WriteLine(String.Format("*** ERROR ***: Unrecognized configuration key {0}.", values.Action)); break; } } } } break; } }
private void buttonSend_Click(object sender, EventArgs e) { if (_checkedDocument) { } else { MessageBox.Show("No Documents Selected", "No Documents Selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); KillWordForWindows(); Application.Exit(); return; } util = new MSUtils(); if (ckdocument1.Checked == true) { File.Copy(_document1Path, Application.StartupPath + "\\temp1\\document1.doc",true ); Stream _readFile = new FileStream(Application.StartupPath + "\\temp1\\document1.doc", FileMode.Open, FileAccess.Read, FileShare.Read); WordDocument _wordDocument = new WordDocument(_readFile); DocToPDFConverter _converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument _pdfDocument = _converter.ConvertToPDF(_wordDocument); _pdfDocument.Save(Application.StartupPath + "\\temp1\\document1.pdf"); PDFFile _file = PDFFile.Open(Application.StartupPath + "\\temp1\\document1.pdf"); _file.SerialNumber = "PDFVW-Y11DV-6VYTH-TWHXK-6DRLB-7MNQB"; for (int i = 0; i < _file.PageCount; i++) { // Convert each page to bitmap and save it. Bitmap pageImage = _file.GetPageImage(i, 96); pageImage.Save(Application.StartupPath + "\\temp2\\document1" + i.ToString() + ".tif", ImageFormat.Tiff); _listOfTifs.Add(Application.StartupPath + "\\temp2\\document1" + i.ToString() + ".tif"); } _file.Dispose(); _readFile.Close(); _readFile.Dispose(); } if (ckdocument2.Checked == true) { File.Copy(_document2Path, Application.StartupPath + "\\temp1\\document2.doc", true); Stream _readFile = new FileStream(Application.StartupPath + "\\temp1\\document2.doc", FileMode.Open, FileAccess.Read, FileShare.Read); WordDocument _wordDocument = new WordDocument(_readFile); DocToPDFConverter _converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument _pdfDocument = _converter.ConvertToPDF(_wordDocument); _pdfDocument.Save(Application.StartupPath + "\\temp1\\document2.pdf"); PDFFile _file = PDFFile.Open(Application.StartupPath + "\\temp1\\document2.pdf"); _file.SerialNumber = "PDFVW-Y11DV-6VYTH-TWHXK-6DRLB-7MNQB"; for (int i = 0; i < _file.PageCount; i++) { // Convert each page to bitmap and save it. Bitmap pageImage = _file.GetPageImage(i, 96); pageImage.Save(Application.StartupPath + "\\temp2\\document2" + i.ToString() + ".tif", ImageFormat.Tiff); _listOfTifs.Add(Application.StartupPath + "\\temp2\\document2" + i.ToString() + ".tif"); } _file.Dispose(); _readFile.Close(); _readFile.Dispose(); } if (ckdocument3.Checked == true) { File.Copy(_document3Path, Application.StartupPath + "\\temp1\\document3.doc", true); Stream _readFile = new FileStream(Application.StartupPath + "\\temp1\\document3.doc", FileMode.Open, FileAccess.Read, FileShare.Read); WordDocument _wordDocument = new WordDocument(_readFile); DocToPDFConverter _converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument _pdfDocument = _converter.ConvertToPDF(_wordDocument); _pdfDocument.Save(Application.StartupPath + "\\temp1\\document3.pdf"); PDFFile _file = PDFFile.Open(Application.StartupPath + "\\temp1\\document3.pdf"); _file.SerialNumber = "PDFVW-Y11DV-6VYTH-TWHXK-6DRLB-7MNQB"; for (int i = 0; i < _file.PageCount; i++) { // Convert each page to bitmap and save it. Bitmap pageImage = _file.GetPageImage(i, 96); pageImage.Save(Application.StartupPath + "\\temp2\\document3" + i.ToString() + ".tif", ImageFormat.Tiff); _listOfTifs.Add(Application.StartupPath + "\\temp2\\document3" + i.ToString() + ".tif"); } _file.Dispose(); _readFile.Close(); _readFile.Dispose(); } if (ckdocument4.Checked == true) { File.Copy(_document4Path, Application.StartupPath + "\\temp1\\document4.doc", true); Stream _readFile = new FileStream(Application.StartupPath + "\\temp1\\document4.doc", FileMode.Open, FileAccess.Read, FileShare.Read); WordDocument _wordDocument = new WordDocument(_readFile); DocToPDFConverter _converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument _pdfDocument = _converter.ConvertToPDF(_wordDocument); _pdfDocument.Save(Application.StartupPath + "\\temp1\\document4.pdf"); PDFFile _file = PDFFile.Open(Application.StartupPath + "\\temp1\\document4.pdf"); _file.SerialNumber = "PDFVW-Y11DV-6VYTH-TWHXK-6DRLB-7MNQB"; for (int i = 0; i < _file.PageCount; i++) { // Convert each page to bitmap and save it. Bitmap pageImage = _file.GetPageImage(i, 96); pageImage.Save(Application.StartupPath + "\\temp2\\document4" + i.ToString() + ".tif", ImageFormat.Tiff); _listOfTifs.Add(Application.StartupPath + "\\temp2\\document4" + i.ToString() + ".tif"); } _file.Dispose(); _readFile.Close(); _readFile.Dispose(); } if (ckdocument5.Checked == true) { File.Copy(_document5Path, Application.StartupPath + "\\temp1\\document5.doc", true); Stream _readFile = new FileStream(Application.StartupPath + "\\temp1\\document5.doc", FileMode.Open, FileAccess.Read, FileShare.Read); WordDocument _wordDocument = new WordDocument(_readFile); DocToPDFConverter _converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument _pdfDocument = _converter.ConvertToPDF(_wordDocument); _pdfDocument.Save(Application.StartupPath + "\\temp1\\document5.pdf"); PDFFile _file = PDFFile.Open(Application.StartupPath + "\\temp1\\document5.pdf"); _file.SerialNumber = "PDFVW-Y11DV-6VYTH-TWHXK-6DRLB-7MNQB"; for (int i = 0; i < _file.PageCount; i++) { // Convert each page to bitmap and save it. Bitmap pageImage = _file.GetPageImage(i, 96); pageImage.Save(Application.StartupPath + "\\temp2\\document5" + i.ToString() + ".tif", ImageFormat.Tiff); _listOfTifs.Add(Application.StartupPath + "\\temp2\\document5" + i.ToString() + ".tif"); } _file.Dispose(); _readFile.Close(); _readFile.Dispose(); } if (ckdocument6.Checked == true) { File.Copy(_document6Path, Application.StartupPath + "\\temp1\\document6.doc", true); Stream _readFile = new FileStream(Application.StartupPath + "\\temp1\\document6.doc", FileMode.Open, FileAccess.Read, FileShare.Read); WordDocument _wordDocument = new WordDocument(_readFile); DocToPDFConverter _converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument _pdfDocument = _converter.ConvertToPDF(_wordDocument); _pdfDocument.Save(Application.StartupPath + "\\temp1\\document6.pdf"); PDFFile _file = PDFFile.Open(Application.StartupPath + "\\temp1\\document6.pdf"); _file.SerialNumber = "PDFVW-Y11DV-6VYTH-TWHXK-6DRLB-7MNQB"; for (int i = 0; i < _file.PageCount; i++) { // Convert each page to bitmap and save it. Bitmap pageImage = _file.GetPageImage(i, 96); pageImage.Save(Application.StartupPath + "\\temp2\\document6" + i.ToString() + ".tif", ImageFormat.Tiff); _listOfTifs.Add(Application.StartupPath + "\\temp2\\document6" + i.ToString() + ".tif"); } _file.Dispose(); _readFile.Close(); _readFile.Dispose(); } if (ckdocument7.Checked == true) { File.Copy(_document7Path, Application.StartupPath + "\\temp1\\document7.doc", true); Stream _readFile = new FileStream(Application.StartupPath + "\\temp1\\document7.doc", FileMode.Open, FileAccess.Read, FileShare.Read); WordDocument _wordDocument = new WordDocument(_readFile); DocToPDFConverter _converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument _pdfDocument = _converter.ConvertToPDF(_wordDocument); _pdfDocument.Save(Application.StartupPath + "\\temp1\\document7.pdf"); PDFFile _file = PDFFile.Open(Application.StartupPath + "\\temp1\\document7.pdf"); _file.SerialNumber = "PDFVW-Y11DV-6VYTH-TWHXK-6DRLB-7MNQB"; for (int i = 0; i < _file.PageCount; i++) { // Convert each page to bitmap and save it. Bitmap pageImage = _file.GetPageImage(i, 96); pageImage.Save(Application.StartupPath + "\\temp2\\document7" + i.ToString() + ".tif", ImageFormat.Tiff); _listOfTifs.Add(Application.StartupPath + "\\temp2\\document7" + i.ToString() + ".tif"); } _file.Dispose(); _readFile.Close(); _readFile.Dispose(); } if (ckdocument8.Checked == true) { File.Copy(_document8Path, Application.StartupPath + "\\temp1\\document8.doc", true); Stream _readFile = new FileStream(Application.StartupPath + "\\temp1\\document8.doc", FileMode.Open, FileAccess.Read, FileShare.Read); WordDocument _wordDocument = new WordDocument(_readFile); DocToPDFConverter _converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument _pdfDocument = _converter.ConvertToPDF(_wordDocument); _pdfDocument.Save(Application.StartupPath + "\\temp1\\document8.pdf"); PDFFile _file = PDFFile.Open(Application.StartupPath + "\\temp1\\document8.pdf"); _file.SerialNumber = "PDFVW-Y11DV-6VYTH-TWHXK-6DRLB-7MNQB"; for (int i = 0; i < _file.PageCount; i++) { // Convert each page to bitmap and save it. Bitmap pageImage = _file.GetPageImage(i, 96); pageImage.Save(Application.StartupPath + "\\temp2\\document8" + i.ToString() + ".tif", ImageFormat.Tiff); _listOfTifs.Add(Application.StartupPath + "\\temp2\\document8" + i.ToString() + ".tif"); } _file.Dispose(); _readFile.Close(); _readFile.Dispose(); } if (ckdocument9.Checked == true) { File.Copy(_document9Path, Application.StartupPath + "\\temp1\\document9.doc", true); Stream _readFile = new FileStream(Application.StartupPath + "\\temp1\\document9.doc", FileMode.Open, FileAccess.Read, FileShare.Read); WordDocument _wordDocument = new WordDocument(_readFile); DocToPDFConverter _converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument _pdfDocument = _converter.ConvertToPDF(_wordDocument); _pdfDocument.Save(Application.StartupPath + "\\temp1\\document9.pdf"); PDFFile _file = PDFFile.Open(Application.StartupPath + "\\temp1\\document9.pdf"); _file.SerialNumber = "PDFVW-Y11DV-6VYTH-TWHXK-6DRLB-7MNQB"; for (int i = 0; i < _file.PageCount; i++) { // Convert each page to bitmap and save it. Bitmap pageImage = _file.GetPageImage(i, 96); pageImage.Save(Application.StartupPath + "\\temp2\\document9" + i.ToString() + ".tif", ImageFormat.Tiff); _listOfTifs.Add(Application.StartupPath + "\\temp2\\document9" + i.ToString() + ".tif"); } _file.Dispose(); _readFile.Close(); _readFile.Dispose(); } if (ckdocument10.Checked == true) { File.Copy(_document10Path, Application.StartupPath + "\\temp1\\document10.doc", true); Stream _readFile = new FileStream(Application.StartupPath + "\\temp1\\document10.doc", FileMode.Open, FileAccess.Read, FileShare.Read); WordDocument _wordDocument = new WordDocument(_readFile); DocToPDFConverter _converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument _pdfDocument = _converter.ConvertToPDF(_wordDocument); _pdfDocument.Save(Application.StartupPath + "\\temp1\\document10.pdf"); PDFFile _file = PDFFile.Open(Application.StartupPath + "\\temp1\\document10.pdf"); _file.SerialNumber = "PDFVW-Y11DV-6VYTH-TWHXK-6DRLB-7MNQB"; for (int i = 0; i < _file.PageCount; i++) { // Convert each page to bitmap and save it. Bitmap pageImage = _file.GetPageImage(i, 96); pageImage.Save(Application.StartupPath + "\\temp2\\document10" + i.ToString() + ".tif", ImageFormat.Tiff); _listOfTifs.Add(Application.StartupPath + "\\temp2\\document10" + i.ToString() + ".tif"); } _file.Dispose(); _readFile.Close(); _readFile.Dispose(); } //util.ConvertToMultiPageTiff(_listOfTifs,_ftpfolder + "\\newtif.tif"); util.ConvertToMultiPageTiff(_listOfTifs, Application.StartupPath + "\\temp2\\newtif.tif"); try { File.Copy(Application.StartupPath + "\\temp2\\newtif.tif", "\\\\hmdn-notes.ct-ortho.com\\YHP-Notes\\" + _fileName + ".tif", true); UpdateAppointmentTable(_chargeSlipNumber); } catch (Exception er) { MessageBox.Show(er.Message, "Problem Copying File", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } try { KillWordForWindows(); } catch { } MessageBox.Show("Files Moved", "Done", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Application.Exit(); }