How to use iTextSharp?

So, I need a PDF generator for my ASP.NET application. I downloaded iTextSharp because it seems the most popular free. But after searching the Internet I can’t find the information I need to get started. The few tutorials I've found so far are too confusing. I know a book there, but I am a student and do not want to spend money. I just need really basic step-by-step information, preferably with code in VB. The most basic tutorial I've found so far is http://www.mikesdotnetting.com/Article/80/Create-PDFs-in-ASP.NET-getting-started-with-iTextSharp , but it does not work for me. I tried to follow it and came up with this code:

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using iTextSharp.text; using iTextSharp.text.pdf; using System.IO; public partial class Default3 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { var doc1 = new Document(); string path = Server.MapPath("PDFs"); PdfWriter.GetInstance(doc1, new FileStream(path + "/Doc1.pdf", FileMode.Create)); doc1.Open(); doc1.Add(new Paragraph("My first PDF")); doc1.Close(); } } 

But this gives me an error: "CS1502: best overloaded method matching for" iTextSharp.text.pdf.PdfWriter.GetInstance (iTextSharp.text.Document, System.IO.Stream) "contains some invalid arguments" and the highlighted line is PdfWriter.GetInstance ...

Somehow, I was wondering if anyone knows what I did wrong in this tutorial, or what other tutorials I can use. Or, if you want to give me a basic explanation of how to start my words, that would be great. Keep in mind, unfortunately, I don’t know anything about this. :) Thank you.

+7
source share
2 answers

It's hard to say, but I'm going to assume that your doc not iTextSharp.text.Document; Using all of these “used” commands, it’s quite possible that you have imported several classes with the name “Document” and get the wrong version.

You should be able to use the full name to see if this is really a problem:

 var doc1 = new iTextSharp.text.Document(); 

(Fair Warning: I do not know vb.net, so the actual syntax may be completely different)

using Spam is going to create problems with name collisions sooner or later. "Sooner or later" in this case.

+3
source

iTextSharp is a direct port from the iText Java library , so you can link to any of iText's native documents and usually apply them to C # and .NET.

The best documentation is in iText in Action , but you can download the sample code book from a website, and basic API documents are also available on the Internet.

This CodeProject article also has some downloadable .NET iTextSharp .NET source code examples:

+2
source

All Articles