从横向格式的HTML页面制作PDF


Make a PDF from a HTML page in landscape format

我需要制作一个横向格式的PDF。

<script type="text/javascript">
    $(function () {
        var doc = new jsPDF();
        var specialElementHandlers = {
            '#editor': function (element, renderer) {
                return true;
            }
        };
        $('#cmd').click(function () {
            doc.fromHTML($('#content').html(), 15, 15, {
                'width': 170,
                'elementHandlers': specialElementHandlers
            });
            doc.save('sample-file.pdf');
        });
    });
</script>

我发现了。很简单:)第一个Param用于jsPDF()中的景观,这就是l用于景观。

var pdf = new jsPDF('l', 'mm', [297, 210]); //The first Param is for landscape or portrait

app.component.ts

@ViewChild('pdfContent') pdfContent: ElementRef;
 async capture() {
// var doc = new jspdf("p", "pt", "a4");  // For Portrait
var doc = new jspdf('l', 'pt', "a4");  // For landscape
//code

})

app.component.html

 <div class="col-md-12" class="tablejoin" #pdfContent id = 
 "entireTable" >
<table> .. </table>
</div>

使用以下代码进行人像模式。

    var doc = new jsPDF('l', 'mm', 'a4'); // optional parameters
    doc.addImage(img/imgdata, 'PNG', 10, 10, 280, 180);
    doc.save("new.pdf");

在为pdf添加图像或数据时配置尺寸。