How to use mPDF to display the barcode

mPDF is a open source software which was used for creating the pdf files from a html page, for that you can use the php or the html page to create the pdf files. mPDF also gives us a option to create a variety of barcode such as

Barcode Types –  which can be created by mPDF

EAN13, ISBN, ISSN, UPCA, UPCE, EAN8
EAN13P2, ISBNP2, ISSNP2, UPCAP2, UPCEP2, EAN8P2 (with EAN-2 supplement code i.e. 01-99 )
EAN13P5, ISBNP5, ISSNP5, UPCAP5, UPCEP5, EAN8P5  (with EAN-5 supplement code e.g. 90000 )
(UPCE needs the UPCA code entered)
IMB, RM4SCC, KIX, POSTNET, PLANET
C128A, C128B, C128C
EAN128A, EAN128B, EAN128C
C39, C39+, C39E, C39E+
S25, S25+, I25, I25+, I25B, I25B+
C93
MSI, MSI+
CODABAR
CODE11

Creating the barcode is so simple when using the mPDF, if you are using a php barcode script to create a barcode then you can create the barcode in a image format but if you use the mPDF then you can create the barcode and import it in a pdf format too. Here i am going to give you a code which was used to create the barcode in a pdf format.

$imgSrc = <link your image here>;

$sid = “1234567”;
        $mpdf = new mPDF(‘utf-8’, ‘A4′,0,”,15,15,25,16,4,9,’P’);
           $mpdf->WriteHTML(‘<watermarkimage src=’.$imgSrc.’ alpha=”0.33″ size=”50,30″/>’);
        
        $mpdf->showWatermarkImage = true;
        $mpdf->WriteHTML($html);
        $mpdf->WriteHTML(‘<div style=”
            color:white;
            text-align:center;
            padding:5px;”>
            <barcode code=”$sid” type=”C128A” size=”0.5″ height=”2.0″/></div>’); //Sizes between 0.8 and 2.0        
        $mpdf->WriteHTML(‘<div style=”
            text-align:center;”>
            Student Bardcode ID</div>’);
        $mpdf->Output($title.’.pdf’, “I”);

The above coding will use the design tags to show the barcode with pdf, it will show the pdf file when executed.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *