Generate a PDF Invoice with a Barcode Using PDF.co and Zapier
Create a barcode from an invoice number, embed it in an HTML invoice, and convert the invoice to PDF. This example uses Google Sheets to supply the invoice data.
Prerequisites
- PDF.co, Zapier, and Google Sheets accounts.
- A spreadsheet with columns for Invoice Number, Customer Name, Description, and Total, plus a completed sample row.
Step 1: Set Up the Trigger
Create a Zap and select Google Sheets with the New Spreadsheet Row trigger.
Connect your Google account, select the spreadsheet and worksheet, and test the trigger to retrieve your sample invoice.
Step 2: Generate the Barcode
Add PDF.co and select Barcode Generator. Connect your PDF.co account through OAuth, then configure:
- Barcode Value: Map Invoice Number from Google Sheets.
- Barcode Type: Select Code128.
- Generate Inline URL: Set to True.
- Custom Profiles: Leave blank.
Test the action. The inline image output contains the barcode image data, which you can embed directly in your HTML invoice. See the Barcode Generator documentation.
Step 3: Create the HTML Invoice
Add another PDF.co action and select HTML to PDF Converter.
Choose Raw HTML code as the input type. Paste the following into HTML or URL Input:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
body { font-family: Arial, sans-serif; padding: 24px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px; border-bottom: 1px solid #ddd; }
th { text-align: left; }
.barcode { margin-top: 24px; }
</style>
</head>
<body>
<h1>Invoice</h1>
<p>Invoice number: INVOICE_NUMBER</p>
<p>Bill to: CUSTOMER_NAME</p>
<table>
<tr><th>Description</th><th>Total</th></tr>
<tr><td>DESCRIPTION</td><td>TOTAL</td></tr>
</table>
<div class="barcode">
<img src="BARCODE_INLINE_URL" alt="Invoice barcode">
</div>
</body>
</html>Replace INVOICE_NUMBER, CUSTOMER_NAME, DESCRIPTION, and TOTAL with the corresponding Google Sheets fields using Zapier’s field picker. Replace BARCODE_INLINE_URL inside the quotation marks with the inline image output from Step 2.
Complete the conversion settings:
- HTML Template ID and HTML Template Data: Leave blank.
- Page Orientation: Portrait.
- Page Size: A4.
- Media Type: Print.
- Name: Map the invoice number and append
.pdf. - Custom Profiles: Leave blank.
See the HTML to PDF documentation for the available settings.
Step 4: Test and Save the Invoice
Test the conversion and open the returned PDF URL. Check the invoice details and scan the barcode to confirm it contains the correct invoice number.
To save the invoice, add Google Drive’s Upload File action. Select your destination folder and map the PDF URL to File.
Test the upload, then publish the Zap. Each new invoice row will generate a PDF with its corresponding barcode.
Fantastic! We have successfully generated a PDF Invoice with Barcode using the HTML To PDF and the Barcode Generator in PDF.co.
Related Tutorials

