remove product images from invoice PDF and adjust table layout columns
This commit is contained in:
parent
ae3747e8c2
commit
59bc47f7ad
@ -200,8 +200,7 @@ const generateInvoicePDF = async (orderData) => {
|
|||||||
.fillColor(primaryColor);
|
.fillColor(primaryColor);
|
||||||
|
|
||||||
doc.text('S.No', 40, tableY, { width: 35 });
|
doc.text('S.No', 40, tableY, { width: 35 });
|
||||||
doc.text('Image', 85, tableY, { width: 60 });
|
doc.text('Product', 85, tableY, { width: 270 });
|
||||||
doc.text('Product', 155, tableY, { width: 200 });
|
|
||||||
doc.text('Quantity', 365, tableY, { width: 50, align: 'right' });
|
doc.text('Quantity', 365, tableY, { width: 50, align: 'right' });
|
||||||
doc.text('Unit price', 425, tableY, { width: 60, align: 'right' });
|
doc.text('Unit price', 425, tableY, { width: 60, align: 'right' });
|
||||||
doc.text('Total price', 495, tableY, { width: 60, align: 'right' });
|
doc.text('Total price', 495, tableY, { width: 60, align: 'right' });
|
||||||
@ -223,14 +222,6 @@ const generateInvoicePDF = async (orderData) => {
|
|||||||
for (let i = 0; i < orderData.line_items.length; i++) {
|
for (let i = 0; i < orderData.line_items.length; i++) {
|
||||||
const item = orderData.line_items[i];
|
const item = orderData.line_items[i];
|
||||||
|
|
||||||
// Fetch product image buffer
|
|
||||||
let imageBuffer = null;
|
|
||||||
if (item.image) {
|
|
||||||
imageBuffer = await fetchImageBuffer(item.image);
|
|
||||||
} else if (item.featured_image && item.featured_image.url) {
|
|
||||||
imageBuffer = await fetchImageBuffer(item.featured_image.url);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Background color for alternating rows
|
// Background color for alternating rows
|
||||||
if (i % 2 === 1) {
|
if (i % 2 === 1) {
|
||||||
doc.rect(40, tableY - 4, 515, 38).fill(rowAltColor);
|
doc.rect(40, tableY - 4, 515, 38).fill(rowAltColor);
|
||||||
@ -243,24 +234,15 @@ const generateInvoicePDF = async (orderData) => {
|
|||||||
// S.No
|
// S.No
|
||||||
doc.text((i + 1).toString(), 40, tableY);
|
doc.text((i + 1).toString(), 40, tableY);
|
||||||
|
|
||||||
// Image
|
|
||||||
if (imageBuffer) {
|
|
||||||
try {
|
|
||||||
doc.image(imageBuffer, 85, tableY - 2, { fit: [35, 30] });
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Failed to draw item image:', err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Product Name and Variant/Quantity details
|
// Product Name and Variant/Quantity details
|
||||||
const productText = item.title || item.name;
|
const productText = item.title || item.name;
|
||||||
doc.text(productText, 155, tableY, { width: 200, height: 15, ellipsis: true });
|
doc.text(productText, 85, tableY, { width: 270, height: 15, ellipsis: true });
|
||||||
|
|
||||||
// Display quantity/variant info if available
|
// Display quantity/variant info if available
|
||||||
if (item.variant_title) {
|
if (item.variant_title) {
|
||||||
doc.fontSize(8)
|
doc.fontSize(8)
|
||||||
.fillColor('#64748b')
|
.fillColor('#64748b')
|
||||||
.text(item.variant_title, 155, tableY + 12, { width: 200 });
|
.text(item.variant_title, 85, tableY + 12, { width: 270 });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset font size
|
// Reset font size
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user