|
using System;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace iTextSharp.tutorial.Chapter1
{
/// <summary>
/// Example 4 shows: Setting Meta Information or PDF Document Properties
/// </summary>
public class Example4
{
public Example4()
{
string appRootDir = new DirectoryInfo(Environment.CurrentDirectory).Parent.Parent.FullName;
try
{
// Step 1: Creating System.IO.FileStream object
using (FileStream fs = new FileStream(appRootDir + "/PDFs/" + "Chapter1_Example4.pdf", FileMode.Create, FileAccess.Write, FileShare.None))
// Step 2: Creating iTextSharp.text.Document object
using (Document doc = new Document())
// Step 3: Creating iTextSharp.text.pdf.PdfWriter object
// It helps to write the Document to the Specified FileStream
using (PdfWriter writer = PdfWriter.GetInstance(doc, fs))
{
// Setting Document properties e.g.
// 1. Title
// 2. Subject
// 3. Keywords
// 4. Creator
// 5. Author
// 6. Header
doc.AddTitle("Hello World example");
doc.AddSubject("This is an Example 4 of Chapter 1 of Book 'iText in Action'");
doc.AddKeywords("Metadata, iTextSharp 5.4.4, Chapter 1, Tutorial");
doc.AddCreator("iTextSharp 5.4.4");
doc.AddAuthor("Debopam Pal");
doc.AddHeader("Nothing", "No Header");
// Step 4: Openning the Document
doc.Open();
// Step 5: Adding a paragraph
// NOTE: When we want to insert text, then we've to do it through creating paragraph
doc.Add(new Paragraph("Hello World"));
// Step 6: Closing the Document
doc.Close();
}
}
// Catching iTextSharp.text.DocumentException if any
catch (DocumentException de)
{
throw de;
}
// Catching System.IO.IOException if any
catch (IOException ioe)
{
throw ioe;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Hello! Myself
Debopam Pal. I've completed my MCA degree from West Bengal University of Technology at 2013. I'm from India. I’ve started to work with MS Technologies in 2013 specially in C# 4.0, ASP.NET 4.0. I've also worked in PHP 5. Now I work in JAVA/J2EE, Struts2. Currently I'm involved in a e-Governance Project since Jan, 2014. In my leisure time I write Blog, Articles as I think that every developer should contribute something otherwise resource will be finished one day. Thank you for your time.
Visit:
Linkedin Profile |
Facebook Profile |
Google+ Profile |
CodeProject Profile