Display file in an Iframe MVC Razor - asp.net-mvc

My problem here is I have been trying to display a pdf file in an Iframe.It works fine in IE but not working in chrome or firefox.However I am able to open them in a new tab.But as per my requirement I have to display it along with other form where data from pdf will be filled in the form.So I have used Iframes.Is there any other solution to display file along with form other than Iframes.what can i do with it? Below is the one which I tried.
<iframe src="file://///GSEV/PdfsFolder/#Model.FileName"></iframe>
<iframe src="#Url.Content("file://///GSEV/PdfsFolder/" + Model.FileName )"></iframe>
thanks in advance..

Related

Display File From Local Drive in MVC view

I have been trying to display local Pdffile from D drive in a view of MVC along with other data.I have tried out Iframe and even added extensions for browsers like local links to display but of no use.I have been stuck with this problem since 3 days.I have tried out the following code.
<iframe src="#Url.Content("file:///D:/PdfsFolder/" + Model.FileName)"></iframe>
This works fine for me in IE but not working in Other browsers.When I try to open only the file using hyperlink it works in all browsers.My problem is to display it along with other data.please help me out If there is any other way to display that file in the View other than Iframe.
you have to write a controller & action that will fetch the file and pass back to the response:
public ActionResult TestPdf()
{
return File(#"d:\test.pdf", "application/pdf");
}
and now in your view you could use an iframe to point it to this controller action:
<iframe src="<%= Url.Action("TestPdf", "SomeController") %>"></iframe>
why are to trying to attach a file from drive use root directory of project to pic the files like create a folder in your project put files their and try below code
<img src="<%= Url.Content("~/Content/UserImages/FileName.jpg") %>" />

issue when converting html string to pdf using evo pdf library

I got a problem when converting html string to pdf, to be simple, I found the Kendo js/css file I referenced in my html string looks like not working at all.
Detail:
I am working on a project that converting my views(ASP MVC 4.5
) to Pdf using Evo Pdf, in my view, I have used Kendo UI controls, so I reference the Kendo css js file like below in my view file
#Scripts.Render("~/Libs/KendoUI/js/kendo.all.min.js")
<script type="text/javascript" src="#Url.Content("~/Libs/KendoUI/js/kendo.all.min.js")"></script>
When I open the view in browser, all controls works fine, but when I render the view into string, and pass it to Evo SavePdfFromHtmlStringToStream function, the pdf is generated but all the Kendo controls are missing on the pdf.
Ps, I know maybe I can use the absolute URL to convert URL to Pdf, but I am using view with model(model are posted to controller), so I don’t really want to do that.
Actually, I found the solution 2 weeks ago from Evo team, I just need set a base url in the parameters, that's all, now works fine! thanks for all!

How do I return MVC File ActionResult of PDF over jQuery modal dialog

Note: I am not wanting to display the PDF inline with the modal. Rather, I am looking to have the browser acknowledge the file and allow the user to save or open it.
I have a jQueryUI modal dialog in MVC 4. The dialog IS modal. The content of the dialog is from a Partial Views which works fine. I have only one button on the dialog itself and have successfully gotten all the JavaScript to deal with client side data entry checking.
What is giving me a headache is that I have one button embedded in the Partial View that is to display a PDF file. I can successfully call a JavaScript function that calls the controller that gets the file from another server. I can even get the file converted to a byte array and the last line is
return File(contents, "application/pdf", "PropsedChanges.pdf");
However it will not open as I suspect that the modal dialog is preventing it.
I have done something similar outside of the model dialog and it gives me the save/open option at the bottom of the screen for IE or in the correct manner in other browsers.
Is there a way to display the PDF in a registered PDF viewer on the client's PC/Device outside of the browser needing to ask if they want to save or open it? Which, as I suspect, is not happening due to the modal dialog.
Help is greatly appreciated.
public ActionResult GetPdf(Model modelo)
{
return File(Pdf bytes[], "application/pdf");
}
Try using a new window to open your PDF. Like target="_new" or "blank".
If you are using Asp.net 5, install MvcPdfActionResult via nuget
PM> Install-Package MvcPdfActionResult
Simply use return type as PdfActionResult in the controller will output PDF document instead of HTML. This converts HTML to PDF using the iTextXmlWorker Library.
...
return PdfActionResult(model);
}
Generates pdf documents from your razor views within an asp.net 5 MVC project. https://www.nuget.org/packages/MvcPdfActionResult/

Print web page with original look

I want to achieve print functionality such that user can print out the web form and use it as paper form for the same purpose. Of course I do not need all the web page header and footer to be printed, just content of a div which take most of the page. I did play around with media print css and menage print result to look almost as original page. But the I tried to print it in another browser(Chrome) and it is all messed. (before I tried Mozilla).
For the web form I user css framework Twitter Bootstrap and I had to override its css (in print media) for almost each element individually to get some normal look in the print result.
My question is is there some way (framework/plugin) to print just what you see on the page, maybe as an image or something?
Any other suggestions are welcome.
Thanks.
If you are familiar with PHP you can try the PHP class files of TCPDF or those of FPDF.
Or there is also dompdf which renders HTML to PDF, but this will include more than just the information of one div.
And for further info here is a post on Stack where users are discussing which they think is best.

Display file (PDF/TXT) on form brought from Database in MVC ASP.NET

I want to display file on my form using MVC.
I am bringing a Byte[] array data from the Database, and using FileContentResult I am converting it into a file.I want to now display this file on my page for viewing . How can it be acheived. What code to write in my View for the same.
Assuming you're using Razor, rendering a text file can be done as simple as:
<div>
#(new System.IO.StreamReader("myFile.txt")).ReadToEnd()
</div>
For PDF files, you'll have to find a third-party component to convert to HTML.
You probably don't want to use FileContentResult, that is something generally used for providing the raw file.
In theory though there is nothing different in using any other url
<img src="#Html.ActionLink("View","Image",{id = Model.key})" />
Or you can provide that link in a pdf reference, or as a stylesheet etc.

Resources