简体   繁体   English

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

[英]Make a PDF from a HTML page in landscape format

I need to make a PDF 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>

I found it out.我发现了。 It is so simple :) The first Param is for landscape in jsPDF() which is l for landscape.很简单:) 第一个参数是jsPDF()中的风景, l代表风景。

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

app.component.ts 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应用程序组件.html

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

use the below code for portrait mode.使用以下代码进行纵向模式。

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

Configure dimension while adding the image or data for pdf.在为 pdf 添加图像或数据时配置尺寸。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM