按F12打开控制台输入以下代码到console(控制台)
function doPrint(){
var head_str = "
var foot_str = ""; //生成尾部
var older = document.body.innerHTML;
//var new_str = document.getElementById('wrapper').innerHTML; //获取指定打印区域
var new_str = document.getElementsByClassName('blog-content-box')[0].innerHTML; //获取指定打印区域
var old_str = document.body.innerHTML; //获得原本页面的代码
document.body.innerHTML = head_str + new_str + foot_str; //构建新网页
window.print(); //打印刚才新建的网页
document.body.innerHTML = older; //将网页还原
return false;
};doPrint(); 标签:body,innerHTML,CSDN,str,new,var,PDF,document,下载 From: https://www.cnblogs.com/brickMovingWorker/p/16950524.html