📚
note
Blog
  • Initial page
  • JS-notes
    • 使用浏览器书签执行js代码
    • JSON.stringify的小技巧
    • Fisher–Yates shuffle洗牌算法
    • 打印页面
  • Web-notes
    • 在网页中引入在线字体
  • Uniapp-notes
    • swiper-item高度自适应
    • 微信小程序的图片预览兼容性处理
  • VUE-notes
    • vue-note
    • vue3-note
  • VPS-notes
    • CentOs7笔记
    • ssh小记
    • Ubuntu笔记
    • vps安全相关
    • [Google Drive笔记](VPS-notes/Google Drive笔记.md)
  • TypeScript-notes
    • ts热编译项目
    • TypeScript笔记
    • js项目转ts
  • Python-notes
    • Python爬虫笔记
    • Python笔记
  • PHP-notes
    • php笔记
    • php+redis
    • php-codeIgniter
    • php抽奖算法
    • Laravel笔记
  • Mobile-notes
    • 移动端常用样式及兼容相关
  • Linux-notes
    • linux常用指令
  • Game-notes
    • Minecraft-server
  • TelegramBot-notes
    • tg-bot小记
  • Windows-notes
    • window-note
    • node-note
    • WSL-note
  • RaspberryPi-notes
    • RaspberryPi-note
    • 其他玩法
    • Openwrt
    • Ubuntu安装指南
  • Phone-notes
    • ZenFone6-note
  • Cocos-notes
    • Cocos-note
  • Network-notes
    • 单线复用
  • Other-notes
    • 国际化地域标识码
Powered by GitBook
On this page

Was this helpful?

  1. JS-notes

打印页面

print-js库可以通过设置style参数来指定打印时的样式。我们可以通过设置一个@page媒体查询,来控制是否打印页眉和页脚。

例如,我们可以在样式中添加以下代码:

@media print {
  /* 不打印页眉和页脚 */
  @page {
    margin-top: 0;
    margin-bottom: 0;
  }
}

然后在调用printJS函数时,将上述样式作为style参数传递进去即可,例如:

printJS({
  printable: 'print-content',
  type: 'html',
  style: `
    @media print {
      @page {
        margin-top: 0;
        margin-bottom: 0;
      }
    }
  `
});

上述代码中,我们将@page查询的样式作为style参数传递给了printJS函数,这样在打印时就会自动隐藏页眉和页脚了。

Last updated 2 years ago

Was this helpful?