【发布时间】:2016-03-22 06:19:06
【问题描述】:
如何在从远程位置获取的网页上显示 pdf 文件或 doc 文件。 例如 - 从服务器到客户端
<!DOCTYPE html> //specifying the html version
<html> //a html file will show on to the remote browser
<head>// head element of an html
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script>
function addMoreInputType() //custom function when a button is clicked
{ // opening of a function
var ip=document.getElementById("p1"); // id of a <p>tag
var cele=document.createElement("embed");//creating a new html element
cele.setAttribute("src","1.pdf"); //setting an attribute named src and 1.pdf is the pdf file on the server which i wanted to show on the client browser
cele.setAttribute("width","600px"); //setting an attribute named width to diplay
cele.setAttribute("height","500px");//setting an attribute named height
cele.setAttribute("alt","pdf");
cele.setAttribute("pluginspace","http://www.adobe.com/products/acrobat/readstep2 .html");// that is the plugin
cele.setAttribute("internalinstanceid","14");// that is setting the attribute for the new html element
ip.appendChild(cele);// finally appending it to p tag child
} //closing of a function
</script> // ending of the script tag
</head> //end of the head tag
<body> // the content to be displayed on the client browser
<input type="button" value=" clickme " onclick="addMoreInputType()">Button click// a button which on clicking will invoke the addM....() so that they will request to server to give the pdf file and show onto browser's webpage area
<p id="p1"></p> // p tag having id p1
</body>//end of body of html
</html>//end of html file
【问题讨论】:
-
您只需要正确的库即可阅读其内容。在那里你可以显示它。对于 pdf,有 itext 库。
-
你能给我提供更新的解决方案吗
-
使用 ajax 代码,因为我正在使用 ajax
标签: javascript html client-server webpage