. NET Quick Create PDF document by C #

Source: Internet
Author: User

Original address: http://www.cnblogs.com/Creator/archive/2010/03/13/1685020.html

C # Reference itext create PDF document

Refer to Itext to download components from here

Five steps to create a PDF in the following illustration

First step: Create an instance of a file object

Document mydocument= New Document (PageSize.A4.Rotate ());

Step Two: Create a writer listener file and write the desired stream to the file

Pdfwriter.getinstance (MyDocument, New FileStream ("Salman.pdf", FileMode.Create));

Step three: Open the file

Mydocument.open ();

Fourth step: Write some content to the file

Mydocument.add (New Paragraph ("First Pdf File made by Salman using IText");

Fifth step: Finally remember to close the file

Mydocument.close ();

Using System;
Using System.IO;
Using System.Diagnostics;

Using Itextsharp.text;
Using ITextSharp.text.pdf;

Publicclass Itextdemo
{
Publicstaticvoid Main ()
{
Console.WriteLine ("IText Demo");

Step 1:creation of a Document-object
Document MyDocument =new Document (PageSize.A4.Rotate ());

Try
{

Step 2:
Now create a writer, that listens-doucment and writes the document to desired Stream.

Pdfwriter.getinstance (MyDocument, New FileStream ("Salman.pdf", FileMode.Create));

Step 3:open the document now using
Mydocument.open ();

Step 4:now Add some contents to the document
Mydocument.add (New Paragraph ("First Pdf File made by Salman using IText");

}
catch (Documentexception de)
{
Console.Error.WriteLine (DE. Message);
}
catch (IOException IoE)
{
Console.Error.WriteLine (IoE. Message);
}

Step 5:remember to close the documnet

Mydocument.close ();
}
}

To view the original English, click here

. NET Quick Create PDF document by C #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.