Code/C#

iTextSharp 샘플코드 - Hello World

Hide Code 2008. 4. 8. 12:43
iTextSharp 컴포넌트를 이용한 샘플코드이다.

가장 기본적인 예제로 Hello World 파일을 만드는 예제이다.

using System;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;

namespace iTextSharpSample
{
   class Program
   {
       static void Main(string[] args)
       {
           // step 1:
           // Create an instance of the iTextSharp.text.Document object
           Document document = new Document();

           // step 2:
           // Create a Writer that listens to this document and writes the document to the Stream
           PdfWriter.GetInstance(document, new FileStream("sample.pdf", FileMode.Create));

           // step 3:
           // Open the document
           document.Open();

           // step 4:
           // Adds content to the document
           document.Add(new Paragraph("Hello World"));

           // step 5:
           // Closes the document
           document.Close();
       }
   }
}