Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
HTML
<iframe src="http://docs.google.com/gview?url=http://example.com/test/pdf/ex.pdf; ?>&embedded=true" style="width:608px; height:700px;" frameborder="0"></iframe>



The above iframe code, displays pdf on the browser.

But my problem is, I have uploaded the pdf to the database(BLOB) and to be able to download the pdf - the link would be something like

HTML
www.example.com/test/view.php?id=21 


and if i add above url in iframe google viewer, it never recognize is parameter.

HTML
<iframe src="http://docs.google.com/gview?url=http://example.com/test/view.php&id=21 ; ?>&embedded=true" style="width:608px; height:700px;" frameborder="0"></iframe



So what's the best way to be able to view the pdf on the browser, using same technique or something else -

The below code downloads the pdf

HTML
header("Content-type: $this->type");
header("Content-Disposition: attachment; filename=$this->name");
echo $this->content;


Is there anything i can change in this code to force it to open in the same browser instead of download?

Thanks
Posted
Comments
AndyInUK 20-Jul-12 11:58am    
No php/mysql/html guru here??

YOu shoudl search codeproject for this question.... For instance: Blend PDF with Silverlight

The solution is quite complicated though.....
 
Share this answer
 
I am interested to know about your server is it online? can I access it? or it just a local machine? if this is a local machine then it is sure that google server wont be able to get the pdf.

When a client send a request to server it does not know what is going to be replied from server. server can give some direction to client but server cant force client. Server can inform client application that it is sending a pdf. but if client application choose to open pdf file on her application or want to save on local machine then she can. But it depends whether your server is accessible to outside world or not. And whether you mention to google server to download or just to view it would download anyway in order to do processing.
 
Share this answer
 
v2
I created a (private, used by us in the timetable dept) alternative timetable viewing system for a college I worked at a couple of years back. This would display pdfs inside Iframes too. The code that I had was considerably shorter for embedding the pdf.

Basically, the JS would construct the following html for the pdf's iframe.
HTML
<iframe src="pdfTimetable.php?id=12345678&type=student" width="700px" height="500px"></iframe>


The underlying database has since been damaged, however I was able to test the code earlier this year with my android and desktop browsers, the behaviour was still the same as it was 2 years ago, when tested with Chrome, FF, IE 6,7,8.

Which browser(s) are you testing with?

Also, I think the term you're looking for is uploads. As in - "The below code downloads the pdf" --> "The below code uploads the pdf (to the client machine, from the server)"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900