Hey
I have a n8n form with a file attachment field and other text fields.
the flow is Form > Build HTML > HTML2PDF > File Upload.
The only portion I cannot get working is the file part. What I was wanting to do is if convert everything into one large PDF.
Employees are going to be submitting these for the other department to approve and integrate in their workflow to make it easier for everyone.
Is my setup wrong? Or is there a better way to do this?
Here is my code-
const form = $input.all()[0].json;
const receipt = $input.first().binary?.data || $input.binary?.Receipt || $input.binary?.receipt;
let receiptImg = ‘’;
if (receipt?.data && receipt?.mimetype) {
receiptImg = <img src="data:${receipt.mimetype};base64,${receipt.data}" style="max-width:100%; height:auto; display:block; margin:40px 0; border:2px solid #333; box-shadow:0 4px 8px rgba(0,0,0,0.1);">;
} else {
receiptImg = ‘No receipt attached’;
}
const html = `
Receipt Submission body { font-family: Arial, sans-serif; margin: 70px; line-height: 1.6; background:#f9f9f9; color:#333; } h1 { color:#2c3e50; border-bottom:3px solid #3498db; padding-bottom:10px; } table { width: 100%; border-collapse: collapse; margin: 30px 0; background:white; box-shadow:0 2px 10px rgba(0,0,0,0.1); } th, td { border: 1px solid #ddd; padding: 16px; text-align: left; } th { background:#ecf0f1; font-weight: bold; width: 30%; color:#2c3e50; } .receipt-container { margin-top: 50px; padding: 30px; background:white; border-radius:8px; box-shadow:0 4px 20px rgba(0,0,0,0.1); } h2 { color:#2c3e50; margin-bottom:20px; }Receipt Submission
| Date on Receipt | ${form["Date on Receipt"] || ''} |
|---|---|
| Vendor | ${form.Vendor || ''} |
| Amount | ${form["Amount on Receipt"] ? '$' + Number(form["Amount on Receipt"]).toFixed(2) : ''} |
| Payment Method | ${form["Payment Method"] || ''} |
| For | ${form["Item Use"] || ''} |
| QB Account | ${form["Item Type"] || ''} |
| Description | ${form["Description for Invoice"] || ''} |
| Notes | ${form.Notes || ''} |
| Submitted | ${new Date(form.submittedAt).toLocaleString() || ''} |
Receipt Image
${receiptImg}return [{ json: { html } }];
