我一直在想办法如何提取当前页面元素和内容以便可以使用它,我可以将PDF作为输出。目前我的reports2.php包含:
<body style="padding: 10px; font-size: 10pt;" onLoad="generateReport()">
<hr>
<div backcolor="#FEFEFE" backimg="./res/bas_page.png" backimgx="center" backimgy="bottom" backimgw="100%" backtop="0" backbottom="30mm" footer="date;heure;page" style="font-size: 12pt">
<hr>
<table cellspacing="0" style="width: 100%; text-align: center; font-size: 14px">
<tbody>
<tr>
<td style="width: 75%;">
<h1> Advanced World Solutions, Inc.</h1>
<h2> Actual Physical Inventory of MIS Hardware Resources </h2>
</td>
<td style="width: 25%; color: #444444;">
<img style="width: 100%;" src="C:\wamp\www\test\images\logo.jpg"><br>
</td>
</tr>
</tbody>
</table>
<hr>
<table id="search" border="1" style="width:100%">
</table>
</div>
<hr>
</body>
我想要的是在运行此脚本后,页面内容和脚本输出将创建一个新的.php或.html文件,然后我将其转换为PDF。
function generateReport()
{
var xhr;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
var data = "asid=0"
xhr.open("POST", "report/genrep.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(data);
xhr.onreadystatechange = display_data;
function display_data()
{
if (xhr.readyState == 4)
{
if (xhr.status == 200)
{
document.getElementById("search").innerHTML = xhr.responseText;
}
else
{
alert('There was a problem with the request.');
}
}
}
}
我尝试过使用
file_put_contents('test.php', ob_get_contents());
但它返回没有脚本输出的页面。
答案 0 :(得分:0)
也许这会帮助您获取页面内容(仅限于正文内部)..:D
function produce(){
var data = "<textarea rows='50' cols='50' style='width:100%;'>"+document.body.innerHTML+"</textarea>";
document.body.innerHTML = data+document.body.innerHTML;
}
<!-- Any contents as you like -->
..
..
<button id="btn" onclick="produce();">Click to produce result</button>