3

I know how to open an internal pdf file :

public ActionResult GetPDF( string filename )
{
    return File( filename, "application/pdf", Server.HtmlEncode( filename ) );
}

question is, how to open a PDF file from an other/external website, e.g. http://example.com/mypdffile.pdf

2 Answers 2

5

You don't really need a controller action to do this. You could simply:

<a href="http://www.blabla.com/mypdffile.pdf">Open mypdffile.pdf</a>

Of course if you want to hide this address from the user you could use a WebClient to fetch it on the server:

public ActionResult GetPDF() 
{ 
    using (var client = new WebClient())
    {
        var buffer = client.DownloadData("http://www.blabla.com/mypdffile.pdf");
        return File(buffer, "application/pdf", "mypdffile.pdf");
    }
}

And in your view:

<%= Html.ActionLink("Download PDF", "GetPDF") %>
Sign up to request clarification or add additional context in comments.

Comments

0

You will need it locally anyway to do any processing so, you can download it to local folder and then show it. use WebClient or HttpRequest/HttpResponse objects to do the downloading

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.