如何使用 jsPDF 在 canvas 中创建边距

how to create margin in canvas using jsPDF

您好,我正在使用 jdPDF 从 html 生成 pdf,但遗憾的是我无法提供页边距。任何帮助,将不胜感激。如何使用 canvas 对象向我的页面添加边距。

这是源代码。

    $(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);
            }
        );
    //});

    })
    });

我可以得到正确的方法吗?这是有问题

的图像link

http://screencast.com/t/50UMjHImD

我花了很多时间尝试使用 jsPDF 添加边距、添加样式或制作表格。对我来说有点复杂,所以我又看了一个,发现:pdfmake。您可以毫无问题地添加边距,因为样式非常容易定义。 希望这会有所帮助,即使我没有真正回答这个问题。 问候。