Write PDF files using .Net

This item was filled under [ .Net ]

“iText is a library that allows you to generate PDF files on the fly” – using this library, one can easily write PDFs in .Net. To get started, download the library from http://www.lowagie.com/iText/ (or SourceForge.net).

After downloading the .dll file, add it as a reference in your application.

Sample code (C#.Net):

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;

namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
//1. Create a document obj.
Document myDoc = new Document(PageSize.A4.Rotate());

//2. Create a writer & stream that will write to the file
PdfWriter.GetInstance(myDoc, new FileStream("Em.pdf", FileMode.Create));

//3. Open document
myDoc.Open();

//4. Write content to the document
myDoc.Add(new Paragraph("Hello World!"));

//5. Close document
myDoc.Close();
}
}
}

Rate this topic:
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
Popularity: 127 views
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Comment on “Write PDF files using .Net”

  • 25 August, 2008, 22:11

    Hello,

    Our DynamicPDF products for .NET will allow you to create PDF documents programmatically from scratch, merge existing PDF documents, add contents to existing PDF files, stamping PDFs, appending existing PDF documents, form filling, rotating and scaling PDFs, etc.

    You can also create the PDF reports using the Report Writer product for .NET which has a user interface Report Designer to create the report layout.

    PDFs generated by our product are fully comply with the PDF specifications of Adobe. Our product is designed keeping the efficiency in mind and we do provide an excellent technical support for our customers.

    Please feel free to download the fully functional Evaluation version of our product DynamicPDF for .NET http://www.cete.com/Products/DynamicPDFForNET/Suite/Download.csp. Refer the downloaded dll files in your application. Also please go through the examples downloaded with the product download.

    Below is the sample example to generate the PDF file from scratch:

    ceTe.DynamicPDF.Document document = new ceTe.DynamicPDF.Document();
    document.Creator = “HelloWorld.aspx”;
    document.Author = “Your Name”;
    document.Title = “Hello World”;

    // Create a page to add to the document
    ceTe.DynamicPDF.Page page = new ceTe.DynamicPDF.Page( PageSize.Letter, PageOrientation.Portrait, 54.0f );

    // Uncomment the line below to add a layout grid to the page
    //page.Elements.Add( new LayoutGrid() );

    // Create a Label to add to the page
    string strLabel = “Hello C# World…\nFrom DynamicPDF™ Generator for .NET\nDynamicPDF.com”;
    Label label = new Label( strLabel, 0, 0, 504, 100, Font.Helvetica, 18, TextAlign.Center );

    // Add label to page
    page.Elements.Add( label );

    // Add page to document
    document.Pages.Add( page );

    // Outputs the document to the current web page
    document.DrawToWeb( “HelloWorld.pdf” );

Leave a Comment