Wednesday, January 31, 2018

PDF as blank page in HTML

Leave a Comment

My problem is, everything is fine opening PDFs using my browsers, until I uploaded a pdf with a form inside. Then, if I embed it, it returns a blank page. But the other pdfs with forms open normally. Please see my code below:

<object data="{{ asset($test->file_path) }}" type="application/pdf" width="100%" height="100%">     <embed src="{{ asset($test->file_path) }}" type='application/pdf'>     <center>         <a href="{{ route('download.test', ['id' => $test->id]) }}" class="btn btn-primary">Please click here to view</a>     </center> </object> 

Note: I've also tried to use <iframe> but still returns blank page.

4 Answers

Answers 1

<a href="{{ route('download.test', ['id' => $test->id] ,['target'=>'_blank']) }}" class="btn btn-primary">Please click here to view</a> 

Answers 2

It's late, and I'm tired, so apologies if I misread the question.

I noticed that the PDF is hosted on a site that doesn't support HTTPS. It showed a blank page if it was embedded on a site using HTTPS, but worked fine when it was using HTTP.

I think you need to either move the PDF to a site that supports HTTPS or make the site hosting the PDF start using HTTPS.

Answers 3

Consider using Objects and Iframes (Rather than Object and Embed)

Something like this should work for you:

<object data="http://foersom.com/net/HowTo/data/OoPdfFormExample.pdf" type="application/pdf" width="100%" height="100%">     <iframe src="http://foersom.com/net/HowTo/data/OoPdfFormExample.pdf" width="100%" height="100%" style="border: none;">         This browser does not support PDFs. Please download the PDF to view it: <a href="/pdf/example.pdf">Download PDF</a>     </iframe> </object> 

This worked when I tested it locally but I can't show JSFiddle since it uses HTTPS. Also, have a look at these examples: https://pdfobject.com/static.html

Answers 4

Not sure if this will work as I am not able to test your case. You can try this, it always works for me. Try replacing http://yoursite.com/the.pdf with the correct path.

<object data="http://yoursite.com/the.pdf" type="application/pdf" width="750px" height="750px">     <embed src="http://yoursite.com/the.pdf" type="application/pdf">         <p>This browser does not support PDFs. Please download the PDF to view it: <a href="http://yoursite.com/the.pdf">Download PDF</a>.</p>     </embed> </object> 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment