为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

BIG阳 2023-09-04 16:25:57
我需要将 html 的一些片段导出到 pdf 文件。我用的是 html2canvas 和 pdfjs。但是这个片段周围添加了一些灰色边框这是测试 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>以及它的 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;}在 Chrome 中它看起来像这样:这是我在 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');});以下是该片段在文档中的外观:演示: https: //jsfiddle.net/x6yg1kbm/2/所以我的问题:如何在 pdf 导出过程中不显示此边框?
查看完整描述

1 回答

?
慕标琳琳

TA贡献1830条经验 获得超9个赞

只需删除 .white-bg { background: #ffffff; } CSS 属性



查看完整回答
反对 回复 2023-09-04
  • 1 回答
  • 0 关注
  • 85 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信