Sun*_*arg 11 html javascript pdf angularjs jspdf
我正在使用jspdf.debug.js从html页面导出pdf数据.这是我正在使用的控制器的功能.我创建了一个字符串作为我要导出的html表.
$scope.exportReport = function (fileName, fileType) {
objReport.count = 0; // for getting all records
ReportService.getSaleDetail(objReport).then(function (result) {
var strTable = "<table id='tableReport'><tr><td style='width:400px'>Date</td><td style='width:50px'>Order Id</td><td style='width:130px'>Product</td><td style='width:120px'>Gorss Price</td><td style='width:160px'>Currency</td><td style='width:50px'>Order Status</td><td style='width:150px'>Assigned To</td><td style='width:150px'>Assigned User Email</td><td style='width:150px'>Country</td></tr>";
var strRow = '';
if (result.data.totalRecords > 0) {
var totalRecords = parseInt(result.data.totalRecords);
var saleDataJson = result.data.saleDetail;
for (var i = 0; i < totalRecords; i++) {
strRow = '<tr><td>' + saleDataJson[i].date + '</td>' + '<td>' + saleDataJson[i].orderId + '</td>' + '<td>' + saleDataJson[i].product + '</td>' + '<td>' + (1 * saleDataJson[i].grossPrice).toFixed(2) + '</td>' + '<td>' + saleDataJson[i].currency + '</td>' + '<td>' + saleDataJson[i].orderStatus + '</td>' + '<td>' + saleDataJson[i].assignedTo + '</td><td>' + saleDataJson[i].assignedUserEmail + '</td><td>' + saleDataJson[i].country + '</td></tr>';
strTable += strRow;
}
strTable += "</table>";
}
if (fileType === 'pdf') {
var pdf = new jsPDF('p', 'pt', 'letter') // jsPDF(orientation, unit, format)
, source = strTable
, specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'#bypassme': function (element, renderer) {
// true = "handled elsewhere, bypass text extraction"
return true;
}
},
margins = {
top: 30,
bottom: 40,
left: 35,
width: 600
};
pdf.setFontSize(12);
pdf.text(200, 30, fileName);
pdf.setFontSize(8);
pdf.setFontStyle('italic');
pdf.text(420, 35, 'Total Records : ' + totalRecords);
pdf.fromHTML(
source // HTML string or DOM elem ref.
, margins.left // x coord
, margins.top // y coord
, {
'width': margins.width // max width of content on PDF
, 'elementHandlers': specialElementHandlers
},
function (dispose) {
// dispose: object with X, Y of the last line add to the PDF
// this allow the insertion of new lines after html
pdf.save(fileName + '.pdf');
},
margins
)
}
});
};
Run Code Online (Sandbox Code Playgroud)
这个方法就像这样导出pdf文件
我尝试了唐的风格,但它不工作如何降低字体大小,以便我可以正确导出PDF文件?
小智 8
pdf.setFont("helvetica");
pdf.setFontType("bold");
pdf.setFontSize(9);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24741 次 |
| 最近记录: |