嵌入PDF一个ASP.NET页面上 [英] Embed a PDF on a ASP.NET page

查看:269
本文介绍了嵌入PDF一个ASP.NET页面上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着去嵌入到我的页面的PDF,但PDF只是不加载。我检查了这是正确的文件路径。

Im trying to embed a PDF on to my page, but the PDF just does not load. I have checked the file path which is correct.

当第一次加载页面,我得到了一个空白的灰色领域的嵌入,但是当我点击嵌入,我得到这个(其中保持这样的):

When the page first loads, I get a blank grey embed field, however when I click on the embed, I get this (which stays like this):

<script>
    var selected_doc_ref = "";
    function getPDF() {

        //selected_doc_ref = "395";

        var DV_pdf_path = "../../../Document_Viewer/Risk_Assessment/RISK ASSESSMENT 1024.pdf";

        var pdf = document.getElementById("pdf");
        var clone = pdf.cloneNode(true);
        clone.setAttribute('src', DV_pdf_path);
        pdf.parentNode.replaceChild(clone, pdf)
    }
</script>


<body onload="getPDF()">

<embed id="pdf" style="border-radius: 10px;position: relative;top:0;right:0;left:0;bottom:0;width:100%;height:620px;"/>

任何想法,我错了?

Any ideas where I am going wrong?

感谢

推荐答案

由于浏览器不刷新嵌入标签,当你添加的src 属性添加到&LT;&嵌入GT; 页面加载后的标签,你有2个选项:

As the browser does not refresh the embed tag when you add the src attribute to the <embed> tag after page load you have 2 options:


  • 设置的&LT src属性;嵌入&GT; 标记直接,因此可从一开始。你可以设置的src 通过背后或作为一个静态值code。

  • 在您的JavaScript,加上整个&LT;嵌入&GT; getPDF内标签()功能而不是仅仅属性的src

  • Set the src attribute on the <embed> tag directly so it is available from the beginning on. You could set the src through code behind or as a static value.
  • In your javascript, add the whole <embed> tag inside the getPDF() function instead of just the attribute src:

var e = document.createElement('embed');
e.attributes['src'] = src;
e.attributes['style'] = "border-radius: 10px;position: relative;top:0;right:0;left:0;bottom:0;width:100%;height:620px;";
document.getElementById("pdfContainer").appendChild(e);


假设你有,你要放置&LT ID为pdfContainer一个元素;嵌入方式&gt;在标记

Assuming that you have a element with id "pdfContainer" where you want to place the <embed> tag inside.

这篇关于嵌入PDF一个ASP.NET页面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆