Hallo Welt mit iTextSharp

Heute habe ich mir mal die iTextsharp.dll von Sourceforge geladen, um aus C# heraus mal eine PDF Datei zu erzeugen. Im Visual Studio Projekt muss dann nur ein Verweis auf diese DLL erstellt werden, dann sollte das folgende Beispiel problemlos laufen. Ausgehend von diesem Beispiel werde ich mal schauen, ob man das nicht für was Sinnvolles einsetzen kann.
Ist sicher kein Ersatz für LaTeX, ein paar Dinge könnte ich mir jedoch vorstellen… 🙂

using System.IO;
using System.Text;
using iTextSharp.text;
using iTextSharp.text.pdf;
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Document pdfDocument = new Document();
            PdfWriter.GetInstance(pdfDocument, new FileStream("C:\\hallo.PDF", FileMode.Create));
            pdfDocument.Open();
            pdfDocument.Add(new Paragraph("Ich bin ein Absatz"));
            pdfDocument.Close();
        }
    }
}

Auch aus Powershell heraus lässt sich iTextsharp nutzen: http://www.powershell.nu/2009/09/08/scripting-pdf-documents-through-powershell/

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website