.Net, ASP.NET, C#, CodeProject, iTextSharp, PDF, Programming, Software, VB.NET, Web Development, WebForms

iTextSharp – Insert an Image to a PDF in C#

iTextSharp PDF
Using iTextSharp to Generate a PDF

This article will review the basics of programmatically inserting and positioning an image in a PDF being generated using the iTextSharp library. I’ll show you the code for doing so in both C# and VB.NET.

Here are the main categories I’ll be covering, with links to the appropriate section:

  1. Adding your image programmatically while generating your PDF
  2. Adjusting your image scaling so it renders nicely in your PDF
  3. Positioning your image in your PDF
  4. Example code in C#
  5. Example code in VB.NET

If you are interested in working with the iTextSharp .NET libraries then have a look at some of the other articles covering iTextSharp I have written on the topic. Continue reading “iTextSharp – Insert an Image to a PDF in C#”

.Net, ASP.NET, CSS3, GridView, HTML, iTextSharp, JavaScript, PDF, Programming, Reports, Software, Technology, VB.NET, Visual Studio 2010, Web Development

Generate a PDF from an ASP.NET Web Page using the iTextSharp XMLWorker Namespace

If you need to quickly and easily generate PDF documents from ASP.NET, then the iTextSharp library for .NET is very convenient. To install and start using iTextSharp, you can download the zipped reference files from the SourceForge Web site and then add them to your Visual Studio project the same way as you would do with any other third party library file.

The latest version of iTextSharp has deprecated the older HTMLWorker object in favor of the newer XMLWorkerHelper object. This is good news for any developer who likes to use CSS formatting. Although the CSS support is still basic, it is a definite step up from the earlier version of the object which did not support CSS at all. For example, the new object allows a number of important behaviors such as PDF page breaks that were impossible to do using the older object.

To make use of the XMLWorkerHelper object you will need to reference two DLL files in your Visual Studio project. These are:

  1. itextsharp.dll
  2. itextsharp.xmlworker.dll

Once you have referenced these two libraries you are ready to start coding.

In this article I provide a fully working example in both C# and VB.NET. Each example consists of a report page that outputs a simple table, and the main PDF generation page. See the explanation below for further details.

Just to note: if you are interested in further information about iTextSharp then please have a look at the collection of articles I’ve written that cover using iTextSharp for .NET PDF generation.

Continue reading “Generate a PDF from an ASP.NET Web Page using the iTextSharp XMLWorker Namespace”

.Net, ASP.NET, HTML, iTextSharp, Programming, Software, Technology, VB.NET, WebForms

Points to keep in mind when working with the iTextSharp HTML to PDF converter (HTMLWorker)

If you are looking for a tool to convert an HTML document to a PDF, then the iTextSharp converter is a great tool. iTextSharp provides open source libraries for various languages including Java and .NET. If you wish to commercially use iTextSharp, you will, however, need to pay for the license.

Keep in mind that I am basing my observations on the iTextSharp port to .NET. The Java version may behave differently.

I personally like the iTextSharp tool, and even given its quirks, will continue using it. Please note thatthis article is focussed on observations of the iTextSharp HTMLWorker object. Significant advancements have been made with the iTextSharp XMLWorker object which you can read more about in another article I have written.

Have a look at the collection of articles I’ve written that cover the iTextSharp for .NET PDF generation.

Here are some of the main points to consider when planning/writing your HTML to PDF conversion function using the iTextSharp HTMLWorker Object Continue reading “Points to keep in mind when working with the iTextSharp HTML to PDF converter (HTMLWorker)”