简体   繁体   English

如何删除画布周围的灰色边框

[英]How to delete grey border around canvas

I need to export to pdf file some fragment of html.我需要将一些 html 片段导出到 pdf 文件。 I use for that html2canvas and pdfjs.我用于 html2canvas 和 pdfjs。 But there is added some grey border around this fragment但是在这个片段周围添加了一些灰色边框

Here is test html fragment:这是测试 html 片段:

<div class="col-md-12 white-bg box-shadow margb0" id="test">
     <div class="col-md-12 paddl0 paddr0 margt0 margb10">
          <h4 class="paddb10 margt20 margb10 border-bottom-sc">
              Some information out here
          </h4>
     </div>
</div>

And css for it (col-md-12 is from bootstrap.min.css):和它的 css(col-md-12 来自 bootstrap.min.css):

.white-bg { background: #ffffff; }
.margb0 {margin-bottom: 0px !important;}
.margt0 {margin-top: 0px !important;}
.margb10 {margin-bottom: 10px;}
.margt20 { margin-top: 20px;}
.paddl0 {padding-left: 0px !important;}
.paddr0 {padding-right: 0px !important;}
.paddb10 { padding-bottom: 10px;}
.border-bottom-sc {border-bottom: 1px solid #424343;}

In Chrome it looks like this:在 Chrome 中,它看起来像这样: 在此处输入图片说明

Here is how I do this in js:这是我在 js 中执行此操作的方法:

var pdf = new jsPDF('p', 'pt', 'a4', true);
var content = document.getElementById('test');
html2canvas(content, { background: "white" },
                         { scrollX: 0, scrollY: 0 }).then(function (canvas) {
    var srcImg  = canvas;
    var sX      = 0;
    var sY      = 0;
    var sWidth  = 1150;
    var sHeight = 1350;
    var dX      = 25;
    var dY      = 25;
    var dWidth  = 1150;
    var dHeight = 1350;
    window.onePageCanvas = document.createElement("canvas");
    onePageCanvas.setAttribute('width', 1150);
    onePageCanvas.setAttribute('height', 1350);
    var ctx = onePageCanvas.getContext('2d');
    ctx.drawImage(srcImg, sX, sY, sWidth, sHeight, dX, dY, dWidth, dHeight);
    var canvasDataURL = onePageCanvas.toDataURL("image/png", 1.0);

    var width         = onePageCanvas.width;
    var height        = onePageCanvas.height;
    pdf.addImage(canvasDataURL, 'jpg', 0, 0, (width*.51), (height*.51));
    pdf.save('test.pdf');
});

And here is how this fragment looks in document:这是这个片段在文档中的样子: 在此处输入图片说明

Demo: https://jsfiddle.net/x6yg1kbm/2/演示: https : //jsfiddle.net/x6yg1kbm/2/

So my question: how to not show this border during pdf export?所以我的问题是:如何在 pdf 导出期间不显示此边框?

It is needed just to delete .white-bg { background: #ffffff;只需要删除 .white-bg { background: #ffffff; } css property css 属性

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM