0

i'm using Laravel for my application, i want to show a PDF file in view

i know i have to use <embed> or <iframe> but when i use this tags, i can't see my PDF file in my view and it will download automatic, i dont want to download file, just need to see PDF file content.

this is my view :

<div class="row justify-content-center">
     <div id="detail_div_a4">                      
          <embed src="{{ $letter->image }}" type="application/pdf" width="100%" height="600px">
      </div>
</div>

src return my PDF file location in $letter->image

thank you for your helps <3

Pooriya Mostaan
  • 257
  • 1
  • 5
  • 21

1 Answers1

2

As you mentioned, you can use "iframe" to display your pdf. Here is a sample of code that should work for you.

<div class="row justify-content-center">
    <iframe src="{{ asset('folder/file_name.pdf') }}" width="50%" height="600">
            This browser does not support PDFs. Please download the PDF to view it: <a href="{{ asset('folder/file_name.pdf') }}">Download PDF</a>
    </iframe>
</div>

You can play around with the asset declaration to include your variable vs the file path. You can also test this code without your variable to see if that is causing the issue. You may also have some conflicting code in your custom div. Keep in mind you can style the pdf container in the iframe, so you may not need the div labeled "detail_div_a4". Good luck.

Here is another thread that may offer some additional support: HTML embedded PDF iframe

Nyk
  • 83
  • 9