using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Windows.Forms;
using word= Microsoft.Office.Interop.Word;
using iTextSharp.text.pdf;
using iTextSharp.text;
using System.IO;
using System.Reflection;
namespace ConvertPDFandWord
{
public partial class ConverPDFandWord : Form
{
static string QueryString = @"Data Source=.;Initial Catalog=TestDataBase;Integrated Security=True";
SqlConnection con = new SqlConnection(QueryString);
SqlCommand cmd = new SqlCommand();
SaveFileDialog sfd = new SaveFileDialog();
public ConverPDFandWord()
{
InitializeComponent();
}
private void btnSaveDB_Click(object sender, EventArgs e)
{
string Insertquery = "Insert into savedatabase (data)values('"+rtb.Text+"')";
SqlCommand cmd = new SqlCommand(Insertquery,con);
try
{
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show("SaveDataBase"+ex.Message+ex.Stack Trace);
}
}
private void btnSavePDF_Click(object sender, EventArgs e)
{
sfd.Title = "Save As PDF";
sfd.Filter = "(*.pdf)|*.pdf";
sfd.InitialDirectory = @"C:\";
if (sfd.ShowDialog() == DialogResult.OK)
{
iTextSharp.text.Document doc = new iTextSharp.text.Document();
PdfWriter.GetInstance(doc,new FileStream(sfd.FileName,FileMode.Create));
doc.Open();
doc.Add(new iTextSharp.text.Paragraph(rtb.Text));
doc.Close();
}
}
private void btnSaveWord_Click(object sender, EventArgs e)
{
sfd.Title = "Save As MsWord";
sfd.Filter = "WordDocument|*.docx";
//sfd.DefaultExt = "docx";
sfd.InitialDirectory = @"C:\";
if (sfd.ShowDialog() == DialogResult.OK)
{
rtb.SaveFile(sfd.FileName, RichTextBoxStreamType.PlainText);
}
}
private void btnTextFile_Click(object sender, EventArgs e)|
{
sfd.Title = "Save As Textfile";
sfd.InitialDirectory = @"C:\";
sfd.Filter = "TextDocuments|*.txt";
//sfd.DefaultExt = "txt";
if (sfd.ShowDialog() == DialogResult.OK)
{
rtb.SaveFile(sfd.FileName, RichTextBoxStreamType.PlainText);
}
}
}
}