Author: Rafael Martin Soto
Viewers: 1,195
Last month viewers: 111
Package: PHP Print Labels to PDF
You can solve that problem by generating PDF documents that show areas for each label containing the details of the people you want to appear.
Read this tutorial article to learn how to generate such PDF files using simple code that calls the PHP Print Labels PDF package to produce those files.
In this article you will learn:
1. Why Printing Labels Is Useful
2. What Can be Done to Print Labels
3. How Can You Generate Labels in PDF Format From PHP
4. How Fast is this PHP Print Labels to PDF Package
5. How to Download the PHP Print Labels to PDF Package or Install It with PHP Composer
If you prefer to read this article in Spanish, you may also find it here.
1. Why Printing Labels Is Useful
Labels are often used to display the names and addresses of people or some other kind of information that is useful to stick on other object, so people can read and learn from the information that is displayed in labels.
2. What Can be Done to Print Labels
A label may contain text or graphics. If you compose a document with the label text and graphics, you can print that document to generate the labels you need.
One common way to use computers to generate documents to be printed is creating files in the PDF format and then send the PDF file to a printer.
3. How Can You Generate Labels in PDF Format From PHP
If you ever have thought on how to print labels using PHP, you may have run into problems, problems and more problems. How many headaches must those problems have caused you when printing labels over the years?
We need to print labels, calculate margins, link with word templates, leave some labels without printing to take advantage of the previous ones. Now they change my printer. Now they change the label format. Now the sheets are blank and I have to be the one to draw the edges to trim the labels. And so on.
How do I link to the database to make it easy for the client? The simple reply is with PHP and PDF.
I have suffered a lot with that. So I have decided to create a class in standard PHP to be able to solve this problem definitively, at least from Web servers.
One way to generate a label document in PDF is to create an HTML document and convert it to PDF format using a separate program. That is the solution that the PHP Print Labels to PDF package implements.
When creating the label document, keep in mind that measurements must be used in cm and not in pixels, since this is what makes many of the works that I have seen carried out work on some systems and not on others.
By doing it in document measurements (centimeters in this case), it will work for any operating system, for any printer, and for any environment. No more tag 'mismatch' problems.
The content of each tag is given in HTML format, so we can use the HTML standards to use bold text, underlined, italics, etc ..... We can also use the size and/or font that we have installed on the server (Times, Sans, Courier, ....).
The only requirement, you have to know that it is necessary to also install the MPDF library.
The use of this class is very simple. It is enough to carry out the inclusion of the class file, give it the parameters such as page size, top and left margins, measurements of the labels, margins within them and space between them. These parameters are common to any type of tag.
The system generates a PDF file ready to print. The options are:
Show the PDF of the Labels to print in the browser.
Download the PDF file of the Labels to print on the computer.
Save the PDF file of the Labels to print on the web server itself.
As a bonus, the class allows a couple of interesting functions:
If required, a border can be drawn around the labels. This is useful for example, when we have a blank adhesive paper, but we need a guide to cut out these labels.
You can start printing in any row and column number to reuse the previously used paper and take advantage of the remaining labels. RECYCLE !!!!!.
4. How Fast is this PHP Print Labels to PDF Package
I have done a Benchmark to find out the time it takes to create label files in PDF with this package. In fact, the execution time of the script that generates the PDF file is saved in each of the documents, just in case it is useful for you.
To generate a PDF document with 2,499 labels with borders, the system took 18 seconds (about 0.72 seconds for every 100 labels), in an Ubuntu virtual machine. In this case, a PDF of the APLI tags ref. 00014 and the result is here.
In the case of a simple Raspberry pi B 2, the result of creating 999 labels has been 2 minutes and 28 seconds (about 14.81 seconds for every 100 labels).
The library could be improved further, by preparing the default data for different label references from different manufacturers, but I'm still waiting for a response from the APLI factory to make my work a little easier. I won't do it all myself, right?
5. How to Download the PHP Print Labels to PDF Package or Install It with PHP Composer
The PHP Print Labels to PDF package can be downloaded from download page or be installed using the PHP Composer tool following instructions in the Composer install instructions page.
You need to be a registered user or login to post a comment
1,616,107 PHP developers registered to the PHP Classes site.
Be One of Us!
Login Immediately with your account on:
Comments:
No comments were submitted yet.