4

I need to make a PDF in landscape format.

<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>
Pankaj Makwana
  • 3,030
  • 6
  • 31
  • 47
L.S
  • 141
  • 1
  • 1
  • 9
  • 1
    Possible duplicate of [Is it possible to save HTML page as PDF using JavaScript or jquery?](http://stackoverflow.com/questions/6896592/is-it-possible-to-save-html-page-as-pdf-using-javascript-or-jquery) – manniL Apr 19 '16 at 13:59
  • I don't understand how this can slove my Problem? There is nothing about the landscape format. – L.S Apr 20 '16 at 06:19

3 Answers3

9

I found it out. It is so simple :) The first Param is for landscape in jsPDF() which is l for landscape.

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

Pankaj Makwana
  • 3,030
  • 6
  • 31
  • 47
L.S
  • 141
  • 1
  • 1
  • 9
1

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>
Techdive
  • 997
  • 3
  • 24
  • 49
  • When answering questions on Stack Overflow, it's important to explain the answer so that people can learn from it. It's also important to answer directly. Your answer here adds a lot of unnecessary code which can be confusing, preventing people from learning from you. – Brad Sep 24 '19 at 06:34
  • Okay. Thanks for the suggestion. I shall correct it. – Techdive Sep 24 '19 at 06:39
1

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.