projects > pdfb library - barcodes in dynamic pdfs
PDFB Library - Barcodes in Dynamic PDFs
- If you've ever wanted to generate PDFs on-the-fly on your server and wanted to do more than just plain text, PDFB Library just might be what you're looking for.
- PDFB Library by Chirag Mehta makes it very easy for even novice PHP programmers to generate high-quality dynamic PDF files. The library allows you to take any PDF file, then overlay text, images, and barcodes (Code 3 of 9, Code 128, Interleaved 2 of 5, and UPC-A), and generate a new PDF dynamically.
- On most servers it requires almost no configuration and as long as the PHP Image library is setup correctly, you're ready to go. PDFB Library has been tested to run on Linux and Windows servers without any problems.
Live Demo of PDFB Library
- Let us take this base PDF as a template.
- Now write this simple PHP code.
- Voila! Generate the PDF on the fly!
- View the ReadMe.txt file for more info.
Download PDFB Library
- You may choose to download the full demo + working code that you can distribute and modify yourself or you can download the compact working code with a demo that you can use in production environments.
- PDFB Library - Full Version - 378kb (Recommended)
- PDFB Library - Compact Version - 136kb (For Production Use)
Credits
- PDFB Library works by combining the following three awesome PHP libraries:
- FPDF by Olivier Plathey (current version: v1.53)
- FPDI by Jan Slabon (current version: v1.1)
- Barcode by Karim Mribti (current version: v0.0.8a)
- Each of these libraries have their own licensing and copyright/copyleft schemes. For license and legal requirements for each of these libraries, refer to the URLs above.
- The PDFB ElePHPant Logo was created using a template by El Roubio.
License
- The PDFB Library is released under the Creative Commons license.
- While I use code and algorithms from various sources, I always respect the code license and give credit where it's due. If you think that I am using your code/algorithm without the appropriate license, please let me know.
Usage
- Download PDFB Library from the links above.
- Extract to any folder on your server that is accessible by a web browser.
- Go to demo.php on your server to test it. If you see a PDF, then success! Rejoice!
- Otherwise spend all night trying to figure out what's wrong.
- Before you give up, make sure you have PHP Image library setup correctly.
Sample Code
<?php
require("pdfb/pdfb.php"); // Must include this
class PDF extends PDFB
{
function Header()
{
// Add your code here to generate
// Headers on every page
}
function Footer()
{
// Add your code here to generate
// Footers on every page
}
}
// Create a PDF Page object
$pdf = new PDF("p", "pt", "letter");
// Load the base PDF into template
$pdf->setSourceFile("demo.pdf");
$tplidx = $pdf->ImportPage(1);
// Add new page & use the base PDF as template
$pdf->AddPage();
$pdf->useTemplate($tplidx);
// See pdfb/pdfb.php for parameters on BarCode()
// Create a Code 128-B barcode
$pdf->BarCode("PKG1234", "C128B");
// UPC-A Barcode
$pdf->BarCode("73725735882", "UPCA", 300, 300);
$pdf->Output();
$pdf->closeParsers();
?>
Documentation
- For help, documentation, and server requirements for each of the libraries used in PDFB Library, refer to the documentation from the URLs above.
- For help and documentation on how to use the PDFB Library, view the source-code of demo.php file included in the PDFB Library download above. View the ReadMe.txt file for some more information. Due to time constraints, I cannot write detailed documentation for PDFB Library. However, feel free to email me for further information, technical questions, ideas, improvements etc.
- I have just one request:
PLEASE DO NOT CONTACT ME ABOUT INSTALLATION/CONFIGURATION ERRORS
Disclaimer
- Developer: Chirag Mehta, 15 Oct. 2005
- This text, algorithm, and design is copyrighted to Chirag Mehta, 2005.
- For reproduction / copyright information contact me.