Skip to main content

Barcodes

bkhtmltopdf has a built-in <barcode> custom tag for generating barcodes and QR codes. It inherits from the standard <img> tag, so it supports style, class, alt, and other attributes, while adding type, value, and options for dynamic generation.

Attributes

AttributeTypeDescription
typestringBarcode type (e.g., qrcode, code128), see: Types
valuestringBarcode content (e.g., text or URL)
optionsstringType-specific options, separated by , (e.g., includetext)
widthstringWidth (e.g., 200px), default is auto
heightstringHeight (e.g., 200px), default is auto
altstringAlternative text for accessible PDFs (screen readers)
tip

<barcode> is converted to an image during rendering, so keep value short to optimize performance.

Example

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hi, bkhtmltopdf!</title>
</head>
<body>
<barcode type="qrcode" value="Hi, bkhtmltopdf." width="200px" height="200px"
alt="This is a QR code whose value is: Hi, bkhtmltopdf."/>

<barcode type="code128" value="123456789" width="200px" height="200px" options="includetext"
alt="This is a Code 128 whose value is: 123456789"/>
</body>
</html>

Preview

Barcode preview

Types

类型编码选项
AusPost 4 State Customer Codeauspostincludetext custinfoenc=character5956439111ABA 9
Aztec Codeazteccodeformat=fullThis is Aztec Code
Aztec Runesaztecrune1
BC412bc412semi includetext includecheckintextBC412SEMI
COOP 2 of 5coop2of5includetext includecheck includecheckintext01234567
Channel Codechannelcodeheight=12 includetext3493
CodabarrationalizedCodabarincludetext includecheck includecheckintextA0123456789B
Codablock Fcodablockfcolumns=8CODABLOCK F 34567890123456789010040digit
Code 11code11includetext includecheck includecheckintext0123456789
Code 128code128includetextCount01234567!
Code 16Kcode16kAbcd-1234567890-wxyZ
Code 25code2of5includetext includecheck includecheckintext01234567
Code 39code39includetext includecheck includecheckintextTHIS IS CODE 39
Code 39 Extendedcode39extincludetext includecheck includecheckintextCode39 Ext!
Code 49code49MULTIPLE ROWS IN CODE 49
Code 93code93includetext includecheckTHIS IS CODE 93
Code 93 Extendedcode93extincludetext includecheckCode93 Ext!
Code OnecodeoneCode One
Compact Aztec Codeazteccodecompact1234
Compact PDF417pdf417compactcolumns=2This is compact PDF417
Custom 1D symbologyrawheight=12331132131313411122131311333213114131131221323
Custom 4 state symbologydaftFATDAFTDAD
Data MatrixdatamatrixThis is Data Matrix!
Data Matrix Rectangulardatamatrixrectangular1234
Data Matrix Rectangular Extensiondatamatrixrectangularextensionversion=8x961234
Datalogic 2 of 5datalogic2of5includetext includecheck includecheckintext01234567
Deutsche Post Identcodeidentcodeincludetext563102430313
Deutsche Post Leitcodeleitcodeincludetext21348075016401
DotCodedotcodeinkspread=0.16This is DotCode
EAN-13ean13includetext guardwhitespace9520123456788
EAN-13 Compositeean13compositeincludetext9520123456788|(99)1234-abcd
EAN-14ean14includetext(01) 0 952 8765 43210 8
EAN-2 (2 digit addon)ean2includetext guardwhitespace05
EAN-5 (5 digit addon)ean5includetext guardwhitespace90200
EAN-8ean8includetext guardwhitespace95200002
EAN-8 Compositeean8compositeincludetext95200002|(21)A12345678
Flattermarkenflattermarkeninkspread=-0.25 showborder borderleft=0 borderright=011099
GS1 Composite 2D Componentgs1-ccccversion=b cccolumns=4(01)09521234543213(3103)000123
GS1 Data Matrixgs1datamatrix(01)09521234543213(17)120508(10)ABCD1234(410)9501101020917
GS1 Data Matrix Rectangulargs1datamatrixrectangular(01)09521234543213(17)120508(10)ABCD1234(410)9501101020917
GS1 DataBar Expandeddatabarexpanded(01)09521234543213(3103)000123
GS1 DataBar Expanded Compositedatabarexpandedcomposite(01)09521234543213(3103)001234|(91)1A2B3C4D5E
GS1 DataBar Expanded Stackeddatabarexpandedstackedsegments=4(01)09521234543213(3103)000123
GS1 DataBar Expanded Stacked Compositedatabarexpandedstackedcompositesegments=4(01)09521234543213(10)ABCDEF|(21)12345678
GS1 DataBar Limiteddatabarlimited(01)09521234543213
GS1 DataBar Limited Compositedatabarlimitedcomposite(01)09521234543213|(21)abcdefghijklmnopqrst
GS1 DataBar Omnidirectionaldatabaromni(01)09521234543213
GS1 DataBar Omnidirectional Compositedatabaromnicomposite(01)09521234543213|(11)990102
GS1 DataBar Stackeddatabarstacked(01)09521234543213
GS1 DataBar Stacked Compositedatabarstackedcomposite(01)09521234543213|(17)010200
GS1 DataBar Stacked Omnidirectionaldatabarstackedomni(01)24012345678905
GS1 DataBar Stacked Omnidirectional Compositedatabarstackedomnicomposite(01)03612345678904|(11)990102
GS1 DataBar Truncateddatabartruncated(01)09521234543213
GS1 DataBar Truncated Compositedatabartruncatedcomposite(01)09521234543213|(11)990102
GS1 Digital Link Data Matrixgs1dldatamatrixincludetexthttps://id.gs1.org/01/09521234543213/22/ABC%2D123?99=XYZ-987
GS1 Digital Link QR Codegs1dlqrcodeincludetextHTTPS://ID.GS1.ORG/01/09521234543213/22/ABC%2D123?99=XYZ-987
GS1 DotCodegs1dotcoderows=16(235)5vBZIF%!<B;?oa%(01)09521234543213(8008)19052001
GS1 North American Coupongs1northamericancouponincludetext segments=8(8110)106141416543213500110000310123196000
GS1 QR Codegs1qrcode(01)09521234543213(8200)http://www.abc.net(10)ABCD1234(410)9501101020917
GS1-128gs1-128includetext(01)09521234543213(3103)000123
GS1-128 Compositegs1-128compositeccversion=c(00)095287654321012346|(02)09521234543213(37)24(10)1234567ABCDEFG
HIBC Aztec CodehibcazteccodeA999BJC5D6E71
HIBC Codablock FhibccodablockfA999BJC5D6E71
HIBC Code 128hibccode128includetextA999BJC5D6E71
HIBC Code 39hibccode39includetextA999BJC5D6E71
HIBC Data MatrixhibcdatamatrixA999BJC5D6E71
HIBC Data Matrix RectangularhibcdatamatrixrectangularA999BJC5D6E71
HIBC MicroPDF417hibcmicropdf417A999BJC5D6E71
HIBC PDF417hibcpdf417A999BJC5D6E71
HIBC QR CodehibcqrcodeA999BJC5D6E71
Han Xin CodehanxinThis is Han Xin
IATA 2 of 5iata2of5includetext includecheck includecheckintext01234567
ISBNisbnincludetext guardwhitespace978-1-56581-231-4 90000
ISMNismnincludetext guardwhitespace979-0-2605-3211-3
ISSNissnincludetext guardwhitespace0311-175X 00 17
ITF-14itf14includetext0 952 1234 54321 3
Industrial 2 of 5industrial2of5includetext includecheck includecheckintext01234567
Interleaved 2 of 5 (ITF)interleaved2of5height=12 includecheck includetext includecheckintext2401234567
Italian Pharmacodecode32includetext01234567
Japan Post 4 State Customer Codejapanpostincludetext includecheckintext6540123789-A-K-Z
MSI Modified Plesseymsiincludetext includecheck includecheckintext0123456789
Marks & Spencermandsincludetext0642118
Matrix 2 of 5matrix2of5includetext includecheck includecheckintext01234567
MaxiCodemaxicodemode=2 parse[)>^03001^02996152382802^029840^029001^0291Z00004951^029UPSN^02906X610^029159^0291234567^0291/1^029^029Y^029634 ALPHA DR^029PITTSBURGH^029PA^029^004
Micro QR Codemicroqrcode1234
MicroPDF417micropdf417MicroPDF417
Miscellaneous symbolssymbolbackgroundcolor=DD000011fima
PDF417pdf417columns=2This is PDF417
Pharmaceutical Binary Codepharmacodeshowborder117480
Pharmazentralnummer (PZN)pznincludetext123456
Plessey UKplesseyincludetext includecheckintext01234ABCD
PosiCodeposicodeversion=b inkspread=-0.5 parsefnc includetextABC123
QR Codeqrcodeeclevel=Mhello
Rectangular Micro QR Coderectangularmicroqrcodeversion=R17x1391234
Royal Dutch TPG Post KIXkixincludetext1231FZ13XHS
Royal Mail 4 State Customer Coderoyalmailincludetext barcolor=FF0000LE28HS9Z
Royal Mail Mailmarkmailmarktype=29JGB 012100123412345678AB19XY1A 0             www.xyz.com
SSCC-18sscc18includetext(00) 0 9528765 432101234 6
Swiss QR CodeswissqrcodeparseSPC^CR^LF0200^CR^LF1^CR^LFCH5800791123000889012^CR^LFS^CR^LFRobert Schneider AG^CR^LFRue du Lac^CR^LF1268^CR^LF2501^CR^LFBiel^CR^LFCH^CR^LF^CR^LF^CR^LF^CR^LF^CR^LF^CR^LF^CR^LF^CR^LF199.95^CR^LFCHF^CR^LFK^CR^LFPia-Maria Rutschmann-Schnyder^CR^LFGrosse Marktgasse 28^CR^LF9400 Rorschach^CR^LF^CR^LF^CR^LFCH^CR^LFSCOR^CR^LFRF18539007547034^CR^LF^CR^LFEPD
TelepentelepenincludetextABCDEF
Telepen Numerictelepennumericincludetext01234567
Two-track Pharmacodepharmacode2includetext showborder117480
UPC-Aupcaincludetext012345000058
UPC-A Compositeupcacompositeincludetext012345000058|(99)1234-abcd
UPC-Eupceincludetext01234558
UPC-E Compositeupcecompositeincludetext01234558|(15)021231
USPS Intelligent Mailonecodebarcolor=FF00000123456709498765432101234567891
USPS PLANETplanetincludetext includecheckintext01234567890
USPS POSTNETpostnetincludetext includecheckintext01234
Ultracodeultracodeeclevel=EC2Awesome colours!