Blues Clues
Blues Clues

Reputation: 1858

PDF as blank page in HTML

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.

Solution:

option1:

Renamed my file that has # sign. And everything should work fine.

option2:

Use urlencode if needed.

Upvotes: 6

Views: 6186

Answers (4)

Suneel Kumar
Suneel Kumar

Reputation: 5831

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>

Upvotes: 0

ganesh avhad
ganesh avhad

Reputation: 94

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

Upvotes: 6

Alexander Cardosi
Alexander Cardosi

Reputation: 127

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

Upvotes: 0

SigaVPN
SigaVPN

Reputation: 11

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.

Upvotes: 1

Related Questions