0

I'm trying to create a pdf which uses css to completely style the background-color. I can't seem to get the css to give it a full background.

My CSS:

@media print {
    @page {
        background: pink !important; // not showing
         margin: 0 !important;
        padding: 0 !important;
        -webkit-print-color-adjust: exact !important;
    }
}

html, body {
    box-sizing: border-box;
    min-height: 100%;
    min-width: 100%;
    height: 100%;
    width: 100%;
    font-family: Montserrat;
    background-color: #20333e;
    color: rgba(255, 255, 255, 0.87);
    border: 2px solid red;
}

Which outputs:

enter image description here

I already have the markdown data in json format and am using the package markdown-pdf to create the pdf.

import * as markdownpdf from 'markdown-pdf';

markdownpdf({cssPath: './path/to/my/ebook.css'}).from.string('# CSS Not Full Background').to("./document.pdf", function () {
    console.log("done");
});

How can I style my pdf to have a full background?

Jonathan002
  • 9,639
  • 8
  • 37
  • 58

2 Answers2

1

try adding top, bottom, margin values to body,html element

body,html{
top: 0, bottom: 10, left: 0, right: 0

JustCode
  • 661
  • 1
  • 8
  • 19
0

replace page{...} inside @media print with

body {
        background-color: pink; 
    }
  • I've tried replacing the @page with body, and the results are still the same. How is it different from selecting the body tag outside @page? – Jonathan002 May 29 '18 at 07:54