. Net quick creation of PDF document by C #

Source: Internet
Author: User

C # reference itext to create a PDF document

You can reference itext fromHereDownload Components

The following shows how to create a PDF file in five steps.

Step 1: Create an instance of a file object

Document mydocument = new document (Pagesize. a4.rotate ());

Step 2: Create a writer listening file and write the desired stream to the file

Using writer. getinstance (mydocument, new filestream ("salmanworkflow", filemode. Create ));

Step 3: open the file

Mydocument. open ();

Step 4: write some content to the file

Mydocument. Add (new paragraph ("first PDF file made by Salman using itext "));

Step 5: Close the file

Mydocument. Close ();

 

 Using  System;
Using System. IO;
Using System. diagnostics;

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

Public Class Itextdemo
{
Public Static Void 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 to this doucment and writes the document to desired stream.

Using writer. 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 specified net

Mydocument. Close ();
}
}

 

To view the original English text, click here

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.