ReLaXed icon indicating copy to clipboard operation
ReLaXed copied to clipboard

How to remove document margin?

Open kazzkiq opened this issue 6 years ago • 11 comments

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?

captura de tela 2018-05-27 as 02 06 06

kazzkiq avatar May 27 '18 05:05 kazzkiq

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?

captura de tela 2018-05-27 as 02 13 08

kazzkiq avatar May 27 '18 05:05 kazzkiq

html { margin: 0; padding: 0} ?

Zulko avatar May 27 '18 09:05 Zulko

It doesn't seem to fix the slim white strip on the right side (see picture in my last comment). Perhaps a macOS bug?

kazzkiq avatar May 27 '18 15:05 kazzkiq

Do you have a example html document for us which we can use to reproduce / test this?

DanielRuf avatar May 27 '18 17:05 DanielRuf

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;

kazzkiq avatar May 27 '18 18:05 kazzkiq

another approach is: when you try this example, do you see a margin on the left ?

Zulko avatar May 28 '18 21:05 Zulko

any news ? I can't reproduce this.

Zulko avatar Jun 02 '18 11:06 Zulko

@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):

captura de tela 2018-06-02 as 22 59 02

kazzkiq avatar Jun 03 '18 02:06 kazzkiq

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.

Zulko avatar Jun 16 '18 09:06 Zulko

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.

goshatch avatar Oct 03 '19 13:10 goshatch

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.

fro avatar Dec 12 '19 19:12 fro