With this article, I will tell you about how to to read pdf document properties in  ASP.NET 5. We know that there is no- such  in-built class in .NET framework that read the pdf document. In this example,I will used third-party library iTextSharp. And here is the code that I used for this article:

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PdfPropertiesReader.aspx.cs"    Inherits="PdfPropertiesReader" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div id="pdfProperties" runat="server">
        </div>
    </div>
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Read Pdf Properties" />    </form>
</body>
</html>


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)
    {
        try
        {
            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)
        {
            Response.Write(exception.Message);
        }
    }
}

HostForLIFE.eu ASP.NET 5 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.