Reputation: 102
I need to export to pdf file some fragment of html. I use for that html2canvas and pdfjs. But there is added some grey border around this fragment
Here is test html fragment:
<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):
.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;}
Here is how I do this in 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/
So my question: how to not show this border during pdf export?
Upvotes: 0
Views: 2981
Reputation: 102
It is needed just to delete .white-bg { background: #ffffff; } css property
Upvotes: 1