How to change exported pdf margin colors

I set my background color to #Fffcf8 in my userstyles.css in the .body block, but this causes ugly white margins in the pdf:


How do I fix this?

Sorry to dig this old thread up, but have the same quesiton and haven't yet been able to find an answer to it on the forums.

From Adding header and footers - #6 by dpoulton I was able to add into my userstyle.css this code

.exported-note {
	background-color: darkgrey !important;
}

It seems that what you are seeing are the page margins. What you can do with margins using css seems to be quite limited.

All I have found is that if you set the margins to 0 for the page and then add a background colour to the body it does fill the page. However you have no margins and it looks rather bad. So you can then add the margins back using the body tag.

(I have wrapped the css in @media print so that the css only applies when printed.)

@media print {
    @page {
        margin: 0cm;
        /* zero size margins for the page*/
    }
    body {
        margin: 2cm 2cm 2cm 3cm;
        /* adds margins for the body - margin order top, right, bottom, left */
        background-color: darkgrey;
    }
}

So this note

produces this pdf

I only did enough testing to get this to work for this note so there is a possibility it may screw things up with other notes. Consider it something to work from :slight_smile:

As always, if anyone knows a better, more elegant way of doing this please feel free to comment!

3 Likes

This is amazing for me, who knows nothing about coding.
Can you please make the exported pdf with bookmark included?
Can you also please make the exported pdf with page number/total pages appear at the botom?
I seem to have requested too much :grinning: I am currently using typora to export to pdf, but I failed in change the background colour.

Thank you very much in advance