This article shows how to convert text into PDF format and a database table take form and ContextMenuStrip in that Save to PDF and Save to DB and
also take RichtxtBox and write coding click event.
private void saveToPDFToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog s = new SaveFileDialog();
s.InitialDirectory = "C:";
s.Filter = "Pdf file(*.pdf)|*.pdf";
if (s.ShowDialog() == DialogResult.OK)
{
Document Doc = new Document();
PdfWriter.GetInstance(Doc, new FileStream(s.FileName, FileMode.Create));
Doc.Open();
Doc.Add(new Paragraph(richTextBox1.Text));
Doc.Close();
}
}
private void saveToDBToolStripMenuItem_Click(object sender, EventArgs e)
{
{
SqlConnection cn = new SqlConnection("Data Source=.;Initial Catalog=master;User ID=sa;word=coign");
string s1 = "Insert into Dat values('" + richTextBox1.Text + "')";
SqlCommand cmd = new SqlCommand(s1, cn);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
MessageBox.Show("save in DB");
}
}

Lie yingPosted Sep 27, 2011, 9:20 PM
which .dll file and namespace will be used ,can you speak clear ?
Olamide AfolabiPosted Mar 12, 2011, 7:40 PM
Can i use this code to convert a jpeg file to pdf? If yes what will i modify?
Ankit NandekarPosted Feb 24, 2011, 3:00 AM
thnx dinkar it is very useful code and i have tried its working. thnx
SapnaPosted Feb 16, 2011, 10:55 PM
Very simple and nice article!
Blocked AccountPosted Feb 16, 2011, 10:52 PM
Hi Dinkar, one question, how to write formatted text in PDF.
ramone castonPosted Feb 16, 2011, 9:37 PM
Does this code work in WPF.. if not can you upload the src I am getting errors in the Document Doc = new Document(); line. thanks
AjayPosted Feb 16, 2011, 3:27 AM
It's very nice article
Dinesh BeniwaleditedPosted Feb 16, 2011, 3:11 AMEdited Feb 16, 2011, 3:11 AM
Welcome on the C# Corner Community.