Created
January 21, 2020 19:43
-
-
Save joaobibiano/ffada50d7d7cab6188614f90dc27fd79 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jsPDF from 'jspdf'; | |
import 'jspdf-autotable'; | |
const createPDF = (data) => { | |
const doc = new jsPDF({ orientation: 'landscape' }); | |
const body = data.map(item => { | |
return [ | |
item.pro_code, | |
item.pro_description, | |
item.pro_expiration ? new Date(item.pro_expiration).toLocaleDateString() : null, | |
item.pro_cost.toFixed(2), | |
item.pro_totalAmount.toFixed(2), | |
item.pro_totalValue.toFixed(2) | |
]; | |
}); | |
doc.autoTable({ | |
head: [['Código', 'Descrição', 'Vencimento', 'Custo', 'Quantidade', 'Total']], | |
body: body | |
}); | |
doc.save(`relatorio_${new Date().toLocaleString().replace(/\/+|:| /g, '_')}.pdf`); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment