【问题标题】:Embed PDF file doesnt work嵌入 PDF 文件不起作用
【发布时间】:2017-04-28 13:31:57
【问题描述】:

所以我想在我的视图中嵌入解码的 pdf 文件,但它不起作用。

我正在使用以下代码

<embed src="localhost/tmp/invoices/1481634077_tmp_pdf.pdf" width="100%" height="700" type='application/pdf'>

此代码不起作用,但如果我直接从浏览器调用文件名,我可以看到文件,如果我想从外部页面嵌入文件,它也可以工作

例子

<embed src="http://www.orimi.com/pdf-test.pdf" width="100%" height="700" type='application/pdf'>

我也尝试在线上传我的应用程序,但我遇到了同样的问题(我的域中的链接不显示 PDF-s,但我可以阅读其他链接。

我也尝试过 Iframe 和 Object 标签

感谢您的帮助

【问题讨论】:

  • 因为你缺少协议!

标签: php pdf embed


【解决方案1】:

您使用的是相对 URL。

因此,如果您页面的 URL 是 http://localhost/http://localhost/index.php,那么您在 src 属性 (localhost/tmp/invoices/1481634077_tmp_pdf.pdf) 中使用的 URL 实际上将引用 http://localhost/localhost/tmp/invoices/1481634077_tmp_pdf.pdf

这可能不是你想要的。

您可以:

  • 使用绝对 URL:http://localhost/tmp/invoices/1481634077_tmp_pdf.pdf
    (以http://开头)
    但是,如果您将网站上传到 localhost 以外的域,则必须更改它。
  • 使用正确的相对 URL:tmp/invoices/1481634077_tmp_pdf.pdf
  • 使用根相对 URL:/tmp/invoices/1481634077_tmp_pdf.pdf
    (以/ 开头)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-15
    • 2017-12-10
    • 2017-02-02
    • 2015-04-19
    • 2015-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多