Skip to content

Instantly share code, notes, and snippets.

@joaobibiano
Created January 21, 2020 19:43
Show Gist options
  • Save joaobibiano/ffada50d7d7cab6188614f90dc27fd79 to your computer and use it in GitHub Desktop.
Save joaobibiano/ffada50d7d7cab6188614f90dc27fd79 to your computer and use it in GitHub Desktop.
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