Sunday, March 21, 2010

Import PDF file into PHP script and superimpose text

The last post neglected to mention that the license to remove the PDF watermark costs over $500 (for PDFLib). I thought that since all the "native" php functions for php were activated the license would be free, or at least below $100. NOT.

So I switched to what turns out to be a three pronged solution using free libraries:

FPDF - from fpdf.org
FPDI - from setasign.de
FPDF_TPL - from setasign.de

Recipe:
1. FPDF Put fpdf.php into script folder. Put the font folder in there too.
2. FPDI Put entire contents of FPDI download (including fpdi.php) in the same folder.
3. FPDF_TPL Put fpdf_tlp.php into the same folder.

Now the sample scripts that come with FPDI and FPDF work!!

Friday, March 19, 2010

Adding PDFlib to MAMP

(1) Download PDFLib 8.0
Don't install. Instead, enter the downloaded disk image, and surf to:
/bind/php/php-520/libpdf_php.so
Copy that file into:
/Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613

(2) Open Terminal and:
chmod +x /Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613/libpdf_php.so

(3) REM out
#DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
#export DYLD_LIBRARY_PATH
in the file
/Applications/MAMP/Library/bin/envvars
by adding # to the beginning of those two lines.

(4) Add
extension=libpdf_php.so
to extension section of php.ini for php5

REBOOT APACHE AND CHECK THAT PDFLIB IS ENABLED IN PHPINFO.
CREDITS TO JAMES WRIGHT IN THE MAMP FORUM. THANKS YOU JAMES WHERE EVER YOU ARE.