welcome to the ninth chapter of PHP FPDF tutorial series.
in this chapter i will demonstrate how to add barcode in PDF using modified PHP FPDF library.
i've already prepared the barcode class in my github repository, link in the description.
there are a lot of barcode standard format,
but here we will only use 2 format which is EAN13, and UPC_A format.
you can copy-paste the content of fpdf_barcode.php from the github.
make a new php file.
then paste the content.
and change the "require" file path, make sure it properly points to your fpdf class file.
now lets make a new pdf file like usual.
but this time, instead of main fpdf class, we will call the fpdf barcode class file.
and make a pdf object from FPDF_BARCODE class.
the rest is just like what we usually do to build a pdf file like add page and ouput.
to add a barcode, just call either EAN13 or UPC_A method.
both method require 6 parameters for x coordinate,
y coordinate, barcode integer, height of barcode, width of the bar, and font size.
now let's make some more.
by the standard, EAN13 will have 1 digit integer appended to the end for the check digit.
so don't worry about it, you can ignore the last digit.
you can read more about those barcode standards in wikipedia.
barcode is positioned relative to the page,
so you will need to experiment with the placement coordinate.
using online barcode reader, we can check if our barcode is readable by barcode scanner.
and please keep in mind that printers have different printing capability.
barcode relies on the width of the black bar and white spaces.
if the printed result is too blurry the scanner will have difficulty to scan them.
so avoid to make the bar width too tight.
now as an example, let's add this barcode functionality to our invoice from the previous chapter.
this concludes this chapter of tutorial.
please like this video if you find this tutorial helpful.
and subscribe to my channel for more tutorials update.
if you have any question or need the source code, feel free to ask anything in the comment section.
see you next time.

Không có nhận xét nào:
Đăng nhận xét