How to read pdf document properties in

In this post, I will show you how to read the pdf document properties in we know that there is no- such in-built class in the .net framework that read the pdf document. So, for this demo, I will use the third-party library iTextSharp.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PdfPropertiesReader.aspx.cs"
    Inherits="PdfPropertiesReader" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <div id="pdfProperties" runat="server">
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Read Pdf Properties" />
using System;
using System.Collections;
using System.Collections.Generic;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.Text;

public partial class PdfPropertiesReader : System.Web.UI.Page
    private const string FileNmae = @"C:\\temp\\asp.pdf";
    protected void Page_Load(object sender, EventArgs e)

    protected void Button1_Click(object sender, EventArgs e)
            StringBuilder stringBuilder = new StringBuilder();
            // create a reader (constructor overloaded for path to local file or URL)
            PdfReader reader = new PdfReader(FileNmae);
            // total number of pages
            int n = reader.NumberOfPages;
            // size of the first page
            Rectangle psize = reader.GetPageSize(1);
            float width = psize.Width;
            float height = psize.Height;
            Console.WriteLine("Size of page 1 of {0} => {1} × {2}", n, width, height);
            // file properties
            Hashtable infodict = reader.Info;
            foreach (DictionaryEntry kvp in infodict)
                stringBuilder.Append(kvp.Key + "=>" + kvp.Value + "</br>");

            pdfProperties.InnerHtml = stringBuilder.ToString();
        catch (Exception exception)

Next Post Previous Post
No Comment
Add Comment
comment url