简体   繁体   English

如何为PDF设置样式以使其具有完整背景?

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

I'm trying to create a pdf which uses css to completely style the background-color. 我正在尝试创建一个使用css来完全设置背景颜色样式的pdf。 I can't seem to get the css to give it a full background. 我似乎无法让CSS为其提供完整的背景知识。

My CSS: 我的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: 哪个输出:

在此处输入图片说明

I already have the markdown data in json format and am using the package markdown-pdf to create the pdf. 我已经有json格式的markdown数据,并且正在使用markdown-pdf包创建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? 如何为PDF设置样式以使其具有完整背景?

try adding top, bottom, margin values to body,html element 尝试将top,bottom,margin值添加到body,html元素

body,html{ 身体,HTML {
top: 0, bottom: 10, left: 0, right: 0 上:0,下:10,左:0,右:0

replace page{...} inside @media print with 将@media print中的页面{...}替换为

body {
        background-color: pink; 
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我怎么能没有背景颜色扩展整个容器? - How can I not have have background color extend the full container? 如何设置高位图实体量表的样式,使其在百分比后面有背景? - How can I style my highcharts solid gauge to have a background behind the percentage? 如何让我的背景视频全屏响应? - How can I make my background video full screen in react? 我的引导页面上有视频背景-如何使其“固定”? - I have a video background on my bootstrap page - how can I make it “fixed”? 在使用phantomjs将网页呈现为pdf时,如何自动调整viewportSize以获取整个页面宽度? - While rendering webpage to pdf using phantomjs, how can I auto adjust my viewportSize to take full page width? 如何使背景图片占据整页 - how can I make the background image take the full page 如何将内容背景图像拉伸到全屏? - How can I stretch content background image to full screen? 我怎样才能设计 ckeditor5 的样式?(背景颜色和东西) - how can I style ckeditor5?( background-color and stuff ) 如何绑定:样式与对象语法和多个背景图像? - How can I bind:style with object syntax and multiple background images? 如何在嵌入式样式表中使用javascript变量作为背景? - How can I use a javascript variable as a background in an embedded style sheet?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM