C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Visual Studio »

Create PDF document using C#


Posted Date: 29 Jul 2008    Resource Type: Code Snippets    Category: Visual Studio
Author: VidhyaMember Level: Gold    
Rating: 1 out of 5Points: 1



This resource shows how to create a PDF document using C#.

Step 1: First create an instance of document object

Document myDocument= new Document(PageSize.A4.Rotate());

Step 2: Now create a writer that listens to this doucment and writes the document to desired Stream.

PdfWriter.GetInstance(myDocument, new FileStream("Salman.pdf", FileMode.Create));

Step 3: Open the document now using

myDocument.Open();

Step 4: Now add some contents to the document

myDocument.add( new Paragraph ( "First Pdf File made by Salman using iText"));

Step 5: Remember to close the documnet

myDocument.close();




// Code

using System;
using System.IO;
using System.Diagnostics;

using iTextSharp.text;
using iTextSharp.text.pdf;

public class iTextDemo
{
public static void Main()
{
Console.WriteLine("iText Demo");

// step 1: creation of a document-object
Document myDocument = new Document(PageSize.A4.Rotate());

try
{

// step 2:
// Now create a writer that listens to this doucment and writes the document to desired Stream.

PdfWriter.GetInstance(myDocument, new FileStream("Salman.pdf", FileMode.Create));

// step 3: Open the document now using
myDocument.Open();

// step 4: Now add some contents to the document
myDocument.Add(new Paragraph("First Pdf File made by Salman using iText"));

}
catch(DocumentException de)
{
Console.Error.WriteLine(de.Message);
}
catch(IOException ioe)
{
Console.Error.WriteLine(ioe.Message);
}

// step 5: Remember to close the documnet

myDocument.Close();
}
}




Responses

Author: Gaurav Arora    09 Aug 2008Member Level: Diamond   Points : 2
Hi Divya,
This is a good one shot using I/O Text but it works only when you have PDF utility installed on your system.

What about if one hasn't installed the utility on his/her system.

I have gone through the same the Code is quite interesting and bug free but it has some miscrepancies or say dependencies.

Thanks & regards,
Gaurav Arora


Author: Gaurav Arora    09 Aug 2008Member Level: Diamond   Points : 2
Hi Divya,
This is a good one shot using I/O Text but it works only when you have PDF utility installed on your system.

What about if one hasn't installed the utility on his/her system.

I have gone through the same the Code is quite interesting and bug free but it has some miscrepancies or say dependencies.

Thanks & regards,
Gaurav Arora


Author: Himasagar Kutikuppala    12 Aug 2008Member Level: Silver   Points : 2
Hi Gaurav
Yes, iTextSharp DLL required to create the PDF file.
This is open source library only, so you can download from the following link and enjoy..
http://downloads.sourceforge.net/itextsharp/itextsharp-4.0.2-dll.zip?modtime=1173357588&big_mirror=0

For more details about iTextSharp & PDF file creation, Go through the following link
http://www.codeproject.com/KB/graphics/iTextSharpTutorial.aspx

Regards
Himasagar Kutikuppala


Author: Jaiswar Vipin Kumar R.    28 Aug 2008Member Level: Bronze   Points : 2
This application is really grate but as you said the it is open source. But there no provision to download the source code.
Because this open source (as you said) DLL may breaking security of the i.e. if I run application by using this DLL, so may be this DLL sending use information via mail internally to unwanted users.

May I am wring, Hoping I am wrong on this discussion, but if it is really true then where is source code?

Thanks & Regards
Jaiswar Vipin Kumar R.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
PDF Document c#.net  .  PDF Document .net  .  Creation of PDF Document in c#.net  .  Creation of PDF Document in 5 easy steps  .  Creation of PDF Document in .net  .  Creation of PDF Document .net  .  Creation of PDF Document  .  5 easy steps  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Adding a Combobox to ListBox in XAML
Previous Resource: How to use SQL Compact Edition Insert Statement
Return to Discussion Resource Index
Post New Resource
Category: Visual Studio


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use