Skip to content

How to Generate Barcodes on PDF Documents

Add barcodes to merged PDFs using spreadsheet data. Generate Code 128, EAN-13, UPC-A, and other types for shipping labels and inventory documents.

Adding Barcodes to Merged PDF Documents

Barcodes turn your merged documents into machine-readable records — perfect for shipping labels, product tags, inventory tags, and asset tracking. With Mergram, you can generate barcodes directly from spreadsheet data and embed them into each merged PDF.

Prerequisites

To add barcodes to your merged PDFs, you need:

Barcodes vs. QR codes

Barcodes (1D, linear) store short numeric or alphanumeric codes as parallel lines. QR codes (2D) store much more data including URLs, text, and structured information. Use barcodes for simple IDs and product codes. Use QR codes when you need to embed URLs or complex data. See the comparison table below for details.

Supported Barcode Types

Mergram supports a wide range of barcode symbologies for different industries and use cases:

Barcode TypeData FormatMax LengthCommon Use
Code 128ASCII text (letters, numbers, symbols)~80 charsShipping, logistics, general purpose
Code 39Uppercase letters, numbers, symbols~43 charsAutomotive, defense, healthcare
EAN-1312 or 13 digits13 digitsRetail products, ISBNs
EAN-87 or 8 digits8 digitsSmall retail products
UPC11 or 12 digits12 digitsUS/Canada retail products
EAN-55 digits5 digitsSupplemental add-on for EAN/UPC
EAN-22 digits2 digitsSupplemental add-on for EAN/UPC
ITFEven number of digits~14 digitsShipping containers, cartons, warehousing
MSIDigits only~11 digitsWarehouse shelves, inventory
PharmacodeNumber (3–131,070)Single numberPharmaceutical packaging
CodabarDigits + symbols (-$:/.+)~20 charsLibraries, blood banks, FedEx

When in doubt, use Code 128

Code 128 is the most versatile barcode type. It accepts any combination of letters, numbers, and symbols. Use it for tracking numbers, serial numbers, and internal IDs. It’s the default choice for logistics and shipping.

Choosing the Right Barcode Type

For Shipping and Logistics

Use Code 128 for tracking numbers and shipping IDs. Most carriers (UPS, FedEx, DHL, USPS) use Code 128 for their tracking barcodes.

For Retail Products

Use EAN-13 for products sold internationally or UPC for products sold in the US and Canada. These barcodes must be registered with GS1.

For Inventory and Warehouses

Use Code 128 for general inventory tags or ITF for outer cartons and shipping containers.

For Pharmaceuticals

Use Pharmacode for pharmaceutical packaging — it encodes a single number and is the standard for the industry.


Barcodes vs. QR Codes

Choose the right 1D/2D code for your use case:

FeatureBarcodes (1D)QR Codes (2D)
Data capacityUp to ~80 charactersUp to ~4,000 characters
Data typesNumbers, some textText, URLs, vCards, WiFi
Scan directionHorizontal onlyAny angle
Print spaceNeeds horizontal widthSquare, compact
Error correctionMinimalBuilt-in (survives damage)
Best forProduct IDs, tracking numbersURLs, complex data, verification
Common useShipping, retail, inventoryMarketing, tickets, certificates

Use barcodes when you need simple, standardized product or tracking codes. Use QR codes when you want recipients to open a URL or access digital content.

Preparing Your Spreadsheet

Add a dedicated column for barcode values. Ensure the data matches the format requirements of your chosen barcode type:

ProductSKUBarcodeValueBarcodeType
Widget ASKU-001123456789012EAN-13
Widget BSKU-002123456789013EAN-13
Gadget CSKU-003TRK-2025-001Code 128
Gadget DSKU-004TRK-2025-002Code 128

Validate barcode data before merging

Check that your values match the format requirements. EAN-13 needs exactly 12 or 13 digits — letters will cause errors. Code 128 is the most forgiving and accepts any text. Use Excel’s data validation feature to enforce format rules in your spreadsheet.

Placing Barcode Fields on the Canvas

  1. Select the column — Click the barcode data column in the data fields panel
  2. Set render type — Change from “Text” to “Barcode” in the field properties
  3. Position on canvas — Drag the barcode bounding box to the desired location
  4. Resize — Barcodes scale to fill the bounding box width. Drag the bounding box wider or narrower to control the barcode width. Use the height and margin settings in the toolbar to control vertical dimensions
  5. Add human-readable text — If you want the barcode value displayed below the barcode as text, add a separate text field with the same column next to the barcode field

Sizing Guidelines for Scannable Barcodes

Barcodes that are too small or narrow won’t scan reliably. Follow these guidelines:

GuidelineRecommendation
Minimum widthAt least 1.5 inches (4cm) for Code 128
Minimum heightAt least 0.5 inches (1.3cm)
Quiet zoneLeave 0.25 inches (6mm) of white space on each side
Print resolution300 DPI minimum for crisp barcode lines
BackgroundWhite or light-colored background only
ForegroundBlack or very dark color for maximum contrast

Barcodes scale to bounding box width

Barcodes scale to fill the bounding box width on the canvas. Drag the bounding box wider for a wider barcode, narrower for a compact one. The height setting in the toolbar controls how tall the bars are. You can add a margin for padding around the barcode.

Real-World Use Cases

Shipping Labels with Barcodes

Create shipping labels with a Code 128 barcode for the tracking number. Pair it with text fields for the recipient address, sender address, and weight.

Product Tags

Generate product tags with EAN-13 barcodes from your product catalog spreadsheet. Include product name, price, and SKU as text fields alongside the barcode.

Asset Tags

Create equipment asset tags with Code 128 barcodes for asset IDs. Add fields for department, location, and purchase date.

Inventory Labels

Print ITF-14 barcodes on warehouse bin labels and carton labels. Include the item description and quantity as companion text fields.

Best Practices for Barcode Fields

  1. Test scan before bulk generation — Generate one sample, print it, and scan with a real barcode scanner or phone app
  2. Include human-readable text — Add a text field below the barcode showing the same value, so people can read it if scanning fails
  3. Keep data clean — Remove leading/trailing spaces from barcode values in your spreadsheet
  4. Use consistent formats — Don’t mix barcode types in the same column. If you need different types, use separate columns
  5. Check digit validation — For EAN/UPC codes, ensure your spreadsheet includes correct check digits

Common Issues and Troubleshooting

Barcodes not scanning: Ensure the bounding box is wide enough for the barcode data. Increase the barcode height for taller bars that are easier to scan. Ensure there’s sufficient white space around the barcode (quiet zone). Verify the print output is at 100% scale — reduced-size printing makes bars too thin.

“Invalid data” error during merge: The data format doesn’t match the barcode type requirements. EAN-13 requires digits only. Code 39 requires uppercase only. Switch to Code 128 if you need maximum flexibility.

Barcodes look compressed or distorted: Barcodes scale to fill the bounding box width. If the bounding box is too narrow, the bars will be compressed. Widen the bounding box or use a shorter data value. Adjust the barcode height setting to control bar height independently.

Blurry barcodes in print: Mergram renders barcodes at full resolution. If print output is blurry, check your printer settings — ensure you’re printing at actual size (100%) with no page scaling.

Get Started

Upload your PDF template, add a barcode column to your spreadsheet, and place a barcode field on the canvas in the Mergram editor. Preview with real data to verify the barcode renders and scans correctly before running the full merge.

Step-by-step guide

  1. 1

    Prepare Barcode Data

    Add a column to your spreadsheet with the barcode values. Ensure the data format matches your chosen barcode type's requirements.

  2. 2

    Place Barcode Field

    In the editor, drag the barcode column onto the canvas and set the render type to 'Barcode'.

  3. 3

    Configure Barcode Type

    Select the appropriate barcode symbology (Code 128, EAN-13, etc.) in the field properties panel.

  4. 4

    Preview and Merge

    Preview with real data to verify the barcode renders correctly, then run the full merge.

Frequently asked questions

What barcode types does Mergram support?
Mergram supports Code 128, Code 39, EAN-13, EAN-8, EAN-5, EAN-2, UPC, ITF, MSI, Pharmacode, and Codabar. Code 128 is the most versatile and recommended for general use.
Can each PDF have a different barcode?
Yes. Each row in your spreadsheet produces a unique barcode from the corresponding cell value. Use different product IDs, tracking numbers, or serial numbers for each row.
What is the difference between barcodes and QR codes?
Barcodes (1D) encode data as parallel lines and hold up to about 20 characters. QR codes (2D) use a grid pattern and hold up to 4,000 characters, including URLs and multi-line text. Barcodes are better for simple IDs; QR codes are better for complex data and URLs.
Can I combine barcodes and QR codes on the same PDF?
Yes. Place as many barcode and QR code fields as you need on the same template. For example, a shipping label could include a Code 128 barcode for the tracking number and a QR code linking to the tracking page.
What data format do barcodes require?
Each barcode type has specific requirements. Code 128 accepts any ASCII text. EAN-13 requires exactly 12 or 13 digits. UPC-A requires 11 or 12 digits. Check the format requirements for your chosen barcode type before preparing your data.

Ready to try it yourself?

Start merging PDFs in minutes — free account required, no credit card needed.

Related articles