Я новичок в изучении angular и jspdf. Я столкнулся с проблемой при использовании автозапуска jspdf для печати небольших страниц (термальная страница). Я перепробовал много вещей, но, похоже, ничего не получилось. Табель не соответствует странице.
Это мой код:
onThermalPrint(){
let i = 1;
let products = [];
for (let invProduct of this.invoiceProducts) {
let row = [];
row.push(i++);
row.push(invProduct.product.name);
// row.push(invProduct.quantity);
// row.push(invProduct.retailPrice);
// row.push(invProduct.discount);
row.push((invProduct.retailPrice - invProduct.discount) * invProduct.quantity);
products.push(row);
}
let pdf = new jspdf('p', 'mm', [80,57]);
let invoice_line_1;
let invoice_line_2;
for (let option of this.options) {
if (option.name === 'invoice_line_1') invoice_line_1 = option.value;
if (option.name === 'invoice_line_2') invoice_line_2 = option.value;
}
pdf.setFontSize(2);
pdf.text(invoice_line_1,1,2);
pdf.setFontSize(1);
pdf.text(invoice_line_2, 1, 2.5);
pdf.setFontSize(1);
pdf.text(`Salesperson ${this.invoice.salesman.fullName}`, 15, 2);
pdf.setFontSize(1);
let address = "";
let customerName = `${this.invoice.customer.firstName} ${this.invoice.customer.lastName}`;
if (this.invoice.customer.streetAddress) address = `- ${this.invoice.customer.streetAddress}`;
pdf.text(`Customer ${customerName} ${address}`, 1, 4);
pdf.text(`Invoice Date ${new Date(this.invoice.invoiceDate).toUTCString()}`, 1, 5);
pdf.text(`Invoice Number ${this.invoice.salesInvoiceNumber}`, 1, 6);
pdf.autoTable({
startY: 7,
tableWidth: 'auto',
columnWidth: 'wrap',
tableLineWidth: 0,
// pageBreak:'avoid',
theme:'grid',
bodyStyles:{
halign: 'center'
},
styles: {
fontSize: 1,
overflow: 'linebreak',
cellWidth: 'wrap'
},
columnStyles: {
0: {cellWidth: 5},
1: {cellWidth: 5},
2: {cellWidth: 5},
},
head: [['Sr. #','Name','Amount']],
body: products
});
let offset = pdf.previousAutoTable.finalY;
pdf.setFontSize(0.5);
pdf.text("All values are in PKR", 1, offset + 1);
pdf.setFontSize(1);
if (this.invoice.customer.shippingAddress) {
pdf.text(`Billing Address ${address}`, 1, offset + 2);
pdf.text(`Shipping Address ${this.invoice.customer.shippingAddress}`, 1, offset + 3);
}
pdf.text(`${this.invoice.invoiceTerms}`, 1, offset + 5);
pdf.text(`Total Tax ${this.totalTax}`, 4, offset + 1);
pdf.text(`Shipping ${this.invoice.shippingCharges}`, 4, offset + 2);
pdf.text(`Total Amount ${this.totalAmount}`, 4, offset + 3);
pdf.text(`Grant Total ${this.invoice.total}`, 4, offset + 4);
pdf.autoPrint({variant: 'non-conform'});
pdf.save(`thermalInvoice-${this.invoice.salesInvoiceNumber}.pdf`);}
Это скриншоты печати.
Я получаю сообщение "Столбцы не помещаются на странице" на моей консоли. Как я могу сделать таблицы по центру и поместиться на странице. Я использую angular 7. Пожалуйста, помогите мне с этой проблемой, поскольку я новичок в этом. Спасибо.