Hi kaungzawli,
I have created sample. I have IDM install in my pc and i have adobe reader 11 also install. Refer the below code.
Controller
public ActionResult Index()
{
return View();
}
public FileResult OpenPDF()
{
return File(Server.MapPath("/PDF/Aptitude Formulas.pdf"), "application/pdf");
}
public FileResult DownloadPDF()
{
string filepath = Server.MapPath("/PDF/Aptitude Formulas.pdf");
byte[] pdfByte = GetBytesFromFile(filepath);
return File(pdfByte, "application/pdf", "test.pdf");
}
public FileResult DisplayPDF()
{
string filepath = Server.MapPath("/PDF/Aptitude Formulas.pdf");
byte[] pdfByte = GetBytesFromFile(filepath);
return File(pdfByte, "application/pdf");
}
public PartialViewResult PDFPartialView()
{
return PartialView();
}
public byte[] GetBytesFromFile(string fullFilePath)
{
// this method is limited to 2^32 byte files (4.2 GB)
FileStream fs = null;
try
{
fs = System.IO.File.OpenRead(fullFilePath);
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, Convert.ToInt32(fs.Length));
return bytes;
}
finally
{
if (fs != null)
{
fs.Close();
fs.Dispose();
}
}
}
OpenPDF.cshtml
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Open PDF</title>
</head>
<body>
<div>
</div>
</body>
</html>
DownloadPDF.cshtml
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Download PDF</title>
</head>
<body>
<div>
</div>
</body>
</html>
DispalyPDF.cshtml
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Display PDF</title>
</head>
<body>
<div>
</div>
</body>
</html>
PDFPartialView.cshtml
<embed src="~/PDF/Aptitude Formulas.pdf" width="500px" height="200px" type="application/pdf"></embed>
Screenshot
