Download the PHP package faerber/pdf-to-zpl without Composer
On this page you can find all versions of the php package faerber/pdf-to-zpl. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download faerber/pdf-to-zpl
More information about faerber/pdf-to-zpl
Files in faerber/pdf-to-zpl
Package pdf-to-zpl
Short Description Convert a PDF file to a ZPL file
License MIT
Homepage https://github.com/benfaerber/pdf-to-zpl
Informations about the package pdf-to-zpl
PDF to ZPL
Convert a PDF into the ZPL format. Allowing for custom images, alphabets like Hebrew, Arabic and Cyrillic (without messing with fonts on the printer) and multipage shipping labels!
Gettings Started:
You will need admin rights to setup Imagick PDF reading (essential for this library).
Linux Environment Setup:
The minimum version for this package is 8.1
.
Ensure you have Imagick and GD installed using:
(Or whatever PHP Version you are using)
Then make sure to enable them in php.ini
(usually enabled by default).
Imagick Settings
You may need to enable PDF permission in your Imagick settings.
- Find your Imagick Policy File:
ls /etc/ | grep ImageMagick
- Edit your Imagick Policy File:
sudo nano "/etc/ImageMagick6/policy.xml"
Find this line and ensure the rights are set to read | write
:
Change to:
If this line doesn't exist at all, add it. You'll only run into this with tiny linux boxes like Github Actions.
Imagick has had PDF related security issues. Convert only trusted PDFs. Here's one example: CVE-2020-29599
Windows Environment Setup:
Install GhostScript
with choco
and Imagick and GD extensions.
Converting Images:
Previewing Labels
The labelary
API is used to generate images from ZPL allowing the label to be previewed.
This is a free API that requires no auth so it can be used with no setup. Be sure to respect their rate limits!
Settings
There are many settings you can use to configure the conversion. You can use Imagick instead of GD, rotate and resize labels etc.
See Settings for more details.
Unit Testing
Run composer test
. Testing is done via PHP Unit.
If you make major changes you may need to regenerate the test data (tests pass if each file is at least 95% similar to the test data generated with PHP 8.3 on my linux box).
For example modifying scaling code where the output is correct but the test data is outdated.
Run composer generate-test-data
and manually verify the images are rendered correctly.
Benchmarking
Run composer benchmark
. Benchmarking is done via phpbench
.
Here's some basic performance information:
- Converting a PNG to ZPL:
668.26ms
- Convert a 3 page PDF label to ZPL with GD Backend:
1.8s
- Convert a 3 page PDF label to ZPL with Imagick Backend:
5.4s
This was run on my workstation. (AMD Ryzen 9 7950x 16-core
, 32Gib
)
See phpbench output for more details.
Formatting
Run composer format
. Formatting is done via php-cs-fixer
.
How does this work?
- Loads the PDF and render each page as image
- Scale the image to match the DPI and aspect ratio of the label
- Convert each page into a grayscaled bitmap
- Run line encode the bitmap and marshall it into a ZPL binary representation
- Wrap the encoded data into a ZPL payload