You are on page 1of 11

C# TUTORIAL: CREATE PDF FILE

Create pdf file


In this page, you learn to create a PDF document from scratch by using
iTextSharp library in C#. The iText library is available in two versions: the
original Java version, and the C# port, iTextSharp. The iTexSharp is a useful
library that can be used with C# to create and manipulate PDF documents. To
start creating a PDF document in C# by using iTextSharp library, you need to
download the library from http://sourceforge.net/projects/itextsharp/files/.

Then create a new Console project in


Visual Studio 2010. You will create a
libs folder in this Console project
folder and extract the iTextSharp
library zip file to this libs folder. In the
Solution Explorer, right click the
References->Add Reference.... In the
Add Reference dialog box, select
browse. Navigate to the libs folder
that contains the iTextSharp libary. Select itextsharp.dll from the list box. Click
Ok to add the itextsharp library to the Console project.

At the header section of Program.cs file, you need to write the following code
to use iTextSharp and IO libraries.

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

To create a simple PHP document, write the C# code shown below in the Main
method.

//create a document object


var doc = new Document();
//get the current directory
string path = Environment.CurrentDirectory;
//get PdfWriter object
PdfWriter.GetInstance(doc, new FileStream(path + "/pdfdoc.pdf",
FileMode.Create));
//open the document for writing
doc.Open();
//write a paragraph to the document ⇒
doc.Add(new Paragraph("Hello World"));
//close the document
doc.Close();
//view the result pdf file
System.Diagnostics.Process.Start(path + "/pdfdoc.pdf");

By running the program, you will see a PDF document as shown below.

The C# code above creates a PDF file called pdfdoc.pdf in the current working
folder of the Console project. There are five steps in the PDF file creation:

-Create a PDF document object.

-Get PDFWriter object.

-Open the document.


-Write content to the document.

-Close the document.

You can download the complete source code of the example project from ⇒
here.

ASP.NET MVC UI C# tutorial: PDF Free flowchart C# tutorial: extract


Controls - 70+ Controls page setup software text from a PDF file
for Every Need

Ad telerik.com worldbestlearningcenter.com Ad Lucidchart worldbestlearningcenter.com

RBarcode for .NET C# tutorial: PDF C# tutorial: insert C# tutorial: Add


metadata pages to an existing annotations to an
PDF document existing PDF
Ad www.java4less.com worldbestlearningcenter.com worldbestlearningcenter.com worldbestlearningcenter.com

Comments

 hjk

jgjh
2016-08-30

 lorretadt ⇒
i find a free online WPF PDF viewer on rasteredge http://www.rast
eredge.com/how-to/vb-net-imaging/pdf-net-wpf-feature-view/, i
t can view the pdf document for free online.

2016-06-30

 lorretadt

i find a free online WPF PDF viewer on rasteredge http://www.rast


eredge.com/how-to/vb-net-imaging/pdf-net-wpf-feature-view/, i
t can view the pdf document for free online.

2016-06-30

 bnm

bnnnb

2016-05-24
 lorretadt

vb.net wpf display pdf file is what you are trying to do is impossible,
what you could try to do is show vb.net create pdf from wpf online

was that what you were trying?, if

so, try something like this:http://www.rasteredge.com/how-to/vb-


net-imaging/pdf-net-wpf-feature-view/

2016-05-14

 dsfdsf

dsfsdf

2016-04-04

 Sodama

It is very nice C# to PDF tutorial.

2015-01-12

 Omar
I would like to recommend the .NET Library i use for managing my
PDF files known as Aspose.PDF for .NET. You can create simple or
complex PDF file with this lib and it offers many other features. Che
ck it out: ⇒

http://www.aspose.com/.net/pdf-component.aspx

2014-04-29

Publish
C# Pdf Editing Tutorials

Create PDF file

PDF page setup ⇒


Draw graphics in PDF document

Add Chunk and Phrase to PDF document

Add a table to PDF

Customize the background color of rows

Customize border of cells

Display images in cells of a table of PDF

Get information of PDF document

Import pages from PDF document

Add content to an existing PDF document

Insert pages to an existing PDF document

Combine PDF files

Split PDF file

PDF Navigation

Link in PDF

Bookmark in PDF

Annotations in PDF

Add annotations to existing PDF

PDF file attachments

PDF print button

PDF Form Fields


PDF List and Combo Boxes

PDF fill in form

PDF painting patterns

Creating an image in iTextSharp ⇒


Mask and Clip an image

PDF Barcodes

PDF metadata

PDF Compression

Encrypt PDF file

Extract text from PDF file

Area-based text extraction and margins finding

Extract images from PDF file

List fonts used in a PDF file

Embed a video in a PDF file

C# related posts

C# Programming Tutorial

C# example programs

C# questions

C# exercises

C# FAQs
Ads by Google Ads by Google

Download PDF C# PDF

PDF Writer Software Open PDF


Popular Posts Related Post


C# exercises Java by Examples
C++ exercises Android Development by Examples
Java exercises Software Development Life Cycle
Android tips (I) Structured Analyis & Design
Android tips (II) Object-Oriented Analysis
C# tutorials Advantages of IS in Business

Other Useful Resources


Android Developers
Android Developers Blog
Android video tutorials
Stack Overflow

The JavaTM Tutorials


W3Schools Online Web Tutorials

Custom Search
Search
Like 8 5 1 people lik e th is. Be th e first of you r friends.

CodeV ideo

+ 9 9 9 You Tu be ⇒

This website intents to provide free and high quality tutorials, examples,
exercises and solutions, questions and answers of programming and scripting
languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP,
ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS
Excel, MS Access, and MS Word. However, we don't guarantee all things of
the web are accurate. If you find any error, please report it then we will take
actions to correct it as soon as possible.

Forum Downloads About Contact

© 2014 worldbestlearningcenter.com

You might also like