如何通过 CSS 设置 Safari 打印边距以进行无边框打印 [英] How to set Safari print margins via CSS to print borderless

查看:72
本文介绍了如何通过 CSS 设置 Safari 打印边距以进行无边框打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Safari 中将网页打印为 PDF,没有任何边距.在打印对话框中将页面大小设置为A4 无边框".

I want to print a webpage to PDF without any margins in Safari. Page size is set to 'A4 borderless' in the print dialogue.

无论我做什么,OSX 上的 Safari 都会在我的 HTML 周围添加额外的边距.检查打印背景"以了解我的意思.

Whatever I seem to do, Safari on OSX is adding an extra margin around my HTML. Check 'print backgrounds' to see what I mean.

显然@page-rule 对 Safari 没有影响,但还有其他方法吗?

Clearly the @page-rule has no effect for Safari, but are there any other ways?

http://jsfiddle.net/willemvb/psFHC/

@page {
  size: 21cm 29.7cm;   /*A4*/
  margin: 0; /*webkit says no*/
}

html{
    margin: 0;
    padding: 0;
    width: 100%;
}

body {
    margin: 0;
    padding: 0;
    font-family: sans-serif;
    width: 100%; 
    background: #eee;
}

推荐答案

需要考虑 3 件事:

  1. 页面规则的边距,不幸的是

  1. The margin of the page's rule, unfortunately

@page {
margin: 0cm !important;
}

对 Safari 6 没有影响,它在 Chrome 23 中的影响.据我所知,只要 Safari 不支持这一点,就没有解决方案(它似乎固定在 10 毫米左右).

Has no effect on Safari 6, where it does in Chrome 23. As I know, as long as Safari is not supporting this, there is no solution (it seems to be fixed to around 10mm).

页面设置见此处 您可能必须在打印..."菜单面板中定义自定义的纸张尺寸"而没有任何边距(顺便说一句,您已经这样做了).

The page setting as seen here you might have to define a custom "Paper Size" in the "Print…" menu panel without any margin (you did it already btw).

显然是为了照顾其他内部内容 html、body……不要有任何边距.

Obviously to take care of the other inner content html, body… not to have any margin.

这篇关于如何通过 CSS 设置 Safari 打印边距以进行无边框打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆