ReLaXed
ReLaXed copied to clipboard
How to remove document margin?
I'm trying to remove document margin, so I can paint/handle it myself accordingly to the page I'm on. But it seems the only way to do it is adding negative margin to @page
as margin: 0mm;
doesn't works at all.
How can I fully remove the document margin?
I just figured that body { margin: 0 }
does the trick.
However, the generated PDF seems to keep a white stripe at the right side. Any ideas how to get rid of that?

html { margin: 0; padding: 0}
?
It doesn't seem to fix the slim white strip on the right side (see picture in my last comment). Perhaps a macOS bug?
Do you have a example html document for us which we can use to reproduce / test this?
Yes. You can check the files I've used below:
book.pug
#cover
h1.title Hello
style
include:scss theme.scss
theme.scss
@import 'variables';
@page {
margin: 0;
size: $page_width $page_height;
-relaxed-page-width: $page_width;
-relaxed-page-height: $page_height;
}
html, body {
margin: 0;
width: $page_width;
height: $page_height;
font-family: $font-family;
}
#cover {
width: $page_width;
height: $page_height;
background: $color-blue;
color: #fff;
padding: 10mm;
}
variables.scss
$color-blue: #233142;
$color-gold: #FCD08A;
$color-gold-dark: #6F483F;
$font-family: serif;
// A4
$page_width: 210mm;
$page_height: 297mm;
another approach is: when you try this example, do you see a margin on the left ?
any news ? I can't reproduce this.
@Zulko: when you try this example, do you see a margin on the left ?
Nope. But as soon as I change the size to A4 (210mm x 297mm) the white stripe appears:
@page {
size: 210mm 297mm;
-relaxed-page-width: 210mm;
-relaxed-page-height: 297mm;
margin: 0;
padding: 0;
}
PDF (check right-side for the white stripe):
Interesting, might be a float precision. For A4 pages it should be sufficient to not give any size parameters (remove size
and -relaxed-
parameters) since A4 is the default. Maybe it will work better.
Has there been any updates on the right side white stripe issue? Just betting on A4 working well because it's the default doesn't solve my use case unfortunately.
No matter the parameters, nothing can prevent the white strip to appear up, right, down. Here's what I have tried:
@page {
// default
}
@page {
margin: 0px 0px 0px 0px;
}
@page {
-relaxed-page-size: A4;
size: A4;
}
@page {
-relaxed-page-width: 210mm;
-relaxed-page-height: 297mm;
size: 210mm 297mm;
}
@page {
-relaxed-page-width: 210mm;
-relaxed-page-height: 297mm;
-relaxed-page-size: A4;
size: A4;
margin: 0px 0px 0px 0px;
}
@page {
-relaxed-page-width: 210mm;
-relaxed-page-height: 297mm;
size: 210mm 297mm;
margin: 0px 0px 0px 0px;
}
The best I can do is 21,01 × 29,71 cm instead of 210 mm × 297 mm.
My two cents, @Zulko is right about the float precision.