Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View PDF as part of the page

Tags:

I am trying to view a PDF document in my MVC web page, but I cant make it to work.

I would like the PDF to be displayed as a part of the other stuff on the page (header, footer etc.). Currently I have a solution where the PDF is shown, but on the entire page.

Has anybody done this, if yes then how?

like image 406
Peter Avatar asked Jun 22 '11 12:06

Peter


People also ask

How do I see part of a PDF?

Some PDF files contain a table of contents, which lets you quickly jump to sections within a document. To view the table of contents, Choose View > Show Contents Pane, and click the TOC button or choose View > Table Of Contents.

Can you split view a PDF?

Open a pdf file and click 'View' on the main menu > Select 'Split View'. Open the files in two tabs and click the area between the tabs. Click the View settings button on the top toolbar. Drag and drop one tab over another one to enable the split mode.

How do I change page view in PDF?

To resize the page to fit entirely in the document pane, choose View > Zoom > Zoom To Fit Page. To resize the page to fit the width of the window, choose View > Zoom > Fit Width. Part of the page may be out of view. To resize the page to fit the height of the window, choose View > Zoom > Fit Height.


1 Answers

Why don't you try using iframe like this :

<iframe src="even file stream action url"></iframe> 

I suggest to use object tag if it's possible, use iframe just for testing.

If you want to render PDF as part of the page as you just did

src='<% Html.RenderAction("GetPDF"); %>'

Then this is your option

If you need complete control over PDF content using CSS or whatsoever, like Google books and so on, then you need tools that help you to convert each requested page of PDF to Plain Text, HTML or even image. tools like PDFsharp. Search Google For Tools

If you want display PDF as part of the page then this is what you have to do

ASPX: src="<%= Url.Action("GetPDF") %>" Razor: src="@Url.Action("GetPDF")" 

And final answer could be

<object data="<%= Url.Action("GetPDF") %>" type="application/pdf" width="300" height="200">     alt : <a href="data/test.pdf">test.pdf</a> </object> 

And in the case that you want to return PDF as Stream then you need

public FileStreamResult GetPDF() {     FileStream fs = new FileStream("c:\\PeterPDF2.pdf", FileMode.Open, FileAccess.Read);     return File(fs, "application/pdf"); } 
like image 66
Beygi Avatar answered Oct 14 '22 08:10

Beygi