Reputation: 11
Hi I'm generating pdf from html by using jdPDF, but unfortunately I'm not able to give page margin. Any help would be appreciated. How I can add margin into my page by using canvas object.
Here is source code.
$(function(){
//$("#button1").click(function(){
console.log("hey");
$( "#other" ).click(function() {
//alert("hello");
var pdf = new jsPDF('p', 'pt', 'letter');
source = $('#fromHTMLtestdiv');
var canvas = pdf.canvas;
canvas.height = 72 * 11;
canvas.width=72 * 8.5;;
// var width = 400;
document.body.style.width = 400 + 'px';
document.body.style.margin = 30 + 'px';
//source.css("border","1px solid");
html2pdf(source, pdf, function(pdf) {
//var iframe = document.createElement('iframe');
// iframe.setAttribute('style','position:absolute;right:0; top:0; bottom:0; height:100%; width:500px');
// document.body.appendChild(iframe);
// iframe.src = pdf.output('datauristring');
window.location = pdf.output('datauristring');
//var div = document.createElement('pre');
//div.innerText=pdf.output();
//document.body.appendChild(div);
}
);
//});
})
});
May I getting right approach? here is the link of image with problem
http://screencast.com/t/50UMjHImD
Upvotes: 0
Views: 5573
Reputation: 38
I took a lot of time trying to add margin, add styles or making tables with jsPDF. To me it's a bit complicated so I looked after another one and I found : pdfmake. You will have no problem to add margin since the styles are really easy to define. Hope this will help even if i'm not really answering the question. Regards.
Upvotes: 1