csdn打印文章代码

    科技2022-07-13  134

    原文链接 https://blog.csdn.net/p1279030826/article/details/106602341

    该方法在 文章直接打印,或者保存PDF(去掉多余内容)上改进而来。

    一、功能及修改方法

    使用方法:按“F12”进入开发者工具,将以下js复制到 console,回车即可一键打印。 

    功能:

    1、自动“展开阅读全文”2、删除顶栏、侧栏、相关文章展示、浏览信息、广告、点赞等多余信息。真正的全清爽模式。3、自动输出打印预览、 (function(){ 'use strict'; var articleBox = $("div.article_content"); articleBox.removeAttr("style"); $("#btn-readmore").parent().remove(); $("#side").remove(); $("#comment_title, #comment_list, #comment_bar, #comment_form, .announce, #ad_cen, #ad_bot").remove(); $(".nav_top_2011, #header, #navigator").remove(); $(".csdn-side-toolbar,.template-box,.reward-user-box").remove(); $(".p4course_target, .comment-box, .recommend-box, #csdn-toolbar, #tool-box,#dmp_ad_58, .more-toolbox, .article-info-box, .btn-readmore, .pub-footer-new").remove(); $("aside").remove(); $(".tool-box").remove(); $("main").css('display','content'); $("main").css('float','left'); $("#mainBox").css('width','100%'); $(".main_father.clearfix.d-flex.justify-content-center").css("width","100%"); window.print(); })();

    二、其他问题

    1、保存为PDF。将打印机改成“另存为PDF”即可。

     

    2、更多设置。

    (1)有的文章页边缘的字会被剪切掉一部分。

    “边距”选择“无”即可解决。使用缩放(例如设置“80%”),把整体缩小就不会超过页面了。

    (2)可以关闭页眉页脚等。

     

    三、优化部分

    此方法增加了修改删除以下信息,真正的全清爽打印输出:

    (1)自动“展开阅读全文”,自动打印全文。

    (2)新版整体页面会右移的问题。

    (3)文章头部的浏览信息:

    (4)文章底部的点赞信息,底部的广告信息: 

    (4)文章右边的“举报置顶”框 。

    ============================20200906更新=================================

    (5)底部的信息栏

     

    参考链接:阅读

    Processed: 0.016, SQL: 8