private void Button_GuardarComo_Click(object sender, EventArgs e) { string documentName = "Entrada Serial " + string.Format("{0:dd-MM-yy}", DateTime.Now); PDFGenerator docpdf; SaveFileDialog svd = new SaveFileDialog { Title = "Documentos - Guardar Como", Filter = "Archivo Documentos|*.txt;*.pdf;*.doc;*.docx", InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), FileName = documentName, AddExtension = true, }; try { if (svd.ShowDialog() == DialogResult.OK) { if (svd.FileName.EndsWith(".pdf")) { docpdf = new PDFGenerator(RichTextBox_EntradaSerial.Text, svd.FileName); docpdf.Font(RichTextBox_EntradaSerial.Font); docpdf.Landscape(false); docpdf.Print(); } else { StreamWriter saveText = new StreamWriter(svd.FileName, false, Encoding.GetEncoding(1252)); if (File.Exists(svd.FileName)) { saveText.Write(RichTextBox_EntradaSerial.Text); saveText.Flush(); saveText.Close(); } else { saveText.Write(RichTextBox_EntradaSerial.Text); saveText.Flush(); saveText.Close(); } } } } catch (Exception) { } }