Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

printing - How to set Safari print margins via CSS to print borderless

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

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

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;
}

?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is 3 things to take in consideration:

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

    @page {
    margin: 0cm !important;
    }
    

    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).

  2. 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).

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...