.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Creating pdf through asp.net

Posted By:Gowthammanju       Posted Date: June 28, 2011    Points: 200    Category: ASP.NET    URL: http://www.dotnetspark.com  

This code is basic to create pdf documents through dotnet


for creating pdf in asp.net first you need to create documents such as

1)Download itext sharp dll file which you found below

2)use the following coding for generating pdf documents such as

using iTextSharp.text;
using System.IO;
using iTextSharp.text.pdf;

 protected void Page_Load(object sender, EventArgs e)
        //Creates a Document object specifying the document's dimensions and left, right, top, and bottom margins, respectively
        var document = new Document(PageSize.A4, 50, 50, 25, 25);

        //Create a new PDFWriter object, specifying the output stream i.e. Stream where the Document object's output should be serialized when it is closed
        //FileStream, which will cause the PDF document's contents to be serialized to a file on disk named HelloPdf.pdf. 

        var output = new FileStream(Server.MapPath("HelloPdf.pdf"), FileMode.Create);
        var writer = PdfWriter.GetInstance(document, output);

        //open the pdf document for writing.

        //Add elements to the document.
        //add a new Paragraph object to the document with the text, "Hello, World!" 
        var helloPara = new Paragraph("Hello ,This is my First PDF Demo");
        //Add this paragraph object to the document.

        //Close the document. This saves the document contents to the output stream.

thanks and regards


 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend