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>
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>
Share
Improve this question
edited Oct 24, 2017 at 5:54
Pankaj Makwana
3,0506 gold badges32 silver badges49 bronze badges
asked Apr 19, 2016 at 13:11
L.SL.S
1411 gold badge1 silver badge9 bronze badges
2
- 1 Possible duplicate of Is it possible to save HTML page as PDF using JavaScript or jquery? – TheAlexLichter Commented Apr 19, 2016 at 13:59
- I don't understand how this can slove my Problem? There is nothing about the landscape format. – L.S Commented Apr 20, 2016 at 6:19
3 Answers
Reset to default 9I 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
app.ponent.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.ponent.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.