0
我想將html轉換爲pdf。是否有任何自定義指令,我可以使用。我也嘗試從npm站點使用angular-save-html-to-pdf,但使用時出現一些錯誤。 是否有任何其他方式將HTML轉換爲角js中的CSS。Html To PDF轉換角js
我想將html轉換爲pdf。是否有任何自定義指令,我可以使用。我也嘗試從npm站點使用angular-save-html-to-pdf,但使用時出現一些錯誤。 是否有任何其他方式將HTML轉換爲角js中的CSS。Html To PDF轉換角js
有jsPDF庫,支持這一點。它使用html2canvas。他們的網站上有一個demo。
var doc = new jsPDF();
// We'll make our own renderer to skip this editor
var specialElementHandlers = {
'#editor': function(element, renderer){
return true;
}
};
// All units are in the set measurement for the document
// This can be changed to "pt" (points), "mm" (Default), "cm", "in"
doc.fromHTML($('body').get(0), 15, 15, {
'width': 170,
'elementHandlers': specialElementHandlers
});
您可以使用帶有angularjs的PdfMake
。
我用pdfmake做了一個示例。
var docDefinition = {
content: [
{
text: 'Criketers and scores'
},
{
style: 'demoTable',
table: {
widths: ['*', '*', '*'],
body: [
[{text: 'Name', style: 'header'}, {text: 'Matches', style: 'header'},
{text: 'Score', style: 'header'}
],
['Sachin', '344', '52'],
['Sanga', '320', '89'],
['Ponting', '300', '68']
]
}
}
],
styles: {
header: {
bold: true,
color: '#000',
fontSize: 11
},
demoTable: {
color: '#666',
fontSize: 10
}
}
};
$scope.openPdf = function() {
pdfMake.createPdf(docDefinition).open();
};
$scope.downloadPdf = function() {
pdfMake.createPdf(docDefinition).download();
};