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