Compatible with Windows 10, 8, 7, Vista, XP and 2000
I have an old project that is using iTextSharp library for PDF generation. ITextSharp DLL is added as reference to the project. ITextSharp was originally available under the LGPL licence. (with previous licence conditions). Or is there any place where I can download old version of iTextSharp that is still under LGPL so I'll be sure I'm. NET port of the iText library — please use iText7 - itext/itextsharp. List of changes can be found in the changelogs and the release in our download hub for Java. Please note: the XMLWorker dll is now included in the itextsharp-all zip.
Optional Offer for WinThruster by Solvusoft | EULA | Privacy Policy | Terms | Uninstall
Overview of Itextsharp.dll
What Is Itextsharp.dll?
Itextsharp.dll is a type of DLL file associated with Third-Party Software developed by Windows Software Developer for the Windows Operating System. The latest known version of Itextsharp.dll is 4.1.2.0, which was produced for Windows. This DLL file carries a popularity rating of 1 stars and a security rating of 'UNKNOWN'.
What Are DLL Files?
DLL ('dynamic link library') files such as itextsharp.dll are small programs, similar to EXE ('executable') files, which allow multiple software programs to share the same functionality (eg. printing).
For example, let's say you are running Windows and editing a document in Microsoft Word. The DLL file that controls printing does not need to load unless it's function is needed - eg. you decide to print your document. When you select 'Print', Microsoft Word calls the printer DLL file, and it is loaded into memory (RAM) at that time. If you want to print a document in another program, Adobe Acrobat for example, that same printer DLL file will be used as well.
Why Do I Have DLL Errors?
Because they are shared files, DLL files exist outside of the software application itself. Although this provides many benefits for software developers, this separation also provides an opportunity for problems to occur.
Quite simply, if Windows cannot properly load your itextsharp.dll file, you will encounter an error message. Please see 'Causes of itextsharp.dll Errors' below for more information.
When Do DLL Errors Occur?
DLL errors, such as those associated with itextsharp.dll, most often occur during computer startup, program startup, or while trying to use a specific function in your program (eg. printing).
Common Itextsharp.dll Error Messages
The most common itextsharp.dll errors that can appear on a Windows-based computer are:
- 'Itextsharp.dll not found.'
- 'The file itextsharp.dll is missing.'
- 'Itextsharp.dll Access Violation.'
- 'Cannot register itextsharp.dll.'
- 'Cannot find C:WindowsSystem32itextsharp.dll.'
- 'Cannot start Third-Party Software. A required component is missing: itextsharp.dll. Please install Third-Party Software again.'
- 'This application failed to start because itextsharp.dll was not found. Re-installing the application may fix this problem.'
These DLL error messages can appear during program installation, while a itextsharp.dll-related software program (eg. Third-Party Software) is running, during Windows startup or shutdown, or even during the installation of the Windows operating system. Keeping track of when and where your itextsharp.dll error occurs is a critical piece of information in troubleshooting the problem.
27 Nov 2013CPOL
Create/Read/Write Advance PDF Report using iTextSharp.DLL in Desktop, Mobile, Web Application
Contents
The following two contents are added in this updated version:
Introduction
Recently I was looking for an Advance Tool to create complex PDF Report in C#.Net and I found
iTextSharp
. The main problem is that lacks of Documentation. Yes, there are a few examples in C#, but that is not sufficient to the Beginners and the examples are in older version of iTextSharp
, there are lots of change in the latest version. So, it will be difficult for beginners to convert older version to latest version. Besides, I think that if I write an Article on this, then it will help me also as a future reference as I'll describe each functionality of this library with example. Frankly speaking, in this Article, you find all the examples from Chapter 1 of the book iText in Action, Second Edition which is written for Java Developers. I'll explain all the examples of the rest Chapters in my next release of this Article. So if any one is interested in using this library, he/she will get a good kick start. To know the history or any other details of iTextSharp, please go through the Official Website
Requirements
- To compile this library, you need a C# 2008 compiler or better, Visual Studio 2008 or Visual C# 2008 Express Edition
- This library code will run in:
- .NET 2.0
- .NET 3.0
- .NET 3.5
- .NET 4.0
- .NET 4.0 Client Profile
- .NET 4.5
- .NET 4.5 Client Profile
Installation
- Simply install the NuGet package
Or you can download the library DLL from the above link or from the SourceForge. Then do the following:
- Add the following library into your project by adding reference to that library DLL. Just see the image below:
- The necessary namespace that you have to add into your C# file to do what are in this Article are::
iTextSharp.text
iTextSharp.text.pdf
Quick Start
Creating PDF Document in 6 Steps:
- Step 1: Create a
System.IO.FileStream
object: - Step 2: Create a
iTextSharp.text.Document
object: - Step 3: Create a
iTextSharp.text.pdf.PdfWriter
object. It helps to write the Document to the Specified FileStream: - Step 4: Openning the Document:
- Step 5: Adding a Paragraph by creating a iTextSharp.text.Paragraph object:
- Step 6: Closing the Document:
Working with Page Size of PDF Document:
Creating a Page of specified size, we must have to create a
iTextSharp.text.Rectangle
object and Passing the size as argument to its constructor. There are a few way to define Page Size: - First Way to define Page Size:
Creating Page Size by Pixels or Inch. NOTE: In iTextSharp library, unit is 'point'. 72 points = 1 inch. Suppose we want to create a PDF File of width = 2 inch & height = 10 inch, then we need 144pt for 2 inch & 72pt for 10 inch. Lets see, how to do this: - Second Way to define Page Size:
Taking Page Size from in-builtiTextSharp.text.PageSize
class:
The following are the Supported in-built Page Size. Read the full Documentation of Page Size:_11X17
A0
A1
A10
A2
A3
A4
A4_LANDSCAPE
A5
A6
A7
A8
A9
ARCH_A
ARCH_B
ARCH_C
ARCH_D
ARCH_E
B0
B1
B10
B2
B3
B4
B5
B6
B7
B8
B9
CROWN_OCTAVO
CROWN_QUARTO
DEMY_OCTAVO
DEMY_QUARTO
EXECUTIVE
FLSA
FLSE
HALFLETTER
ID_1
ID_2
ID_3
LARGE_CROWN_OCTAVO
LARGE_CROWN_QUARTO
LEDGER
LEGAL
LEGAL_LANDSCAPE
LETTER
LETTER_LANDSCAPE
NOTE
PENGUIN_LARGE_PAPERBACK
PENGUIN_SMALL_PAPERBACK
POSTCARD
ROYAL_OCTAVO
ROYAL_QUARTO
SMALL_PAPERBACK
TABLOID
- Third Way to define Page Size:
Rotating Document i.e. height becomes width & vice-versa:
Now, just pass this
iTextSharp.text.Rectangle
object (any one) i.e. either 'rec', or 'rec2' or 'rec3' to the iTextSharp.text.Document
's constructor during object creation like below:Setting Background Color of PDF Document:
There are a few ways to set background color:
- First Way to Set Background Color:
It takes the object ofiTextSharp.text.BaseColor
. BaseColor constructor takes in-built System.Drawing.Color object Or you can pass RGB values to the constructor in different forms: - Second Way to Set Background Color:
It takes the object ofiTextSharp.text.pdf.CMYKColor
. CMYKColor constructor takes only CMYK values in different forms:
Setting Page Margins of PDF Document:
Margins can be set during
Suppose we set the margins as below:
Document
object creation like Page SizeSuppose we set the margins as below:
- Left Margin: 0.5 inch
- Right Margin: 1 inch
- Top Margin: 1.5 inch
- Bottom Margin: 2.5 inch
So, we need to do set the following points for the Left, Right, Top, Bottom Margins respectively as we already know that
iTextSharp
library only understand points where 72 points = 1 inch.- Left Margin: 36pt => 0.5 inch
- Right Margin: 72pt => 1 inch
- Top Margin: 108pt => 1.5 inch
- Bottom Margini: 180pt => 2.5 inch
Lets implement:
Setting Text Alignment in PDF Document:
Alignment
is one of the property of iTextSharp.text.Paragraph
's object. iTextSharp
Library provides various types of Alignments. These Alignments can be access through iTextSharp.text.Element
class. The following are Alignment types provides iTextSharp:- [^]
- [^]
- [^]
- [^]
- [^]
- [^]
- [^]
- [^]
- [^]
- [^]
As we already see the
iTextSharp.text.Document
's constructor takes iTextSharp.text.Paragraph
's object during Document creation. So, after creating the Paragraph object and setting Alignment property, we can pass this object to iTextSharp.text.Document
's constructor during Document ceration. Lets implement:Setting Meta Information or Properties of a PDF Document:
The following Meta information of PDF Document, you can set through
iTextSharp.text.Document
's methods by creating its object i.e. doc
here:- Author Name[^]
- Creation Date[^]
- Creator Name[^]
- Header Name & Content[^]
- Keywords[^]
- Langugae[^]
- Producer[^]
- Subject[^]
- Title[^]
Lets implement a few of them:
Now after openning this PDF file, right click over it and click Properties, then you'll see the following:
Creating a Multipage Document:
We can create a new page through
iTextSharp.text.Document
's NewPage()
method by creating its object. Lets add five pages in PDF Document:Creating a New PDF Document from an existing PDF Document:
We can read from a PDF Document using
iTextSharp.text.pdf.PdfReader
's object and write it to another PDF Document using iTextSharp.text.pdf.PdfStamper
's object. Lets implement:Adding Watermark to PDF Document using Layer:
Watermark can be add after creating the PDF Dodument in
iTextSharp
Library. Here I'll add Watermark to existing PDF Document i.e. Original.pdf
, through creating a iTextSharp.text.pdf.PdfLayer
object. Lets implement: The created PDF Document is below:
Removing Watermark from the just created Watermarked Document by Removing Layer:
Whenever we add Layer in PDF Document, then the content of the Layer resides under
OCG
Group. So if I remove this Layer we can remove the content of the Layer also e.g. here it is Watermark Text. To remove all the Layers from PDF Document, you have to remove OCG Group completely from the Document using reader.Catalog.Remove(PdfName.OCPROPERTIES)
. Now follow the Steps below to remove the Watermark Text from Layer:- Read the existing watermarked document using
iTextSharp.text.pdf.PdfReader
's object - Taking each Page in the
iTextSharp.text.pdf.PdfDictionary
's object usingGetPageN(int pageNumber)
method ofiTextSharp.text.pdf.PdfReader
's object. - Taking the Content of the Page in the
iTextSharp.text.pdf.PdfArray
's object usingGetAsArray(PdfName.CONTENTS)
method ofiTextSharp.text.pdf.PdfDictionary
's object - Loop through this array and Get each element as
iTextSharp.text.pdf.PRStream
's object usingGetAsStream(int arrayIndex)
method ofiTextSharp.text.pdf.PdfArray
's object - Convert each stream into Bytes using Static method of
iTextSharp.text.pdf.PdfReader
class - Convert these Bytes into String using method
- Search for the String '/OC' and also the
Watermarked Text
. If found then remove it by giving it zero length and zero data using two methods:Put()
&SetData()
ofiTextSharp.text.pdf.PRStream
class - Write this modified document exists in the
reader
to a new document usingiTextSharp.text.pdf.PdfStamper
's object
Lets Implement it:
Adding Watermark to each Page during Creation:
Now, we already know that, watermark cannot be add during Page creation, it have to add after document creation. So, I've created a class
PDFWriterEvents
which implements the interface iTextSharp.text.pdf.IPdfPageEvent
and modify the event OnStartPage
. This interface contains a set of events from the Openning & to Closing the PDF Document. The events are following:public void OnOpenDocument(PdfWriter writer, Document document)
public void OnCloseDocument(PdfWriter writer, Document document)
public void OnStartPage(PdfWriter writer, Document document)
public void OnEndPage(PdfWriter writer, Document document)
public void OnParagraph(PdfWriter writer, Document document, float paragraphPosition)
public void OnParagraphEnd(PdfWriter writer, Document document, float paragraphPosition)
public void OnChapterEnd(PdfWriter writer, Document document, float paragraphPosition)
public void OnSectionEnd(PdfWriter writer, Document document, float paragraphPosition)
You may modify other events accroding to your needs which occured against a particular action. Let see the which I've created:
Lets see how & when you use the object of this class:
See,
OnStartPage
event called during adding a new paragraph. So I don't need to add watermark later:)Export/Print/Output the PDF File directly to the Client without saving it to the Disk:
We can create PDF File in memory by creatig
System.IO.MemorySystem
's object. Lets see:Setting Viewer Preferences of a PDF Document:
The values of the different
ViewerPreferences
were originally stored in iTextSharp.text.pdf.PdfWriter
class as an integer constant. You can set the ViewerPreferences
by following two ways: - By setting property
ViewerPreferences
ofiTextSharp.text.pdf.PdfWriter
class. To know all theViewerPreferences
and its purpose, please read this first. E.g.- - By calling method
AddViewerPreference(PdfName key, PdfObject value)
ofiTextSharp.text.pdf.PdfWriter
's object. To know whichvalue
is appropiate for whichkey
, read this first. E.g.-
Encrypting a PDF Document:
By
SetEncryption()
method of iTextSharp.text.pdf.PdfWriter
's object, we can encrypt a PDF document. Read full documentation of this method here. To know all the encryption types, click here. E.g.-