Programming, tutorials, mechatronics, operating systems, and other tech stuff

How to add barcode to PDF created with PHP FPDF

This time, i'm about to explain how to add barcode to your generated pdf file. This tutorial requires you to understand the basics how to make / generate pdf file in PHP using FPDF library beforehand. So please read Generate Printable Invoice in PHP using FPDF library if you haven't done so.

Why and what is barcode?

Barcode is an optical, machine-readable numeric data consisting of series of black and white bars with varying thickness. Commonly used in label which requires fast-reading done by machine or computer. Barcode can minimize user's manual input so instead of showing only numeric id on your, let's say, invoice. You can also provide barcoded id. So the user, especially in fast-paced transaction environment can just scan it using barcode reader instead of manual input with keyboard. And here's how to add barcode to your generated PDF file in PHP FPDF library.

Barcode support for PHP FPDF library.

There are no built-in barcode support in PHP FPDF library. However, with a custom class, we can add a barcode support. Here i have prepared a barcode class in my github repository you can download right away here:
There are a lot of barcode standard format, but here we will only use 2 format. EAN13, and UPC_A format which is a commonly used barcode standard.
EAN stands for European Article Number which is a barcode symbology standard and numbering system used in global trade to identify a specific retail product type, in a specific packaging configuration, from a specific manufacturer. While the UPC stands for Universal Product Code which is also a barcode symbology that is widely used in the United States, Canada, United Kingdom, Australia, New Zealand, in Europe and other countries for tracking trade items in stores. Both can hold 12 digit of integer (last digit in EAN13 is a check number so you can only keep 12 digit). For more explanation about barcode standard, you can look it up in wikipedia.

Using custom PHP FPDF class to make a barcode.

First, you need the PHP FPDF library, here i used  FPDF version 1.7 which you can download here.
Then download or copy-paste the fphp_barcode.php file from my repository to your local webserver.
Open the file and make sure that the second line refer to your fpdf.php file which comes with your fpdf library. On my case, the folder structure looks like this:
         |  |-fpdf.php
 So the "require" path should look like this:


Next, make a new file in the same directory as your fpdf_barcode.php file named barcode-test.php then copy this script into it.


$pdf = new PDF_BARCODE('P','mm','A4');


//EAN13 test

//UPC_A test


Save it then see the result in your browser. If nothing goes wrong, it should be like this:

Now, what does the code above do?
First line, we include the fpdf_barcode.php file, not the usual fpdf.php file. We're using a custom class here.
Next, make a PDF_BARCODE object, not FPDF object. With the same parameter as usual. Then add a page. And at the last line, don't forget to output the result. (Please read this fpdf basic if you haven't done so).
With these lines, you are properly made a single page blank PDF file.

//call the fpdf_barcode.php, not the usual fpdf.php. We're using a custom class here.

//define a PDF_BARCODE object, not FPDF object. With portrait orientation, milimeters unit, and A4 size.
$pdf = new PDF_BARCODE('P','mm','A4');

//add a page

//the content goes here

//Output the result

In the pdf_barcode class, there are 2 methods called EAN13 and UPC_A. As the name implies, the former is to make a EAN13 barcode and the later is for UPC_A.

For EAN13, use :
$pdf->EAN13(float x, float y, string barcode [, float h [, float w[, int font_size]]])

And For UPC_A :
$pdf->UPC_A(float x, float y, string barcode [, float h [, float w[, int font_size]]])

x is the abscissa of barcode. Which means the horizontal position of the top-left corner of the barcode.
y is the ordinate of barcode. The vertical position of the top-left corner of the barcode.
barcode is the value of barcode, consists of 12 digits integer.
h is the height of barcode. Default value is 16.
w is the width of a bar. Default value is 0.35.
font_size is the font size of the number below barcode.

So, this line :

Means that we make an EAN13 Barcode at position of 10mm from left and 10mm from top of the page. The barcode contains 123456789012 and the height is 5 and the bar width (not the whole barcode width) is 0.5. And the text which says the integer value below the barcode have a size of 9 points.

If by any chance you're still confused after following this tutorial, please do enjoy this video-version of this tutorial. And if you want the source code, feel free download it from the link provided in the description or ask me in the comment section of aforementioned video.


  1. Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.

    java training in chennai

    java training in bangalore

    java online training

    java training in pune

    1. IEEE Project Domain management in software engineering is distinct from traditional project deveopment in that software projects have a unique lifecycle process that requires multiple rounds of testing, updating, and faculty feedback. A IEEE Domain project Final Year Projects for CSE system development life cycle is essentially a phased project model that defines the organizational constraints of a large-scale systems project. The methods used in a IEEE DOmain Project systems development life cycle strategy Project Centers in Chennai For CSE provide clearly defined phases of work to plan, design, test, deploy, and maintain information systems.

      This is enough for me. I want to write software that anyone can use, and virtually everyone who has an internet connected device with a screen can use apps written in JavaScript. JavaScript Training in Chennai JavaScript was used for little more than mouse hover animations and little calculations to make static websites feel more interactive. Let’s assume 90% of all websites using JavaScript use it in a trivial way. That still leaves 150 million substantial JavaScript Training in Chennai JavaScript applications.

    2. IEEE Final Year projects Project Center in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. <Final Year Projects for CSE It gives you tips and rules that is progressively critical to consider while choosing any final year project point.

      JavaScript Training in Chennai

      JavaScript Training in Chennai

      The Angular Training covers a wide range of topics including Components, project projects for cseAngular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

  2. Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.
    python training in chennai

    python training in bangalore

    python online training

    python training in pune

  3. Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.

    python training in chennai

    python training in bangalore

    python online training

    python training in pune

  4. Useful information.I am actual blessed to read this article.thanks for giving us this advantageous information.I acknowledge this post.and I would like bookmark this post.Thanks

    Data Science Training in Chennai
    Data science training in bangalore
    Data science online training
    Data science training in pune
    Data science training in kalyan nagar
    Data Science with Python training in chenni

  5. Thank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me 
    python training in rajajinagar
    Python training in btm
    Python training in usa

  6. Thank you for allowing me to read it, welcome to the next in a recent article. And thanks for sharing the nice article, keep posting or updating news article.
    Devops training in sholinganallur

  7. We are a group of volunteers and starting a new initiative in a community. Your blog provided us valuable information to work on.You have done a marvellous job!

    angularjs Training in chennai
    angularjs Training in chennai

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

  8. Hello! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done an outstanding job.

    AWS Online Training | Online AWS Certification Course - Gangboard
    AWS Training in Chennai | AWS Training Institute in Chennai Velachery, Tambaram, OMR
    AWS Training in Bangalore |Best AWS Training Institute in BTM ,Marathahalli

  9. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
    Blueprism training in Chennai

    Blueprism training in Bangalore

  10. Does your blog have a contact page? I’m having problems locating it but, I’d like to shoot you an email. I’ve got some recommendations for your blog you might be interested in hearing.
    AWS Training in Chennai |Best Amazon Web Services Training in Chennai
    AWS Training in Rajaji Nagar | Amazon Web Services Training in Rajaji Nagar

    Best AWS Training Institute in BTM Layout Bangalore ,AWS Coursesin BTM

  11. You may need to take a gander at a few connections and test a program or two to locate a satisfactory free program.

  12. It’s appropriate time to make some plans for the future and it’s time to be happy. I have read this post and if I could I wish to suggest you some interesting things or tips. Maybe you could write next articles referring to this article. I wish to read more things about it! click here

  13. This empowers watchers to peruse them on a PC screen yet can't be reproduced by a business printer - to protect the copyright.


  14. Very nice post here and thanks for it .I always like and such a super contents of these post.
    Excellent and very cool idea and great content of different kinds of the valuable information's.
    data science online training
    python online training
    uipath online training
    data science with python online training
    rpa online training

  15. Pleasant Tips..Thanks for Sharing….We keep up hands on approach at work and in the workplace, keeping our business pragmatic, which recommends we can help you with your tree clearing and pruning in an invaluable and fit way.
    angularjs online training

    apache spark online training

    informatica mdm online training

    devops online training

    aws online training

  16. Thank you for allowing me to read it, welcome to the next in a recent article. And thanks for sharing the nice article, keep posting or updating news article.

    Microsoft Azure online training
    Selenium online training
    Java online training
    Java Script online training
    Share Point online training

  17. They programmers can switch to the most recent version of the widely used server-side scripting language to improve the load speed of websites without putting extra time and effort. small business web design Toronto

  18. Your each post is so valuable and easy to understand. Thanks for your time and guide..!

  19. Attend The Python training in bangalore From ExcelR. Practical Python training in bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python training in bangalore.
    python training in bangalore

  20. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
    Python Training in Electronic City

  21. I enjoyed reading your post. I will share it with my other friends as the information is really very useful. Keep sharing your excellent work. Buy Cheap Ean Barcode

  22. To build up a site that is easy to use, amazing, quick stacking, simple to work, savvy, PHP programming services are for the most part liked. CakePHP Application Development

  23. thanks for Sharing such an Awesome information with us.

    I learned World's Trending Technology from certified experts for free of cost.i Got job in decent Top MNC Company with handsome 14 LPA salary, i have learned the World's Trending Technology from Python training in pune experts who know advanced concepts which can helps to solve any type of Real time issues in the field of Python. Really worth trying Freelance seo expert in bangalore

  24. PHP is an "abnormal state" language, implying that it's commonly increasingly human-accommodating (and simpler to learn) than other programming dialects, for example, C, ASP or use Laravel

  25. Attend The PMP in Bangalore From ExcelR. Practical PMP in Bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The PMP in Bangalore.
    ExcelR PMP in Bangalore

  26. This is an incredible rousing article.I am basically satisfied with your great work.You put truly exceptionally accommodating data...  cursos de ti online

  27. Enroll today to get free access to our live demo session which is a great opportunity to interact with the trainer directly which is a placement based Salesforce training India with job placement and certification . Get salesforce training in affordable cost from a best computer institute.

  28. In any case, it is essentially used to depict the entirety of the various kinds of PC programs. itools for pc 64 bit cracked

  29. I have been reading for the past two days about your blogs and topics, still on fetching! Wondering about your words on each line was massively effective.keep it up
    Ai & Artificial Intelligence Course in Chennai
    PHP Training in Chennai
    Ethical Hacking Course in Chennai Blue Prism Training in Chennai
    UiPath Training in Chennai

  30. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharng this information,this is useful to me.
    AWS training in chennai | AWS training in annanagar | AWS training in omr | AWS training in porur | AWS training in tambaram | AWS training in velachery

  31. The development of artificial intelligence (AI) has propelled more programming architects, information scientists, and different experts to investigate the plausibility of a vocation in machine learning. Notwithstanding, a few newcomers will in general spotlight a lot on hypothesis and insufficient on commonsense application. machine learning projects for final year In case you will succeed, you have to begin building machine learning projects in the near future.

    Projects assist you with improving your applied ML skills rapidly while allowing you to investigate an intriguing point. Furthermore, you can include projects into your portfolio, making it simpler to get a vocation, discover cool profession openings, and Final Year Project Centers in Chennai even arrange a more significant compensation.

    Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account.

  32. Really good information to show through this blog. I really appreciate you for all the valuable information that you are providing us through your blog.
    visit : Digital Marketing Training in Chennai || Digital Marketing Course in Chennai

  33. Sharing the same interest, Infycle feels so happy to share our detailed information about all these courses with you all! Do check them out
    oracle training in chennai & get to know everything you want to about software trainings