simple steps :
step 1 : First of all we have to download the iTextSharp.dll file
step 2 : After downloading the file add the reference of iTextSharp.dll to your project by right clicking on solution explorer.
step 3 : Now add the Namespace to your .cs
using iTextSharp.text;
using iTextSharp.text.pdf;
step 4 : Now one whatever click you wnat to generate the file you can write the below code. in this example i am generating the pdf file button click event.
//Create Document class object and set its size to letter and give space left,right.....
Document doc =new Document(iTextSharp.text.PageSize.LETTER,10,10,42,35);
PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("c:\\Mahen.pdf", FileMode.Create));
doc.Open(); // open Document to write
//Now Write Some Content to it.
Paragraph paragraph = new Paragraph("My name is mahen");
Phrase pharse = new Phrase("And the team member of our project is simmy and ayesha");
Chunk chunk=new Chunk(" I am the student of M S University");
doc.Add(paragraph);
doc.Add(pharse);
doc.Add(Chunk);
doc.Close(); // close the Document
And you are done
Here is the sample pdf file
And below is the full code used inside button click event in C# example

No comments:
Post a Comment