PDF is displayed as an empty white box

I have a project called "Project" and the PDF file is "file.pdf" located at Project/app/assets/file.pdf. I want to make a PDF on a page called "file.html" located at Project/app/views/static/file.html.

I wrote the following code, but everything that is displayed is an empty white box.

<embed src="../../assets/file.pdf" width="500" height="375" type='application/pdf'>

I am sure my browser cannot find the file. What can i do wrong?

UPDATE: I also tried it with the image placed in app/assets/images/Image.png, for example:

<embed src="../../assets/images/Image.png" width="500" height="375" type='image/png'>

but this is not displayed either.

UPDATE 2: Console Output:

GET "/ file" will start for 127.0.0.1 at 2016-02-21 04:48:27 -0600 Processing by StaticController # file as HTML

static/file.html.erb / (63.8ms) 200 OK 757ms (: 749.4ms | ActiveRecord: 0.0ms)

GET "/assets/application.self-e570ac372b74f676a029186250aeeba9bf7016bcd014314d103b5d18b3eb858e.css?body=1" 127.0.0.1 2016-02-21 04:48:28 -0600

GET "/assets/pdf-8f705790d319666d8f804cf8809f4d74f036483049ef8c520646d6c98ebedc5f.png" 127.0.0.1 2016-02-21 04:48:28 -0600

GET "/assets/Advanced_Reading_Sample.pdf" 127.0.0.1 2016-02-21 04:48:28 -0600

+4
5

, , . iframes URL :

<iframe src="http://www.project.com/file.pdf" style="width:100%;height:100%;"><p>Your browser does not support iframes.</p></iframe>

, , .

0

def file
  pdf_filename = File.join(Rails.root, "/assets/file.pdf")
  send_file(pdf_filename, :filename => pdf_filename, :disposition => 'inline', :type => "application/pdf")
end

file.html = > file.html.erb /_/file.html.erb, .

//pdf ().

+4

,

<iframe src="yourfile.pdf" style="width:100%; height:700px;" frameborder="0"></iframe>
+2

pdf () app/assets file.pdf, app/views/static/file.html src embed /assets/file.pdf. .

+1

,

<a href="../../assets/file.pdf" target="_blank">Click To View</a>

Mark SykOv

+1

Source: https://habr.com/ru/post/1629250/


All Articles