Saturday, 24 September 2016

How to add meta information of PDF file using iTextSharp with C-Sharp

In this article, we are going to learn how to add meta information of PDF file using itextsharp in asp.net with C#. First, you need to download iTextSharp dll from the internet. Click on the below link to download

https://github.com/itext/itextsharp

Once file is downloaded, extract it, now you will find 6 more .rar file. Again extract itextsharp-dll-core.rar file, after that add reference of itextsharp.dll to your project.

Related Article

  1. How to generate PDF file using iTextSharp in C#
  2. How to export GridView data into PDF using iTextSharp in asp.net with C#
  3. Insert an image into PDF using iTextSharp with C# (C-Sharp)
  4. How to extract images from a pdf file using C#.Net

In Code-Behind File

Add below nampespaces.

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

Complete C# code:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        AddMetaInfo();
    }
}
public void AddMetaInfo()
{
    // create filestream object
    FileStream fs = new FileStream(Server.MapPath("Example.pdf"), FileMode.Create);

    // create document object
    Document doc = new Document();

    // create PdfWriter instance which will write at file filestream
    PdfWriter.GetInstance(doc, fs);

    // opening the dociment
    doc.Open();

    // creating paragraph object
    Paragraph para = new Paragraph("Add meta information");
    para.Alignment = Element.ALIGN_CENTER;

    // Adding meta info 
    doc.AddTitle("C# iTextSharp");
    doc.AddAuthor("ASPArticles.com");
    doc.AddSubject("Adding meta information of pdf");
    doc.AddKeywords("ASP.Net Articles, iTextSharp, PDF, add Meta Info to PDF");
    doc.AddCreator("iTextSharp dll");

    // adding pargraph to document
    doc.Add(para);

    doc.Close();
}

Once PDF file is generated, Open the file-> go to file menu -> click on Properties then you will see the meta information as shown below.

Adding meta information of PDF file using iTextSharp
Share:

0 comments:

Post a Comment

Email Subscription

Subscribe to our newsletter to get the latest articles directly into your inbox

Blog Archive

BUY FROM AMAZON