2

I am trying to open pdf in a new tab using Asp.net mvc controller. it is opening in new tab correctly but the document name is not showing here is my code

 public ActionResult ViewDocument() { byte[] docFileArr=...... var cntdn = new System.Net.Mime.ContentDisposition { FileName = DocumentName, Inline = true, }; Response.AppendHeader("Content-Disposition", cntdn .ToString()); return File(docFileArr, "application/pdf"); } 

the document opening in new window correctly but it showing the controller name only not the document name. please see the attachment.

thanks in advance for help enter image description here

1

2 Answers 2

2

One way to achieve this is to set the title in the metadata of the PDF (either during creation of the PDF or manipulating it, before the download begins). This has been covered by the already given SO questions.

Another approach is to open a new tab, load an own HTML page generated by an ASP.NET MVC View there, which itsself embeds the PDF file, provided by the ViewDocument action (a more appropriate name would be DownloadDocument).

The HTML page would have a Title in its HTML header, that would be shown by the browser. E.g. the view can look like (just to give the idea):

@{ Layout = null; } <!DOCTYPE html> <html height="100%"> <head> <meta charset="utf-8" /> <title>@Model.Caption</title> <script src="/js/pdfobject.js"></script> <style> .pdfobject-container { height: 96vh; width: 99vw; } </style> </head> <body height="100%"> <div id="pdf" height="100%"></div> <script>PDFObject.embed("@Model.DownloadUrl", "#pdf");</script> </body> </html> 

It uses the PDObject.js library to make PDF embedding easier and less error prone.

Sign up to request clarification or add additional context in comments.

Comments

0

Web browser actually use metadata included in the PDF files in order to display the title. That way, your file will have the same title without any regards to how it's loaded (from your .NET app, from the desktop after download, etc.).

See this article on how to view and edit metadata from Adobe, using Acrobat: https://helpx.adobe.com/acrobat/using/pdf-properties-metadata.html

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.